alamb commented on code in PR #4753:
URL: https://github.com/apache/arrow-datafusion/pull/4753#discussion_r1058590886
##########
datafusion/core/tests/sql/union.rs:
##########
@@ -80,6 +80,23 @@ async fn union_all_with_aggregate() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn union_all_with_count() -> Result<()> {
+ let ctx = SessionContext::new();
+ execute_to_batches(&ctx, "CREATE table t as SELECT 1 as a").await;
+ let sql = "SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from
t)";
Review Comment:
👍 agrees with postgres:
```sql
postgres=# CREATE table t as SELECT 1 as a;
SELECT 1
postgres=# SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t);
ERROR: subquery in FROM must have an alias
LINE 1: SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a fro...
^
HINT: For example, FROM (SELECT ...) [AS] foo.
postgres=# SELECT COUNT(*) FROM (SELECT a from t UNION ALL SELECT a from t)
as sq;
count
-------
2
(1 row)
```
##########
datafusion/core/src/physical_plan/planner.rs:
##########
@@ -773,12 +773,19 @@ impl DefaultPhysicalPlanner {
)?;
Ok(Arc::new(FilterExec::try_new(runtime_expr,
physical_input)?))
}
- LogicalPlan::Union(Union { inputs, .. }) => {
+ LogicalPlan::Union(Union { inputs, schema }) => {
let physical_plans = futures::stream::iter(inputs)
.then(|lp| self.create_initial_plan(lp, session_state))
.try_collect::<Vec<_>>()
.await?;
- Ok(Arc::new(UnionExec::new(physical_plans)))
+ if schema.fields().len() <
physical_plans[0].schema().fields().len() {
Review Comment:
I wonder what is the reason to not always run
`UnionExec::try_new_with_schema`?
--
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]