You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/03/29 18:31:56 UTC

[GitHub] [calcite] abhishek-das-gupta opened a new pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

abhishek-das-gupta opened a new pull request #2757:
URL: https://github.com/apache/calcite/pull/2757


   Add a "SELECT *" wrap over SqlJoin in SqlJoin#toSqlString
   
   Resolves the RuntimeException seen in SqlJoin#toString
   
   Override SqlNode#toSqlString in SqlJoin
   
   Reason: SqlJoin#unparse method calls SqlPrettyWriter#sep with frame being NULL
   
   This change is less fragile than to mutate internal frame state


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] julianhyde commented on a change in pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

Posted by GitBox <gi...@apache.org>.
julianhyde commented on a change in pull request #2757:
URL: https://github.com/apache/calcite/pull/2757#discussion_r837840272



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
##########
@@ -438,6 +441,30 @@ private SqlPrettyWriterFixture tableDotStar() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4401">[CALCITE-4401]
+   * SqlJoin toString throws RuntimeException</a>. */
+  @Test void testJoinClauseToString() throws SqlParseException {
+    final String sql = "SELECT t.region_name, t0.o_totalprice\n"
+        + "FROM (SELECT c_custkey, region_name\n"
+        + "FROM tpch.out_tpch_vw__customer) AS t\n"
+        + "INNER JOIN (SELECT o_custkey, o_totalprice\n"
+        + "FROM tpch.out_tpch_vw__orders) AS t0 ON t.c_custkey = t0.o_custkey";
+
+    final SqlNode node = SqlParser.create(sql).parseQuery();
+    final SqlSelect select = (SqlSelect) node;
+    final SqlJoin join = (SqlJoin) select.getFrom();
+
+    final String expectedJoinString = "SELECT *\r\n"
+        + "FROM (SELECT `C_CUSTKEY`, `REGION_NAME`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__CUSTOMER`) AS `T`\r\n"
+        + "INNER JOIN (SELECT `O_CUSTKEY`, `O_TOTALPRICE`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__ORDERS`) AS `T0` ON `T`.`C_CUSTKEY` = `T0`.`O_CUSTKEY`";
+
+    assert join != null;
+    Assertions.assertEquals(join.toString(), expectedJoinString);
+  }
+

Review comment:
       Please use the fixture, to be consistent with other methods in this test.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] abhishek-das-gupta commented on a change in pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

Posted by GitBox <gi...@apache.org>.
abhishek-das-gupta commented on a change in pull request #2757:
URL: https://github.com/apache/calcite/pull/2757#discussion_r838279705



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
##########
@@ -438,6 +441,30 @@ private SqlPrettyWriterFixture tableDotStar() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4401">[CALCITE-4401]
+   * SqlJoin toString throws RuntimeException</a>. */
+  @Test void testJoinClauseToString() throws SqlParseException {
+    final String sql = "SELECT t.region_name, t0.o_totalprice\n"
+        + "FROM (SELECT c_custkey, region_name\n"
+        + "FROM tpch.out_tpch_vw__customer) AS t\n"
+        + "INNER JOIN (SELECT o_custkey, o_totalprice\n"
+        + "FROM tpch.out_tpch_vw__orders) AS t0 ON t.c_custkey = t0.o_custkey";
+
+    final SqlNode node = SqlParser.create(sql).parseQuery();
+    final SqlSelect select = (SqlSelect) node;
+    final SqlJoin join = (SqlJoin) select.getFrom();
+
+    final String expectedJoinString = "SELECT *\r\n"
+        + "FROM (SELECT `C_CUSTKEY`, `REGION_NAME`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__CUSTOMER`) AS `T`\r\n"
+        + "INNER JOIN (SELECT `O_CUSTKEY`, `O_TOTALPRICE`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__ORDERS`) AS `T0` ON `T`.`C_CUSTKEY` = `T0`.`O_CUSTKEY`";
+
+    assert join != null;
+    Assertions.assertEquals(join.toString(), expectedJoinString);
+  }
+

