You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (JIRA)" <ji...@apache.org> on 2017/01/17 18:26:26 UTC
[jira] [Commented] (CALCITE-1582) RelToSqlConverter doesn't handle
cartesian join (no join cond)
[ https://issues.apache.org/jira/browse/CALCITE-1582?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15826549#comment-15826549 ]
Julian Hyde commented on CALCITE-1582:
--------------------------------------
Looks good. Please provide a PR with a test case.
> RelToSqlConverter doesn't handle cartesian join (no join cond)
> --------------------------------------------------------------
>
> Key: CALCITE-1582
> URL: https://issues.apache.org/jira/browse/CALCITE-1582
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Jess Balint
> Assignee: Julian Hyde
> Priority: Minor
>
> this test fails (added in {{RelToSqlConverterTest}}):
> {code}
> @Test public void testCartesianProduct() {
> String query = "select * from \"department\" , \"employee\"";
> String expected = "SELECT *\n" +
> "FROM \"foodmart\".\"department\"\n" +
> "INNER JOIN \"foodmart\".\"employee\"";
> sql(query).ok(expected);
> }
> {code}
> {{RelToSqlConverter}} is checking that the join condition is a {{RexCall}}. In this case (and {{RelBuilder.join()}} with no join cond), the join cond is a {{RexLiteral}} with a value of {{true}}.
> Suggested fix is to handle the case with this specific join condition before {{convertConditionToSqlNode()}}:
> {noformat}
> --- a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
> +++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
> @@ -104,17 +104,23 @@ public Result visit(Join e) {
> final Context leftContext = leftResult.qualifiedContext();
> final Context rightContext =
> rightResult.qualifiedContext();
> - SqlNode sqlCondition = convertConditionToSqlNode(e.getCondition(),
> - leftContext,
> - rightContext,
> - e.getLeft().getRowType().getFieldCount());
> + SqlNode sqlCondition = null;
> + SqlLiteral condType = JoinConditionType.ON.symbol(POS);
> + if (e.getCondition().isAlwaysTrue()) {
> + condType = JoinConditionType.NONE.symbol(POS);
> + } else {
> + sqlCondition = convertConditionToSqlNode(e.getCondition(),
> + leftContext,
> + rightContext,
> + e.getLeft().getRowType().getFieldCount());
> + }
> SqlNode join =
> new SqlJoin(POS,
> leftResult.asFrom(),
> SqlLiteral.createBoolean(false, POS),
> joinType(e.getJoinType()).symbol(POS),
> rightResult.asFrom(),
> - JoinConditionType.ON.symbol(POS),
> + condType,
> sqlCondition);
> return result(join, leftResult, rightResult);
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)