Fix plan unparsing for filters with subqueries involved type coercion #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DataFusion optimization uses aliases to preserve original expression names during optimizations and type coercions:
apache/datafusion#3794
Datafusion contains special logic to prevent aliasing for filter/join plans, but I still see the alias can be produced for some complex queries/cases
https://github.com/apache/datafusion/blob/f044bc8371d5b4e1e51a9026f3eccac16a6d4648/datafusion/optimizer/src/utils.rs#L316
If there is a filter with additional alias information, we must use the expression only as original expression name is unnecessary and the alias can't be part of the WHERE clause. Note: we don't currently support
Expr::Alias
as general unparsing mechanism, put fix directly towhere_expr
so we are sure that the Alias is part of filter / where clause.Example query
There will be the alias with name "customer.c_acctbal > Decimal128(Some(0),38,15)" produced due to type coercion
Decimal128(Some(0),38,2)
andDecimal128(Some(0),38,15)