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