yyy1000 commented on PR #10276:
URL: https://github.com/apache/datafusion/pull/10276#issuecomment-2084110449
I encountered an issue: the plan's schema would change during rewrite stage.👀
In
> explain verbose SELECT CAST(2 AS INTEGER);
```
+----------------------------------------------------------------------------+--------------------------------------------------------------------------------------+
| plan_type
| plan
|
+----------------------------------------------------------------------------+--------------------------------------------------------------------------------------+
| initial_logical_plan
| Projection: CAST(Int64(2) AS Int32)
|
|
| EmptyRelation
|
| logical_plan after apply_function_rewrites
| SAME TEXT AS ABOVE
|
| logical_plan after inline_table_scan
| SAME TEXT AS ABOVE
|
| logical_plan after type_coercion
| SAME TEXT AS ABOVE
|
| logical_plan after count_wildcard_rule
| SAME TEXT AS ABOVE
|
| analyzed_logical_plan
| SAME TEXT AS ABOVE
|
| logical_plan after eliminate_nested_union
| SAME TEXT AS ABOVE
|
| logical_plan after simplify_expressions
| Projection: Int32(2) AS Int64(2)
|
|
| EmptyRelation
|
| logical_plan after unwrap_cast_in_comparison
| SAME TEXT AS ABOVE
|
| logical_plan after replace_distinct_aggregate
| SAME TEXT AS ABOVE
|
| logical_plan after eliminate_join
| SAME TEXT AS ABOVE
|
| logical_plan after decorrelate_predicate_subquery
| SAME TEXT AS ABOVE
|
| logical_plan after scalar_subquery_to_join
| SAME TEXT AS ABOVE
|
| logical_plan after extract_equijoin_predicate
| SAME TEXT AS ABOVE
|
| logical_plan after simplify_expressions
| SAME TEXT AS ABOVE
|
| logical_plan after rewrite_disjunctive_predicate
| SAME TEXT AS ABOVE
|
| logical_plan after eliminate_duplicated_expr
| SAME TEXT AS ABOVE
|
| logical_plan after eliminate_filter
| SAME TEXT AS ABOVE
|
| logical_plan after eliminate_cross_join
| SAME TEXT AS ABOVE
|
| logical_plan after Optimizer rule 'common_sub_expression_eliminate' failed
| Schema error: No field named "CAST(Int64(2) AS Int32)". Valid fields are
"Int64(2)". |
+----------------------------------------------------------------------------+--------------------------------------------------------------------------------------+
20 row(s) fetched.
Elapsed 0.008 seconds.
```
After `simplify_expressions`, `ConstEvaluator` will rewrite the `Cast` to an
`Alias` to `ScalarValue`, and the name for the `Alias` is different from the
Field name in the original schema (Because in the past the Cast's name is just
the expr, which is the same as the Alias's name, but now it's not.
I will dive into related code but it may take some time. :) I'm not so
familiar with related code base but I will try to learn it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]