You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Sergiy Simonov (JIRA)" <ji...@apache.org> on 2017/05/16 12:47:04 UTC
[jira] [Created] (CALCITE-1792) RelToSqlConverter doesn't handle
cartesian join (join cond as TRUE)
Sergiy Simonov created CALCITE-1792:
---------------------------------------
Summary: RelToSqlConverter doesn't handle cartesian join (join cond as TRUE)
Key: CALCITE-1792
URL: https://issues.apache.org/jira/browse/CALCITE-1792
Project: Calcite
Issue Type: Bug
Components: core
Reporter: Sergiy Simonov
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.15#6346)