tisyabhatia commented on code in PR #5127:
URL: https://github.com/apache/calcite/pull/5127#discussion_r3786214527
##########
core/src/test/java/org/apache/calcite/test/JdbcTest.java:
##########
@@ -1297,15 +1297,23 @@ private void checkResultSetMetaData(Connection
connection, String sql)
+ "c0=1998\n");
}
- /** Test case for [CALCITE-7594] GROUP BY ALL: grouping only by a constant
- * over empty input returns 0 rows. */
+ /** Test case for [CALCITE-7675] GROUP BY ALL over a select list whose only
+ * non-aggregate item is a constant.
+ *
+ * <p>The constant is not a grouping key, so no grouping key remains and the
+ * query is a single-group aggregation. It therefore returns one row even
+ * though the input is empty. Before [CALCITE-7675] the constant was a
+ * grouping key, empty input yielded no groups, and the query returned no
+ * rows. BigQuery documents the behavior asserted here: "If the set of
+ * inferred grouping keys is empty after exclusions are applied, all input
+ * rows are considered a single group for aggregation." */
@Test void testGroupByAllOverEmptyInput() {
CalciteAssert.hr()
.query("select 'x', count(*)\n"
+ "from \"hr\".\"emps\"\n"
+ "where false\n"
+ "group by all")
- .returnsCount(0);
+ .returns("EXPR$0=x; EXPR$1=0\n");
Review Comment:
This PR changes the rule, which I should have led with. Under CALCITE-7594
'x' was a grouping key, so empty input produced no groups; here keys come only
from expressions that depend on the input, so none remains and the query is a
single-group aggregation. I'm following BigQuery / DuckDB, which infers keys
only from expressions referencing a FROM name and treats an empty set like one
group.
--
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]