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/25 21:46:26 UTC

[jira] [Resolved] (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:all-tabpanel ]

Julian Hyde resolved CALCITE-1582.
----------------------------------
       Resolution: Fixed
    Fix Version/s: 1.12.0

Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/499b55e3. Thanks for the PR, [~jbalint@gmail.com]!

> 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
>             Fix For: 1.12.0
>
>
> 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)