Skip to content

Commit

Permalink
feat: add support for array_contains expression
Browse files Browse the repository at this point in the history
  • Loading branch information
dharanad committed Dec 11, 2024
1 parent 21503ca commit eaa6cf6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions native/core/src/execution/datafusion/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ use datafusion_expr::{
AggregateUDF, ScalarUDF, WindowFrame, WindowFrameBound, WindowFrameUnits,
WindowFunctionDefinition,
};
use datafusion_functions_nested::array_has::ArrayHas;
use datafusion_physical_expr::expressions::{Literal, StatsType};
use datafusion_physical_expr::window::WindowExpr;
use datafusion_physical_expr::LexOrdering;
Expand Down Expand Up @@ -735,6 +736,29 @@ impl PhysicalPlanner {
expr.legacy_negative_index,
)))
}
ExprStruct::ArrayContains(expr) => {
println!("dharan code got executed");
let src_array_expr =
self.create_expr(expr.left.as_ref().unwrap(), Arc::clone(&input_schema))?;
let key_expr =
self.create_expr(expr.right.as_ref().unwrap(), Arc::clone(&input_schema))?;
let args = vec![Arc::clone(&src_array_expr), key_expr];
let array_has_expr = Arc::new(ScalarFunctionExpr::new(
"array_has",
Arc::new(ScalarUDF::new_from_impl(ArrayHas::new())),
args,
DataType::Boolean,
));
let is_array_null: Arc<dyn PhysicalExpr> =
Arc::new(IsNullExpr::new(src_array_expr));
let null_literal_expr: Arc<dyn PhysicalExpr> =
Arc::new(Literal::new(ScalarValue::Null));
Ok(Arc::new(CaseExpr::try_new(
None,
vec![(is_array_null, null_literal_expr)],
Some(array_has_expr),
)?))
}
expr => Err(ExecutionError::GeneralError(format!(
"Not implemented: {:?}",
expr
Expand Down
1 change: 1 addition & 0 deletions native/proto/src/proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ message Expr {
GetArrayStructFields get_array_struct_fields = 57;
BinaryExpr array_append = 58;
ArrayInsert array_insert = 59;
BinaryExpr array_contains = 60;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,12 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim
withInfo(expr, "unsupported arguments for GetArrayStructFields", child)
None
}
case expr if expr.prettyName == "array_contains" =>
createBinaryExpr(
expr.children(0),
expr.children(1),
inputs,
(builder, binaryExpr) => builder.setArrayContains(binaryExpr))
case _ if expr.prettyName == "array_append" =>
createBinaryExpr(
expr.children(0),
Expand Down

0 comments on commit eaa6cf6

Please sign in to comment.