Skip to content

Commit

Permalink
fix: Try to convert a static list into a set in Rust (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
advancedxy authored Mar 12, 2024
1 parent 4fec40e commit 5dc865d
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions core/src/execution/datafusion/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ use datafusion::{
common::DataFusionError,
logical_expr::{BuiltinScalarFunction, Operator as DataFusionOperator},
physical_expr::{
expressions::{BinaryExpr, Column, IsNotNullExpr, Literal as DataFusionLiteral},
execution_props::ExecutionProps,
expressions::{
in_list, BinaryExpr, CaseExpr, CastExpr, Column, Count, FirstValue, InListExpr,
IsNotNullExpr, IsNullExpr, LastValue, Literal as DataFusionLiteral, Max, Min,
NegativeExpr, NotExpr, Sum, UnKnownColumn,
},
functions::create_physical_expr,
PhysicalExpr, PhysicalSortExpr,
AggregateExpr, PhysicalExpr, PhysicalSortExpr, ScalarFunctionExpr,
},
physical_plan::{
aggregates::{AggregateMode as DFAggregateMode, PhysicalGroupBy},
Expand All @@ -39,14 +44,6 @@ use datafusion::{
},
};
use datafusion_common::ScalarValue;
use datafusion_physical_expr::{
execution_props::ExecutionProps,
expressions::{
CaseExpr, CastExpr, Count, FirstValue, InListExpr, IsNullExpr, LastValue, Max, Min,
NegativeExpr, NotExpr, Sum, UnKnownColumn,
},
AggregateExpr, ScalarFunctionExpr,
};
use itertools::Itertools;
use jni::objects::GlobalRef;
use num::{BigInt, ToPrimitive};
Expand Down Expand Up @@ -496,7 +493,19 @@ impl PhysicalPlanner {
.iter()
.map(|x| self.create_expr(x, input_schema.clone()).unwrap())
.collect::<Vec<_>>();
Ok(Arc::new(InListExpr::new(value, list, expr.negated, None)))

// if schema contains any dictionary type, we should use InListExpr instead of
// in_list as it doesn't handle value being dictionary type correctly
let contains_dict_type = input_schema
.fields()
.iter()
.any(|f| matches!(f.data_type(), DataType::Dictionary(_, _)));
if contains_dict_type {
// TODO: remove the fallback when https://github.com/apache/arrow-datafusion/issues/9530 is fixed
Ok(Arc::new(InListExpr::new(value, list, expr.negated, None)))
} else {
in_list(value, list, &expr.negated, input_schema.as_ref()).map_err(|e| e.into())
}
}
ExprStruct::If(expr) => {
let if_expr =
Expand Down

0 comments on commit 5dc865d

Please sign in to comment.