berkaysynnada opened a new pull request, #6566:
URL: https://github.com/apache/arrow-datafusion/pull/6566
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Closes #6492.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
When writing query result to MemTable using SELECT .. INTO syntax, window
aggregate projections without alias give error because of schema mismatch. As
an example,
`SELECT SUM(c1) OVER(ORDER BY c1) as sum1 INTO new_table FROM
annotated_data_infinite`
has no problem but
`SELECT SUM(c1) OVER(ORDER BY c1) INTO new_table FROM
annotated_data_infinite`
gives an error:
**Plan("Mismatch between schema and batches")**.
This is because of the schema, which is created from the input LogicalPlan,
has fields whose names are the result of
[display_name()](https://github.com/apache/arrow-datafusion/blob/c7bfe15b4940ebff39f466212ccf32e891db7243/datafusion/expr/src/expr_schema.rs#L283)
(It writes the whole expression, func + window specs). However, the
RecordBatch's fields of partitions are the result of
[physical_name()](https://github.com/apache/arrow-datafusion/blob/c7bfe15b4940ebff39f466212ccf32e891db7243/datafusion/core/src/physical_plan/planner.rs#L1601).
(It writes only the function part of the expr).
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
In `create_memory_table()` function, there is a match arm that handles the
case which the table does not exist. In that case, we initialize the MemTable
with try_new(), comparing the fields one-to-one. For these not registered and
newly created tables, we don't need to check LogicalPlan schema and the schema
coming from partitions. By implementing a MemTable::new_not_registered()
function, we can directly adopt the schema coming from partitions. In case of
empty batches (Create Table statements without values inserted), we can use
input plan's schema.
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are
they covered by existing tests)?
-->
Yes, the erroneous example above is tested.
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
--
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]