Skip to content

Commit cf68d2d

Browse files
committed
chore: cleanup expression handler
1 parent f3d9310 commit cf68d2d

File tree

4 files changed

+27
-1069
lines changed

4 files changed

+27
-1069
lines changed

crates/deltalake-core/src/kernel/client/expressions.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ use std::sync::Arc;
66

77
use arrow_arith::boolean::{and, is_null, not, or};
88
use arrow_arith::numeric::{add, div, mul, sub};
9-
use arrow_array::RecordBatch as ColumnarBatch;
109
use arrow_array::{
1110
Array, ArrayRef, BinaryArray, BooleanArray, Date32Array, Decimal128Array, Float32Array,
1211
Int32Array, RecordBatch, StringArray, TimestampMicrosecondArray,
1312
};
1413
use arrow_ord::cmp::{eq, gt, gt_eq, lt, lt_eq, neq};
1514

16-
use super::ExpressionEvaluator;
1715
use crate::kernel::error::{DeltaResult, Error};
1816
use crate::kernel::expressions::{scalars::Scalar, Expression};
1917
use crate::kernel::expressions::{BinaryOperator, UnaryOperator};
20-
use crate::kernel::schema::SchemaRef;
2118

2219
// TODO leverage scalars / Datum
2320

@@ -43,7 +40,10 @@ impl Scalar {
4340
}
4441
}
4542

46-
fn evaluate_expression(expression: &Expression, batch: &RecordBatch) -> DeltaResult<ArrayRef> {
43+
pub(crate) fn evaluate_expression(
44+
expression: &Expression,
45+
batch: &RecordBatch,
46+
) -> DeltaResult<ArrayRef> {
4747
match expression {
4848
Expression::Literal(scalar) => Ok(scalar.to_array(batch.num_rows())),
4949
Expression::Column(name) => batch
@@ -166,20 +166,6 @@ fn evaluate_expression(expression: &Expression, batch: &RecordBatch) -> DeltaRes
166166
}
167167
}
168168

169-
#[derive(Debug)]
170-
/// Expression evaluator based on arrow compute kernels.
171-
pub struct ArrowExpressionEvaluator {
172-
_input_schema: SchemaRef,
173-
expression: Box<Expression>,
174-
}
175-
176-
impl ExpressionEvaluator for ArrowExpressionEvaluator {
177-
fn evaluate(&self, batch: &ColumnarBatch) -> DeltaResult<ColumnarBatch> {
178-
let _result = evaluate_expression(&self.expression, batch)?;
179-
todo!()
180-
}
181-
}
182-
183169
#[cfg(test)]
184170
mod tests {
185171
use super::*;

crates/deltalake-core/src/kernel/client/mod.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//! Delta kernel client implementation.
2+
use std::sync::Arc;
23

34
use arrow_array::RecordBatch;
45

5-
use super::error::DeltaResult;
6+
use self::expressions::evaluate_expression;
7+
use crate::kernel::error::DeltaResult;
8+
use crate::kernel::expressions::Expression;
9+
use crate::kernel::schema::SchemaRef;
610

711
pub mod expressions;
812

@@ -16,5 +20,21 @@ pub trait ExpressionEvaluator {
1620
///
1721
/// Contains one value for each row of the input.
1822
/// The data type of the output is same as the type output of the expression this evaluator is using.
19-
fn evaluate(&self, batch: &RecordBatch) -> DeltaResult<RecordBatch>;
23+
fn evaluate(&self, batch: &RecordBatch, output_schema: SchemaRef) -> DeltaResult<RecordBatch>;
24+
}
25+
26+
#[derive(Debug)]
27+
/// Expression evaluator based on arrow compute kernels.
28+
pub struct ArrowExpressionEvaluator {
29+
_input_schema: SchemaRef,
30+
expression: Box<Expression>,
31+
}
32+
33+
impl ExpressionEvaluator for ArrowExpressionEvaluator {
34+
fn evaluate(&self, batch: &RecordBatch, output_schema: SchemaRef) -> DeltaResult<RecordBatch> {
35+
Ok(RecordBatch::try_new(
36+
Arc::new(output_schema.as_ref().try_into()?),
37+
vec![evaluate_expression(&self.expression, batch)?],
38+
)?)
39+
}
2040
}

crates/deltalake-core/src/kernel/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Kernel module
22
33
pub mod actions;
4+
#[cfg(feature = "arrow")]
45
pub mod client;
56
pub mod error;
67
pub mod expressions;

0 commit comments

Comments
 (0)