mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-17 08:14:56 +00:00
fix(query): preserve dictionary partition pruning
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user