You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jess Balint (JIRA)" <ji...@apache.org> on 2017/01/17 15:08:26 UTC

[jira] [Created] (CALCITE-1582) RelToSqlConverter doesn't handle cartesian join (no join cond)

Jess Balint created CALCITE-1582:
------------------------------------

             Summary: 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


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)