Skip to content

Commit f39badd

Browse files
committed
fix: replace as_any().downcast_ref with downcast_ref after upstream as_any removal (#21573)
1 parent 189287f commit f39badd

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

datafusion/physical-expr/src/expression_analyzer/default.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct DefaultExpressionAnalyzer;
4040
impl DefaultExpressionAnalyzer {
4141
/// Get column index from a Column expression
4242
fn get_column_index(expr: &Arc<dyn PhysicalExpr>) -> Option<usize> {
43-
expr.as_any().downcast_ref::<Column>().map(|c| c.index())
43+
expr.downcast_ref::<Column>().map(|c| c.index())
4444
}
4545

4646
/// Get column statistics for an expression if it's a column reference
@@ -80,7 +80,7 @@ impl ExpressionAnalyzer for DefaultExpressionAnalyzer {
8080
registry: &ExpressionAnalyzerRegistry,
8181
) -> AnalysisResult<f64> {
8282
// Binary expressions: AND, OR, comparisons
83-
if let Some(binary) = expr.as_any().downcast_ref::<BinaryExpr>() {
83+
if let Some(binary) = expr.downcast_ref::<BinaryExpr>() {
8484
match binary.op() {
8585
// AND/OR: only provide a value when both children have estimates.
8686
// Delegating when either child has no information prevents arbitrary
@@ -131,7 +131,7 @@ impl ExpressionAnalyzer for DefaultExpressionAnalyzer {
131131
}
132132

133133
// NOT expression: 1 - child selectivity. Delegate if child has no estimate.
134-
if let Some(not_expr) = expr.as_any().downcast_ref::<NotExpr>() {
134+
if let Some(not_expr) = expr.downcast_ref::<NotExpr>() {
135135
if let Some(child_sel) = registry.get_selectivity(not_expr.arg(), input_stats)
136136
{
137137
return AnalysisResult::Computed(1.0 - child_sel);
@@ -140,13 +140,12 @@ impl ExpressionAnalyzer for DefaultExpressionAnalyzer {
140140
}
141141

142142
// Literal boolean: exact selectivity, no statistics needed.
143-
if let Some(b) = expr
144-
.as_any()
145-
.downcast_ref::<Literal>()
146-
.and_then(|lit| match lit.value() {
147-
ScalarValue::Boolean(Some(b)) => Some(*b),
148-
_ => None,
149-
})
143+
if let Some(b) =
144+
expr.downcast_ref::<Literal>()
145+
.and_then(|lit| match lit.value() {
146+
ScalarValue::Boolean(Some(b)) => Some(*b),
147+
_ => None,
148+
})
150149
{
151150
return AnalysisResult::Computed(if b { 1.0 } else { 0.0 });
152151
}
@@ -168,19 +167,19 @@ impl ExpressionAnalyzer for DefaultExpressionAnalyzer {
168167
}
169168

170169
// Literal: NDV = 1
171-
if expr.as_any().downcast_ref::<Literal>().is_some() {
170+
if expr.downcast_ref::<Literal>().is_some() {
172171
return AnalysisResult::Computed(1);
173172
}
174173

175174
// BinaryExpr: addition/subtraction with a literal is always injective
176175
// TODO: support more injective operators (e.g. multiply by non-zero)
177-
if let Some(binary) = expr.as_any().downcast_ref::<BinaryExpr>() {
176+
if let Some(binary) = expr.downcast_ref::<BinaryExpr>() {
178177
let is_injective = matches!(binary.op(), Operator::Plus | Operator::Minus);
179178

180179
if is_injective {
181180
// If one side is a literal, the operation is injective on the other side
182-
let left_is_literal = binary.left().as_any().is::<Literal>();
183-
let right_is_literal = binary.right().as_any().is::<Literal>();
181+
let left_is_literal = binary.left().is::<Literal>();
182+
let right_is_literal = binary.right().is::<Literal>();
184183

185184
if left_is_literal
186185
&& let Some(ndv) =
@@ -222,7 +221,7 @@ impl ExpressionAnalyzer for DefaultExpressionAnalyzer {
222221
}
223222

224223
// Literal: min = max = value
225-
if let Some(lit_expr) = expr.as_any().downcast_ref::<Literal>() {
224+
if let Some(lit_expr) = expr.downcast_ref::<Literal>() {
226225
let val = lit_expr.value().clone();
227226
return AnalysisResult::Computed((val.clone(), val));
228227
}
@@ -252,7 +251,7 @@ impl ExpressionAnalyzer for DefaultExpressionAnalyzer {
252251
}
253252

254253
// Literal: null fraction depends on whether it's null
255-
if let Some(lit_expr) = expr.as_any().downcast_ref::<Literal>() {
254+
if let Some(lit_expr) = expr.downcast_ref::<Literal>() {
256255
let is_null = lit_expr.value().is_null();
257256
return AnalysisResult::Computed(if is_null { 1.0 } else { 0.0 });
258257
}

datafusion/physical-expr/src/expression_analyzer/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ impl ExpressionAnalyzer for ColumnAOnlyAnalyzer {
448448
_input_stats: &Statistics,
449449
_registry: &ExpressionAnalyzerRegistry,
450450
) -> AnalysisResult<f64> {
451-
if let Some(binary) = expr.as_any().downcast_ref::<BinaryExpr>()
452-
&& let Some(col) = binary.left().as_any().downcast_ref::<Column>()
451+
if let Some(binary) = expr.downcast_ref::<BinaryExpr>()
452+
&& let Some(col) = binary.left().downcast_ref::<Column>()
453453
&& col.name() == "a"
454454
&& matches!(binary.op(), Operator::Eq)
455455
{

0 commit comments

Comments
 (0)