hsyuan commented on a change in pull request #1271: [CALCITE-3112] Support 
Window in RelToSqlConverter
URL: https://github.com/apache/calcite/pull/1271#discussion_r331168476
 
 

 ##########
 File path: 
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
 ##########
 @@ -1826,6 +1827,91 @@ private void checkLiteral2(String expression, String 
expected) {
     sql(query).ok(expected);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-3112";>[CALCITE-3112]
+   * Support Window in RelToSqlConverter</a>. */
+  @Test public void testConvertWinodwToSql() {
+    String query0 = "SELECT row_number() over (order by \"hire_date\") FROM 
\"employee\"";
+    String expected0 = "SELECT ROW_NUMBER() OVER (ORDER BY \"hire_date\") AS 
\"$0\"\n"
+            + "FROM \"foodmart\".\"employee\"";
+
+    String query1 = "SELECT rank() over (order by \"hire_date\") FROM 
\"employee\"";
+    String expected1 = "SELECT RANK() OVER (ORDER BY \"hire_date\") AS 
\"$0\"\n"
+            + "FROM \"foodmart\".\"employee\"";
+
+    String query2 = "SELECT lead(\"employee_id\",1,'NA') over "
+            + "(partition by \"hire_date\" order by \"employee_id\")\n"
+            + "FROM \"employee\"";
+    String expected2 = "SELECT LEAD(\"employee_id\", 1, 'NA') OVER "
+            + "(PARTITION BY \"hire_date\" "
+            + "ORDER BY \"employee_id\") AS \"$0\"\n"
+            + "FROM \"foodmart\".\"employee\"";
+
+    String query3 = "SELECT lag(\"employee_id\",1,'NA') over "
+            + "(partition by \"hire_date\" order by \"employee_id\")\n"
+            + "FROM \"employee\"";
+    String expected3 = "SELECT LAG(\"employee_id\", 1, 'NA') OVER "
+            + "(PARTITION BY \"hire_date\" ORDER BY \"employee_id\") AS 
\"$0\"\n"
+            + "FROM \"foodmart\".\"employee\"";
+
+    String query4 = "SELECT lag(\"employee_id\",1,'NA') "
+            + "over (partition by \"hire_date\" order by \"employee_id\") as 
lag1, "
+            + "lag(\"employee_id\",1,'NA') "
+            + "over (partition by \"birth_date\" order by \"employee_id\") as 
lag2, "
+            + "count(*) over (partition by \"hire_date\" order by 
\"employee_id\") as count1, "
+            + "count(*) over (partition by \"birth_date\" order by 
\"employee_id\") as count2\n"
+            + "FROM \"employee\"";
+    String expected4 = "SELECT LAG(\"employee_id\", 1, 'NA') OVER "
+            + "(PARTITION BY \"hire_date\" ORDER BY \"employee_id\") AS 
\"$0\", "
+            + "LAG(\"employee_id\", 1, 'NA') OVER "
+            + "(PARTITION BY \"birth_date\" ORDER BY \"employee_id\") AS 
\"$1\", "
+            + "COUNT(*) OVER (PARTITION BY \"hire_date\" ORDER BY 
\"employee_id\" "
+            + "RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS \"$2\", "
+            + "COUNT(*) OVER (PARTITION BY \"birth_date\" ORDER BY 
\"employee_id\" "
+            + "RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS \"$3\"\n"
 
 Review comment:
   Hmm, looks like we failed to preserve the column aliases. I don't think it 
is expected. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to