alamb commented on PR #23871: URL: https://github.com/apache/datafusion/pull/23871#issuecomment-5073453055
I am sorry for all the back and forth @HairstonE Rereading https://github.com/apache/datafusion/issues/11748 it uses this query: ``` SELECT AVG(v1) FROM t1 GROUP BY false having false; ``` I am really struggling to figure out why the solutions seem so complicated and I don't understand why emitting an output row is a function of all the groups being constant. Specifically since there are no input rows in this example, it shouldn't matter what the group columns are, no output should be emitted (except for COUNT which is a specia case) It seems to me the core problem is that `SELECT AVG(v1) FROM t1 GROUP BY false;` is returning an output row (note there is no HAVING): ```sql > create table t1(v1 int); 0 row(s) fetched. Elapsed 0.021 seconds. > SELECT AVG(v1) FROM t1 GROUP BY false; +------------+ | avg(t1.v1) | +------------+ | NULL | +------------+ 1 row(s) fetched. Elapsed 0.040 seconds. ``` > explain SELECT AVG(v1) FROM t1 GROUP BY false; +---------------+-------------------------------+ | plan_type | plan | +---------------+-------------------------------+ | physical_plan | ┌───────────────────────────┐ | | | │ AggregateExec │ | | | │ -------------------- │ | | | │ aggr: avg(t1.v1) │ | | | │ mode: Single │ | | | └─────────────┬─────────────┘ | | | ┌─────────────┴─────────────┐ | | | │ DataSourceExec │ | | | │ -------------------- │ | | | │ bytes: 0 │ | | | │ format: memory │ | | | │ rows: 0 │ | | | └───────────────────────────┘ | | | | +---------------+-------------------------------+ 1 row(s) fetched. Elapsed 0.006 seconds. ``` But it works fine when there is a row ```sql > insert into t1 values (1); +-------+ | count | +-------+ | 1 | +-------+ 1 row(s) fetched. Elapsed 0.016 seconds. > SELECT AVG(v1) FROM t1 GROUP BY false; +------------+ | avg(t1.v1) | +------------+ | 1.0 | +------------+ 1 row(s) fetched. Elapsed 0.004 seconds. ``` -- 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]