Review comment:
       I've moved the test case to most logical place (among join tests). 
   
   I first tried to use fixture only but the issue I faced was how to check toString() on JOIN ? The SQLs containing JOIN when parsed give back a SqlSelect. Hence  if I use `sql(sql).check()`  it would assert on the SqlSelect#toString instead of SqlJoin#toString. That is already working on current master since SqlSelect#unparse will start the frame for SqlJoin to conusme in the fromList condition.    
   
   It is only when explicit toString on Join is called then frame is null and we get RuntimeException.
   
   That's why I mimick the steps present in the jira description to  in the testcase. 
   
   I also think this testcase does look not consistent with other test present. 
   
   Is there an api present in fixture that I'm missing ? If so, can you please guide me ? If not,  should I introduce an api in fixture? Otherwise will `sql(sql).check()` suffice ?
   
   Appreciate the review!
   




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] abhishek-das-gupta commented on a change in pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

Posted by GitBox <gi...@apache.org>.
abhishek-das-gupta commented on a change in pull request #2757:
URL: https://github.com/apache/calcite/pull/2757#discussion_r841080060



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
##########
@@ -438,6 +441,30 @@ private SqlPrettyWriterFixture tableDotStar() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4401">[CALCITE-4401]
+   * SqlJoin toString throws RuntimeException</a>. */
+  @Test void testJoinClauseToString() throws SqlParseException {
+    final String sql = "SELECT t.region_name, t0.o_totalprice\n"
+        + "FROM (SELECT c_custkey, region_name\n"
+        + "FROM tpch.out_tpch_vw__customer) AS t\n"
+        + "INNER JOIN (SELECT o_custkey, o_totalprice\n"
+        + "FROM tpch.out_tpch_vw__orders) AS t0 ON t.c_custkey = t0.o_custkey";
+
+    final SqlNode node = SqlParser.create(sql).parseQuery();
+    final SqlSelect select = (SqlSelect) node;
+    final SqlJoin join = (SqlJoin) select.getFrom();
+
+    final String expectedJoinString = "SELECT *\r\n"
+        + "FROM (SELECT `C_CUSTKEY`, `REGION_NAME`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__CUSTOMER`) AS `T`\r\n"
+        + "INNER JOIN (SELECT `O_CUSTKEY`, `O_TOTALPRICE`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__ORDERS`) AS `T0` ON `T`.`C_CUSTKEY` = `T0`.`O_CUSTKEY`";
+
+    assert join != null;
+    Assertions.assertEquals(join.toString(), expectedJoinString);
+  }
+

Review comment:
       Done. Pls check




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] julianhyde commented on a change in pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

Posted by GitBox <gi...@apache.org>.
julianhyde commented on a change in pull request #2757:
URL: https://github.com/apache/calcite/pull/2757#discussion_r837842728



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
##########
@@ -438,6 +441,30 @@ private SqlPrettyWriterFixture tableDotStar() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4401">[CALCITE-4401]
+   * SqlJoin toString throws RuntimeException</a>. */
+  @Test void testJoinClauseToString() throws SqlParseException {
+    final String sql = "SELECT t.region_name, t0.o_totalprice\n"
+        + "FROM (SELECT c_custkey, region_name\n"
+        + "FROM tpch.out_tpch_vw__customer) AS t\n"
+        + "INNER JOIN (SELECT o_custkey, o_totalprice\n"
+        + "FROM tpch.out_tpch_vw__orders) AS t0 ON t.c_custkey = t0.o_custkey";
+
+    final SqlNode node = SqlParser.create(sql).parseQuery();
+    final SqlSelect select = (SqlSelect) node;
+    final SqlJoin join = (SqlJoin) select.getFrom();
+
+    final String expectedJoinString = "SELECT *\r\n"
+        + "FROM (SELECT `C_CUSTKEY`, `REGION_NAME`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__CUSTOMER`) AS `T`\r\n"
+        + "INNER JOIN (SELECT `O_CUSTKEY`, `O_TOTALPRICE`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__ORDERS`) AS `T0` ON `T`.`C_CUSTKEY` = `T0`.`O_CUSTKEY`";
+
+    assert join != null;
+    Assertions.assertEquals(join.toString(), expectedJoinString);
+  }
+

