Skip to content

Commit 738129d

Browse files
committed
Pass on join type of logical correlate to lateral join (1858/2027)
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 5564f26 commit 738129d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/validate/PplRelToSqlNodeConverter.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55

66
package org.opensearch.sql.calcite.validate;
77

8+
import org.apache.calcite.rel.core.Correlate;
9+
import org.apache.calcite.rel.core.JoinRelType;
810
import org.apache.calcite.rel.rel2sql.RelToSqlConverter;
11+
import org.apache.calcite.sql.JoinConditionType;
12+
import org.apache.calcite.sql.JoinType;
913
import org.apache.calcite.sql.SqlDialect;
14+
import org.apache.calcite.sql.SqlJoin;
15+
import org.apache.calcite.sql.SqlLiteral;
16+
import org.apache.calcite.sql.SqlNode;
1017

1118
/**
1219
* An extension of {@link RelToSqlConverter} to convert a relation algebra tree, translated from a
@@ -24,4 +31,26 @@ public class PplRelToSqlNodeConverter extends RelToSqlConverter {
2431
public PplRelToSqlNodeConverter(SqlDialect dialect) {
2532
super(dialect);
2633
}
34+
35+
/** Override Correlate visitor to pass on join type */
36+
@Override
37+
public Result visit(Correlate e) {
38+
Result result = super.visit(e);
39+
SqlNode from = result.asSelect().getFrom();
40+
if (e.getJoinType() != JoinRelType.INNER && from instanceof SqlJoin join) {
41+
JoinType joinType;
42+
try {
43+
joinType = JoinType.valueOf(e.getJoinType().name());
44+
} catch (IllegalArgumentException ignored) {
45+
return result;
46+
}
47+
join.setOperand(2, joinType.symbol(POS));
48+
// INNER, LEFT, RIGHT, FULL, or ASOF join requires a condition
49+
// Use ON TRUE to satisfy SQL syntax because the actual correlation condition logic is inside
50+
// the subquery's WHERE clause
51+
join.setOperand(4, JoinConditionType.ON.symbol(POS));
52+
join.setOperand(5, SqlLiteral.createBoolean(true, POS));
53+
}
54+
return result;
55+
}
2756
}

0 commit comments

Comments
 (0)