From f57530ccdbbb517eaaca1ac64782dbecb352d7ab Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Thu, 16 Jul 2026 17:13:09 +0800 Subject: [PATCH] fix(query): preserve dictionary partition pruning Signed-off-by: Ruihang Xia --- .../src/dist_plan/predicate_extractor.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/query/src/dist_plan/predicate_extractor.rs b/src/query/src/dist_plan/predicate_extractor.rs index 309f3ddcf28..febf6c31203 100644 --- a/src/query/src/dist_plan/predicate_extractor.rs +++ b/src/query/src/dist_plan/predicate_extractor.rs @@ -503,6 +503,11 @@ impl DataFusionExprConverter { // String casts might be safe in some cases DataType::Utf8 => true, DataType::LargeUtf8 => true, + // Dictionary encoding does not change the logical value. DataFusion inserts this cast + // when a predicate literal is compared with a dictionary-encoded scan column. + DataType::Dictionary(_, value_type) => { + Self::is_safe_cast_for_partition_pruning(value_type) + } // Date/time casts might be safe if they don't change precision significantly DataType::Date32 => true, @@ -629,6 +634,26 @@ mod tests { ); } + #[test] + fn test_dictionary_cast_preserves_partition_constraint() { + let dictionary_type = + DataType::Dictionary(Box::new(DataType::UInt32), Box::new(DataType::Utf8)); + let filter = col("tag").eq(Expr::Cast(datafusion_expr::expr::Cast { + expr: Box::new(lit("b")), + data_type: dictionary_type, + })); + + let partition_expr = DataFusionExprConverter::convert(&filter).unwrap(); + assert_eq!( + partition_expr, + PartitionExpr::new( + Operand::Column("tag".to_string()), + RestrictedOp::Eq, + Operand::Value(Value::String("b".into())), + ) + ); + } + #[test] fn test_combines_table_scan_filters_as_conjunction() { let table_scan = create_test_table_scan();