Review comment:
       Also, move your test next to other related tests.
   
   (Contributors seem to think it is 'polite' to add code to the end of a file. It is not. If everyone does that, it creates merge conflicts. Better to put the code in the most logical place, next to related code.)




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] abhishek-das-gupta commented on a change in pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

Posted by GitBox <gi...@apache.org>.
abhishek-das-gupta commented on a change in pull request #2757:
URL: https://github.com/apache/calcite/pull/2757#discussion_r838279705



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
##########
@@ -438,6 +441,30 @@ private SqlPrettyWriterFixture tableDotStar() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4401">[CALCITE-4401]
+   * SqlJoin toString throws RuntimeException</a>. */
+  @Test void testJoinClauseToString() throws SqlParseException {
+    final String sql = "SELECT t.region_name, t0.o_totalprice\n"
+        + "FROM (SELECT c_custkey, region_name\n"
+        + "FROM tpch.out_tpch_vw__customer) AS t\n"
+        + "INNER JOIN (SELECT o_custkey, o_totalprice\n"
+        + "FROM tpch.out_tpch_vw__orders) AS t0 ON t.c_custkey = t0.o_custkey";
+
+    final SqlNode node = SqlParser.create(sql).parseQuery();
+    final SqlSelect select = (SqlSelect) node;
+    final SqlJoin join = (SqlJoin) select.getFrom();
+
+    final String expectedJoinString = "SELECT *\r\n"
+        + "FROM (SELECT `C_CUSTKEY`, `REGION_NAME`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__CUSTOMER`) AS `T`\r\n"
+        + "INNER JOIN (SELECT `O_CUSTKEY`, `O_TOTALPRICE`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__ORDERS`) AS `T0` ON `T`.`C_CUSTKEY` = `T0`.`O_CUSTKEY`";
+
+    assert join != null;
+    Assertions.assertEquals(join.toString(), expectedJoinString);
+  }
+

Review comment:
       I've moved the test case to most logical place (among join tests). 
   
   I first tried to use fixture only but the issue I faced was how to check toString() on JOIN ? The SQLs containing JOIN when parsed give back a SqlSelect. Hence  if I use `sql(sql).check()`  it would assert on the SqlSelect#toString instead of SqlJoin#toString. That is already working on current master since SqlSelect#unparse will start the frame for SqlJoin to conusme in the fromList condition.    
   
   It is only when explicit toString on Join is called then frame is null and we get RuntimeException.
   
   I want to mimick the steps present in the jira description to  in the testcase. 
   
   I also think this testcase does look not consistant with other test present. 
   
   Is there an api present in fixture that I'm missing ? If so, can you please guide me ? If not,  should I introduce an api in fixture? Otherwise will `sql(sql).check()` suffice ?
   
   Appreciate the review!
   




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] abhishek-das-gupta commented on a change in pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

