You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2022/03/25 02:34:15 UTC
[calcite] branch master updated (ce71276 -> 1ce516d)
This is an automated email from the ASF dual-hosted git repository.
jhyde pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git.
omit ce71276 [CALCITE-5050]Aggregate with no GROUP BY always returns 1 row
new 1ce516d [CALCITE-5050] Metadata (RelMdRowCount) should reflect the fact that an Aggregate with no GROUP BY always returns 1 row
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (ce71276)
\
N -- N -- N refs/heads/master (1ce516d)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
[calcite] 01/01: [CALCITE-5050] Metadata (RelMdRowCount) should reflect the fact that an Aggregate with no GROUP BY always returns 1 row
Posted by jh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jhyde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 1ce516dcb660caa40ac806617f37cae9532bd0aa
Author: Jing Zhang <be...@gmail.com>
AuthorDate: Thu Mar 17 21:45:00 2022 +0800
[CALCITE-5050] Metadata (RelMdRowCount) should reflect the fact that an Aggregate with no GROUP BY always returns 1 row
Close apache/calcite#2746
---
.../apache/calcite/rel/metadata/RelMdRowCount.java | 5 +++-
.../org/apache/calcite/test/RelMetadataTest.java | 29 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java
index 6b10195..3de9314 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdRowCount.java
@@ -199,7 +199,10 @@ public class RelMdRowCount
public Double getRowCount(Aggregate rel, RelMetadataQuery mq) {
ImmutableBitSet groupKey = rel.getGroupSet();
-
+ if (groupKey.isEmpty()) {
+ // Aggregate with no GROUP BY always returns 1 row (even on empty table).
+ return 1D;
+ }
// rowCount is the cardinality of the group by columns
Double distinctRowCount =
mq.getDistinctRowCount(rel.getInput(), groupKey, null);
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index c7498da..038547c 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -674,6 +674,35 @@ public class RelMetadataTest {
sql(sql).assertThatRowCount(is(1D), is(1D), is(1D));
}
+ /** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-5050">[CALCITE-5050]
+ * Aggregate with no GROUP BY always returns 1 row. </a>. */
+ @Test void testRowCountAggregateEmptyGroupKey() {
+ fixture()
+ .withRelFn(b ->
+ b.scan("EMP")
+ .aggregate(
+ b.groupKey(),
+ b.count(false, "C"))
+ .build())
+ .assertThatRowCount(is(1D), is(1D), is(1D));
+ }
+
+ /** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-5050">[CALCITE-5050]
+ * Aggregate with no GROUP BY always returns 1 row (even on empty table). </a>. */
+ @Test void testRowCountAggregateEmptyGroupKeyWithEmptyTable() {
+ fixture()
+ .withRelFn(b ->
+ b.scan("EMP")
+ .filter(b.literal(false))
+ .aggregate(
+ b.groupKey(),
+ b.count(false, "C"))
+ .build())
+ .assertThatRowCount(is(1D), is(1D), is(1D));
+ }
+
@Test void testRowCountAggregateConstantKey() {
final String sql = "select count(*) from emp where deptno=2 and ename='emp1' "
+ "group by deptno, ename";