You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by xu...@apache.org on 2026/04/17 06:05:41 UTC

(calcite) branch main updated: Test case for [CALCITE-5124] LIMIT won't work when GROUP BY two or more columns in Elasticsearch Adapter

This is an automated email from the ASF dual-hosted git repository.

xuzifu666 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 88b91847b3 Test case for [CALCITE-5124] LIMIT won't work when GROUP BY two or more columns in Elasticsearch Adapter
88b91847b3 is described below

commit 88b91847b31b82e63eda7029d5855f64d4e801aa
Author: Yu Xu <12...@qq.com>
AuthorDate: Wed Apr 15 14:35:43 2026 +0800

    Test case for [CALCITE-5124] LIMIT won't work when GROUP BY two or more columns in Elasticsearch Adapter
---
 .../elasticsearch/AggregationAndSortTest.java      | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/AggregationAndSortTest.java b/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/AggregationAndSortTest.java
index 3ddf3c82cc..e41c81048b 100644
--- a/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/AggregationAndSortTest.java
+++ b/elasticsearch/src/test/java/org/apache/calcite/adapter/elasticsearch/AggregationAndSortTest.java
@@ -512,4 +512,47 @@ private static Connection createConnectionWithConformance(String lex, String con
             + " group by CAT order by MAX_VAL1 desc, CAT desc")
         .returns("CAT=2; MAX_VAL1=7.0\nCAT=1; MAX_VAL1=1.0\nCAT=null; MAX_VAL1=null\n");
   }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-5124">[CALCITE-5124]
+   * LIMIT won't work when GROUP BY two or more columns in Elasticsearch Adapter</a>.
+   */
+  @Test void testGroupByAggregationLimit() {
+    CalciteAssert.that()
+        .with(AggregationAndSortTest::createConnection)
+        .query("select val1, cat4 from view group by val1, cat4 limit 1")
+        .returnsCount(1);
+
+    CalciteAssert.that()
+        .with(AggregationAndSortTest::createConnection)
+        .query("select val1, cat4 from view group by val1, cat4 limit 2")
+        .returnsCount(2);
+
+    CalciteAssert.that()
+        .with(AggregationAndSortTest::createConnection)
+        .query("select val1, cat4 from view group by val1, cat1, cat4 limit 2")
+        .returnsCount(2);
+
+    CalciteAssert.that()
+        .with(AggregationAndSortTest::createConnection)
+        .query("select val1 from view group by val1 limit 2")
+        .returnsCount(2);
+
+    CalciteAssert.that()
+        .with(AggregationAndSortTest::createConnection)
+        .query("select val1, cat4 from view group by val1, cat4 limit 2")
+        .returns("val1=null; cat4=1576108800000\nval1=1; cat4=1514764800000\n");
+
+    // Test GROUP BY alias with LIMIT (requires BABEL conformance)
+    CalciteAssert.that()
+        .with(() -> createConnectionWithConformance("JAVA", "BABEL"))
+        .query("select val1 as V, cat4 as C from view group by V, C limit 2")
+        .returnsCount(2);
+
+    CalciteAssert.that()
+        .with(() -> createConnectionWithConformance("JAVA", "BABEL"))
+        .query("select cat5 as CAT, max(val1) as MAX_VAL1 from view"
+            + " group by CAT order by MAX_VAL1 desc, CAT desc limit 2")
+        .returns("CAT=2; MAX_VAL1=7.0\nCAT=1; MAX_VAL1=1.0\n");
+  }
 }