Posted by GitBox <gi...@apache.org>.
abhishek-das-gupta commented on a change in pull request #2757:
URL: https://github.com/apache/calcite/pull/2757#discussion_r838279705



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
##########
@@ -438,6 +441,30 @@ private SqlPrettyWriterFixture tableDotStar() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4401">[CALCITE-4401]
+   * SqlJoin toString throws RuntimeException</a>. */
+  @Test void testJoinClauseToString() throws SqlParseException {
+    final String sql = "SELECT t.region_name, t0.o_totalprice\n"
+        + "FROM (SELECT c_custkey, region_name\n"
+        + "FROM tpch.out_tpch_vw__customer) AS t\n"
+        + "INNER JOIN (SELECT o_custkey, o_totalprice\n"
+        + "FROM tpch.out_tpch_vw__orders) AS t0 ON t.c_custkey = t0.o_custkey";
+
+    final SqlNode node = SqlParser.create(sql).parseQuery();
+    final SqlSelect select = (SqlSelect) node;
+    final SqlJoin join = (SqlJoin) select.getFrom();
+
+    final String expectedJoinString = "SELECT *\r\n"
+        + "FROM (SELECT `C_CUSTKEY`, `REGION_NAME`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__CUSTOMER`) AS `T`\r\n"
+        + "INNER JOIN (SELECT `O_CUSTKEY`, `O_TOTALPRICE`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__ORDERS`) AS `T0` ON `T`.`C_CUSTKEY` = `T0`.`O_CUSTKEY`";
+
+    assert join != null;
+    Assertions.assertEquals(join.toString(), expectedJoinString);
+  }
+

Review comment:
       I've moved the test case to most logical place (among join tests). 
   
   I first tried to use fixture only but the issue I faced was how to check toString() on JOIN ? The SQLs containing JOIN when parsed give back a SqlSelect. Hence  if I use `sql(sql).check()`  it would assert on the SqlSelect#toString instead of SqlJoin#toString. That is already working on current master since SqlSelect#unparse will start the frame for SqlJoin to conusme in the fromList condition.    
   
   It is only when explicit toString on Join is called that's when the frame is null and we get RuntimeException.
   
   That's why I mimick the steps present in the jira description to  in the testcase. 
   
   I also think this testcase does not look consistent with other test present. 
   
   Is there an api present in fixture that I'm missing ? If so, can you please guide me ? If not,  should I introduce an api in fixture? Otherwise will `sql(sql).check()` suffice ?
   
   Appreciate the review!
   




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] julianhyde commented on a change in pull request #2757: [CALCITE-4401] SqlJoin toString throws RuntimeException

Posted by GitBox <gi...@apache.org>.
julianhyde commented on a change in pull request #2757:
URL: https://github.com/apache/calcite/pull/2757#discussion_r838886885



##########
File path: core/src/test/java/org/apache/calcite/sql/test/SqlPrettyWriterTest.java
##########
@@ -438,6 +441,30 @@ private SqlPrettyWriterFixture tableDotStar() {
         .check();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-4401">[CALCITE-4401]
+   * SqlJoin toString throws RuntimeException</a>. */
+  @Test void testJoinClauseToString() throws SqlParseException {
+    final String sql = "SELECT t.region_name, t0.o_totalprice\n"
+        + "FROM (SELECT c_custkey, region_name\n"
+        + "FROM tpch.out_tpch_vw__customer) AS t\n"
+        + "INNER JOIN (SELECT o_custkey, o_totalprice\n"
+        + "FROM tpch.out_tpch_vw__orders) AS t0 ON t.c_custkey = t0.o_custkey";
+
+    final SqlNode node = SqlParser.create(sql).parseQuery();
+    final SqlSelect select = (SqlSelect) node;
+    final SqlJoin join = (SqlJoin) select.getFrom();
+
+    final String expectedJoinString = "SELECT *\r\n"
+        + "FROM (SELECT `C_CUSTKEY`, `REGION_NAME`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__CUSTOMER`) AS `T`\r\n"
+        + "INNER JOIN (SELECT `O_CUSTKEY`, `O_TOTALPRICE`\r\n"
+        + "FROM `TPCH`.`OUT_TPCH_VW__ORDERS`) AS `T0` ON `T`.`C_CUSTKEY` = `T0`.`O_CUSTKEY`";
+
+    assert join != null;
+    Assertions.assertEquals(join.toString(), expectedJoinString);
+  }
+

Review comment:
       I think you will need to extend the fixture.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org