Skip to content

Commit 24d103d

Browse files
committed
Datafusion: Support cast operations
Resolves apache#811 Depends on apache#820
1 parent 74a85e7 commit 24d103d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/integrations/datafusion/src/physical_plan/expr_to_predicate.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn to_iceberg_predicate(expr: &Expr) -> TransformedResult {
119119
_ => TransformedResult::NotTransformed,
120120
}
121121
}
122+
Expr::Cast(c) => to_iceberg_predicate(&c.expr),
122123
_ => TransformedResult::NotTransformed,
123124
}
124125
}
@@ -211,7 +212,7 @@ fn scalar_value_to_datum(value: &ScalarValue) -> Option<Datum> {
211212

212213
#[cfg(test)]
213214
mod tests {
214-
use datafusion::arrow::datatypes::{DataType, Field, Schema};
215+
use datafusion::arrow::datatypes::{DataType, Field, Schema, TimeUnit};
215216
use datafusion::common::DFSchema;
216217
use datafusion::logical_expr::utils::split_conjunction;
217218
use datafusion::prelude::{Expr, SessionContext};
@@ -224,6 +225,7 @@ mod tests {
224225
let arrow_schema = Schema::new(vec![
225226
Field::new("foo", DataType::Int32, true),
226227
Field::new("bar", DataType::Utf8, true),
228+
Field::new("ts", DataType::Timestamp(TimeUnit::Second, None), true),
227229
]);
228230
DFSchema::try_from_qualified_schema("my_table", &arrow_schema).unwrap()
229231
}
@@ -392,4 +394,12 @@ mod tests {
392394
let expected_predicate = Reference::new("foo").less_than(Datum::long(0));
393395
assert_eq!(predicate, expected_predicate);
394396
}
397+
398+
#[test]
399+
fn test_predicate_conversion_with_cast() {
400+
let sql = "ts >= timestamp '2023-01-05T00:00:00'";
401+
let predicate = convert_to_iceberg_predicate(sql).unwrap();
402+
let expected_predicate = Reference::new("ts").greater_than_or_equal_to(Datum::string("2023-01-05T00:00:00"));
403+
assert_eq!(predicate, expected_predicate);
404+
}
395405
}

0 commit comments

Comments
 (0)