adriangb opened a new pull request, #25675:
URL: https://github.com/apache/datafusion/pull/25675
## Which issue does this PR close?
- Closes #25669.
## Rationale for this change
`PREPARE p AS SELECT $1 AS a UNION ALL SELECT $2 AS a` fails with `Schema
error: No field named a.` The same happens when a caller optimizes such a plan
before binding its parameters.
`Expr::get_type` had a special case for an alias of an untyped placeholder:
it looked up the alias name as a column in the schema it receives. The `UNION`
coercion code calls `get_type` on each projection expression with the
projection's input schema, which does not contain the alias, so the lookup
fails. `Expr::to_field` has no such special case and returns a `Null` field for
the same expression.
The special case came from #4701. At that time `get_type` returned an error
for a bare untyped placeholder. Today a bare untyped placeholder has type
`Null`, so the special case is no longer needed.
## What changes are included in this PR?
- Remove the `Alias(Placeholder { field: None })` special case from
`Expr::get_type`. An alias now has the type of the expression it wraps, the
same as in `to_field`.
## What is the testing strategy for this PR?
Tests added:
- sqllogictest cases in `prepare.slt` for `PREPARE` and `EXECUTE` of a
`UNION ALL` of aliased placeholders, including a CTE joined to a table.
- A test in `core/tests/sql/select.rs` that optimizes the plan with unbound
placeholders, then binds and executes it.
- A unit test in `expr_schema.rs` that `get_type` and `to_field` agree 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.
--
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]