Repository navigation
fix: validate wrapped negation during type coercion - #20965
Conversation
|
Hey @alamb , Could you please help trigger CI for this PR? This is my first contribution here. I’m hoping to contribute more actively to the project going forward, so I’d really appreciate your help. Thanks! |
75d220e to
0e226bd
Compare
| let predicate_type = expr.get_type(schema)?; | ||
| if !Self::is_allowed_predicate_type(&predicate_type) { | ||
| return plan_err!( | ||
| "Cannot create filter with non-boolean predicate '{expr}' returning {predicate_type}" |
There was a problem hiding this comment.
most DataFusion type validation happens during the Analyzer phase, not the sql planner (binding phase)
I agree with @Acfboy s original statement that failing at physical planning time is probably too late, but trying to do this in sql is too early
Among other things it means that this type checking will not apply to queries created via the DataFrame API
There was a problem hiding this comment.
Thanks @alamb , that makes sense.
I agree that doing this in the SQL planner makes the behavior SQL-specific and misses queries built through the DataFrame API.
I’ll rework this toward the analyzer/type coercion path instead, and I’ll take a closer look at which cases are already covered there versus which ones still need to be handled. I’ll also update the regression tests to match that direction.
There was a problem hiding this comment.
@alamb Thanks for the feedback. After reading through the earlier discussion in more detail, I realized this was originally part of the follow-up from #20201, where the broader question was how much of this validation should happen earlier, and in which phase.
Based on your comment, I reworked this to keep the validation in the analyzer/type coercion path instead of the SQL planner, since that is where most of DataFusion's type validation already happens and it also applies to DataFrame API queries.
After checking the current behavior more closely, it looks like the specific remaining gap here was wrapped unary negation under IS NULL, such as (-'a') IS NULL, so I narrowed this PR to that case and added focused regression tests for it.
I also opened #20988 to track this case more precisely. Could you please take another look when you have a chance?
Also, it looks like the new CI runs ended in
startup_failurebefore any jobs were created, likely because the workflows need to be re-triggered.
@alamb Could you please help trigger CI again when convenient? Thanks.
0e226bd to
f83e6d3
Compare
| get_casted_expr_for_bool_op(*expr, self.schema)?, | ||
| ))), | ||
| Expr::Negative(expr) => { | ||
| let data_type = expr.get_type(self.schema)?; |
There was a problem hiding this comment.
I double checked that this matches the check in physical expr:
datafusion/datafusion/physical-expr/src/expressions/negative.rs
Lines 194 to 195 in 5d37bab
There was a problem hiding this comment.
Thanks for double checking, and thanks for the careful review.🙏
|
Thanks again |
|
🤔 this one seems to have broken CI for some reason: |
Thanks for catching that. I checked the failing job, and this looks like an sqllogictest expectation mismatch. It looks like this particular sqllogictest case had not been exercised in the earlier CI runs I saw on the PR. The analyzer change now surfaces this negation error through type_coercion, while the existing expectation in scalar.slt still assumes the older error form. I’ll open a follow-up PR to update that. |
) ## Which issue does this PR close? - Fixes CI breakage on main introduced by #20965. link: https://github.com/apache/datafusion/actions/runs/23406116823/job/68085237860 ## Rationale for this change #20965 moved invalid negation validation into the analyzer/type coercion path. After that change, the `SELECT -'100'` sqllogictest case now reports the error through `type_coercion`, but `scalar.slt` was still expecting the older error form. This follow-up updates the sqllogictest expectation to match the current behavior. ## What changes are included in this PR? - update the `scalar.slt` expectation for `SELECT -'100'` - keep the expected error aligned with the analyzer/type coercion error shape introduced by #20965 ## Are these changes tested? Yes. I reproduced the failure locally and verified the updated expectation with: - `cargo test -p datafusion-sqllogictest --test sqllogictests -- scalar` ## Are there any user-facing changes? No. Signed-off-by: yaommen <[email protected]>
Perhaps it was anewly added test Thank you for the follow up |
## Which issue does this PR close? - Related to apache#20988 . ## Rationale for this change Invalid wrapped negation expressions such as `(-'a') IS NULL` could still escape type validation during optimization. This PR keeps the fix in the analyzer/type coercion path, which is where most of DataFusion's type validation already happens, rather than adding SQL-planner-specific validation. ## What changes are included in this PR? - add type validation for `Expr::Negative` in `TypeCoercionRewriter` - return an error for invalid negation operands during optimization - add focused regression tests for wrapped negation ## Are these changes tested? Yes. Added: - a unit test for `(-'a') IS NULL` in `type_coercion` - an integration test that verifies the same case fails during `into_optimized_plan()` ## Are there any user-facing changes? Yes. Invalid wrapped negation expressions now fail during optimization instead of escaping type validation until later phases.
…che#21102) ## Which issue does this PR close? - Fixes CI breakage on main introduced by apache#20965. link: https://github.com/apache/datafusion/actions/runs/23406116823/job/68085237860 ## Rationale for this change apache#20965 moved invalid negation validation into the analyzer/type coercion path. After that change, the `SELECT -'100'` sqllogictest case now reports the error through `type_coercion`, but `scalar.slt` was still expecting the older error form. This follow-up updates the sqllogictest expectation to match the current behavior. ## What changes are included in this PR? - update the `scalar.slt` expectation for `SELECT -'100'` - keep the expected error aligned with the analyzer/type coercion error shape introduced by apache#20965 ## Are these changes tested? Yes. I reproduced the failure locally and verified the updated expectation with: - `cargo test -p datafusion-sqllogictest --test sqllogictests -- scalar` ## Are there any user-facing changes? No. Signed-off-by: yaommen <[email protected]>
Which issue does this PR close?
Rationale for this change
Invalid wrapped negation expressions such as
(-'a') IS NULLcould still escape type validation during optimization.This PR keeps the fix in the analyzer/type coercion path, which is where most of DataFusion's type validation already happens, rather than adding SQL-planner-specific validation.
What changes are included in this PR?
Expr::NegativeinTypeCoercionRewriterAre these changes tested?
Yes.
Added:
(-'a') IS NULLintype_coercioninto_optimized_plan()Are there any user-facing changes?
Yes. Invalid wrapped negation expressions now fail during optimization instead of escaping type validation until later phases.