You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by vl...@apache.org on 2019/01/04 13:57:26 UTC
[calcite] branch master updated: [CALCITE-2625] Jdbc adapter: print
Window Frame Boundary only for those aggregates that support it
(KrishnaKant Agrawal)
This is an automated email from the ASF dual-hosted git repository.
vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 276e24b [CALCITE-2625] Jdbc adapter: print Window Frame Boundary only for those aggregates that support it (KrishnaKant Agrawal)
276e24b is described below
commit 276e24b089bc066e9d9ffe3ed5f9bdf3f4699b96
Author: krishnakant.agrawal <kr...@datametica.com>
AuthorDate: Wed Dec 19 20:59:14 2018 +0530
[CALCITE-2625] Jdbc adapter: print Window Frame Boundary only for those aggregates that support it (KrishnaKant Agrawal)
fixes #889
---
.../apache/calcite/rel/rel2sql/SqlImplementor.java | 17 ++++++----
.../calcite/rel/rel2sql/RelToSqlConverterTest.java | 36 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index 99e9220..0937667 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -663,11 +663,6 @@ public abstract class SqlImplementor {
final SqlLiteral isRows =
SqlLiteral.createBoolean(rexWindow.isRows(), POS);
- final SqlNode lowerBound =
- createSqlWindowBound(rexWindow.getLowerBound());
- final SqlNode upperBound =
- createSqlWindowBound(rexWindow.getUpperBound());
-
// null defaults to true.
// During parsing the allowPartial == false (e.g. disallow partial)
// is expand into CASE expression and is handled as a such.
@@ -675,11 +670,21 @@ public abstract class SqlImplementor {
// "disallow partial" and set the allowPartial = false.
final SqlLiteral allowPartial = null;
+ SqlAggFunction sqlAggregateFunction = rexOver.getAggOperator();
+
+ SqlNode lowerBound = null;
+ SqlNode upperBound = null;
+
+ if (sqlAggregateFunction.allowsFraming()) {
+ lowerBound = createSqlWindowBound(rexWindow.getLowerBound());
+ upperBound = createSqlWindowBound(rexWindow.getUpperBound());
+ }
+
final SqlWindow sqlWindow = SqlWindow.create(null, null, partitionList,
orderList, isRows, lowerBound, upperBound, allowPartial, POS);
final List<SqlNode> nodeList = toSql(program, rexOver.getOperands());
- return createOverCall(rexOver.getAggOperator(), nodeList, sqlWindow);
+ return createOverCall(sqlAggregateFunction, nodeList, sqlWindow);
}
private SqlCall createOverCall(SqlAggFunction op, List<SqlNode> operands,
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 fb6a539..388cc2d 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
@@ -1401,6 +1401,42 @@ public class RelToSqlConverterTest {
}
/** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-2625">[CALCITE-2625]
+ * Removing Window Boundaries from SqlWindow of Aggregate Function which do not allow Framing</a>
+ * */
+ @Test public void testRowNumberFunctionForPrintingOfFrameBoundary() {
+ String query = "SELECT row_number() over (order by \"hire_date\") FROM \"employee\"";
+ String expected = "SELECT ROW_NUMBER() OVER (ORDER BY \"hire_date\")\n"
+ + "FROM \"foodmart\".\"employee\"";
+ sql(query).ok(expected);
+ }
+
+ @Test public void testRankFunctionForPrintingOfFrameBoundary() {
+ String query = "SELECT rank() over (order by \"hire_date\") FROM \"employee\"";
+ String expected = "SELECT RANK() OVER (ORDER BY \"hire_date\")\n"
+ + "FROM \"foodmart\".\"employee\"";
+ sql(query).ok(expected);
+ }
+
+ @Test public void testLeadFunctionForPrintingOfFrameBoundary() {
+ String query = "SELECT lead(\"employee_id\",1,'NA') over "
+ + "(partition by \"hire_date\" order by \"employee_id\") FROM \"employee\"";
+ String expected = "SELECT LEAD(\"employee_id\", 1, 'NA') OVER "
+ + "(PARTITION BY \"hire_date\" ORDER BY \"employee_id\")\n"
+ + "FROM \"foodmart\".\"employee\"";
+ sql(query).ok(expected);
+ }
+
+ @Test public void testLagFunctionForPrintingOfFrameBoundary() {
+ String query = "SELECT lag(\"employee_id\",1,'NA') over "
+ + "(partition by \"hire_date\" order by \"employee_id\") FROM \"employee\"";
+ String expected = "SELECT LAG(\"employee_id\", 1, 'NA') OVER "
+ + "(PARTITION BY \"hire_date\" ORDER BY \"employee_id\")\n"
+ + "FROM \"foodmart\".\"employee\"";
+ sql(query).ok(expected);
+ }
+
+ /** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1798">[CALCITE-1798]
* Generate dialect-specific SQL for FLOOR operator</a>. */
@Test public void testFloor() {