Conversation
Expr::get_type looked up the alias of an untyped placeholder as a column in the schema it receives. UNION coercion passes the projection's input schema, which does not contain the alias, so planning failed with "No field named <alias>". Remove the special case so get_type agrees with to_field and returns Null, like a bare untyped placeholder. Closes apache#25669
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25675 +/- ##
==========================================
- Coverage 82.48% 82.48% -0.01%
==========================================
Files 1140 1140
Lines 437614 437622 +8
Branches 437614 437622 +8
==========================================
+ Hits 360986 360987 +1
- Misses 54834 54840 +6
- Partials 21794 21795 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@neilconway could I ping you for review? |
|
This is useful for a Rust service where we cache optimized DataFusion logical plans before binding request params. Hit the same schema lookup failure when a parameterized two-row key set used fwiw, while reading I made a visual walkthrough covering alias type resolution: https://flyovers.dev/flyover/85a1f93d-380b-43e5-9401-274f9f7e6e81 |
I was not expecting what I got when I clicked that link 🤣. If you care about this PR maybe a GitHub review would be helpful in helping get it across the line? Or confirmation that it fixes your problem? |
Which issue does this PR close?
UNIONarm fails with "Schema error: No field named <alias>" when the plan is analyzed or optimized #25669.Rationale for this change
PREPARE p AS SELECT $1 AS a UNION ALL SELECT $2 AS afails withSchema error: No field named a.The same happens when a caller optimizes such a plan before binding its parameters.Expr::get_typehad a special case for an alias of an untyped placeholder: it looked up the alias name as a column in the schema it receives. TheUNIONcoercion code callsget_typeon each projection expression with the projection's input schema, which does not contain the alias, so the lookup fails.Expr::to_fieldhas no such special case and returns aNullfield for the same expression.The special case came from #4701. At that time
get_typereturned an error for a bare untyped placeholder. Today a bare untyped placeholder has typeNull, so the special case is no longer needed.What changes are included in this PR?
Alias(Placeholder { field: None })special case fromExpr::get_type. An alias now has the type of the expression it wraps, the same as into_field.What is the testing strategy for this PR?
Tests added:
prepare.sltforPREPAREandEXECUTEof aUNION ALLof aliased placeholders, including a CTE joined to a table.core/tests/sql/select.rsthat optimizes the plan with unbound placeholders, then binds and executes it.expr_schema.rsthatget_typeandto_fieldagree for an aliased untyped placeholder.The existing prepared statement and placeholder type inference tests pass without changes.
Are there any user-facing changes?
The queries above now plan and run. No API changes.