You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by li...@apache.org on 2023/03/27 04:48:46 UTC
[calcite] branch main updated: [CALCITE-5411] `SparkSqlDialect` should support `ROLLUP` and `CUBE` aggregate functions
This is an automated email from the ASF dual-hosted git repository.
libenchao 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 5c7be55ffe [CALCITE-5411] `SparkSqlDialect` should support `ROLLUP` and `CUBE` aggregate functions
5c7be55ffe is described below
commit 5c7be55ffee836366dcc7fefb6adfc0b8c47465f
Author: Leonid Chistov <lc...@querifylabs.com>
AuthorDate: Thu Dec 1 18:32:48 2022 +0300
[CALCITE-5411] `SparkSqlDialect` should support `ROLLUP` and `CUBE` aggregate functions
SparkSqlDialect also supports `WITH CUBE` and `WITH ROLLUP`, but we prefer the `ROLLUP` and `CUBE` aggregate functions since they are in the SQL standard.
Close apache/calcite#2994
---
.../apache/calcite/sql/dialect/SparkSqlDialect.java | 17 +++++++++++++++++
.../calcite/rel/rel2sql/RelToSqlConverterTest.java | 18 ++++++------------
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/sql/dialect/SparkSqlDialect.java b/core/src/main/java/org/apache/calcite/sql/dialect/SparkSqlDialect.java
index 3a7b628ce1..4c3aa6abd5 100644
--- a/core/src/main/java/org/apache/calcite/sql/dialect/SparkSqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/dialect/SparkSqlDialect.java
@@ -79,6 +79,23 @@ public class SparkSqlDialect extends SqlDialect {
return false;
}
+ @Override public boolean supportsAggregateFunction(SqlKind kind) {
+ switch (kind) {
+ case AVG:
+ case COUNT:
+ case CUBE:
+ case SUM:
+ case SUM0:
+ case MIN:
+ case MAX:
+ case ROLLUP:
+ return true;
+ default:
+ break;
+ }
+ return false;
+ }
+
@Override public boolean supportsApproxCountDistinct() {
return true;
}
diff --git a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index cb41c225d2..cfebf54b1b 100644
--- a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -6153,16 +6153,13 @@ class RelToSqlConverterTest {
final String expected = "SELECT COUNT(*)\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "GROUP BY CUBE(\"product_id\", \"product_class_id\")";
- final String expectedInSpark = "SELECT COUNT(*)\n"
+ final String expectedSpark = "SELECT COUNT(*)\n"
+ "FROM foodmart.product\n"
- + "GROUP BY product_id, product_class_id WITH CUBE";
- final String expectedPresto = "SELECT COUNT(*)\n"
- + "FROM \"foodmart\".\"product\"\n"
- + "GROUP BY CUBE(\"product_id\", \"product_class_id\")";
+ + "GROUP BY CUBE(product_id, product_class_id)";
sql(query)
.ok(expected)
- .withPresto().ok(expectedPresto)
- .withSpark().ok(expectedInSpark);
+ .withPresto().ok(expected)
+ .withSpark().ok(expectedSpark);
}
@Test void testRollupWithGroupBy() {
@@ -6174,13 +6171,10 @@ class RelToSqlConverterTest {
+ "GROUP BY ROLLUP(\"product_id\", \"product_class_id\")";
final String expectedSpark = "SELECT COUNT(*)\n"
+ "FROM foodmart.product\n"
- + "GROUP BY product_id, product_class_id WITH ROLLUP";
- final String expectedPresto = "SELECT COUNT(*)\n"
- + "FROM \"foodmart\".\"product\"\n"
- + "GROUP BY ROLLUP(\"product_id\", \"product_class_id\")";
+ + "GROUP BY ROLLUP(product_id, product_class_id)";
sql(query)
.ok(expected)
- .withPresto().ok(expectedPresto)
+ .withPresto().ok(expected)
.withSpark().ok(expectedSpark);
}