Skip to content

Commit

Permalink
[CALCITE-3207] Fail to convert Join RelNode with like condition to sq…
Browse files Browse the repository at this point in the history
…l statement (wojustme)

close apache#1328
  • Loading branch information
xurenhe authored and danny0405 committed Jul 30, 2019
1 parent 0061b2a commit 3309396
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public static SqlNode convertConditionToSqlNode(RexNode node,
case GREATER_THAN_OR_EQUAL:
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
case LIKE:
node = stripCastFromString(node);
operands = ((RexCall) node).getOperands();
op = ((RexCall) node).getOperator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.calcite.plan.hep.HepProgram;
import org.apache.calcite.plan.hep.HepProgramBuilder;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.rules.UnionMergeRule;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
Expand Down Expand Up @@ -614,6 +615,35 @@ private static String toSql(RelNode root, SqlDialect dialect) {
assertThat(toSql(root, dialect), isLinux(expectedSql));
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-3207">[CALCITE-3207]
* Fail to convert Join RelNode with like condition to sql statement </a>.
*/
@Test public void testJoinWithLikeConditionRel2Sql() {
final RelBuilder builder = relBuilder();
final RelNode rel = builder
.scan("EMP")
.scan("DEPT")
.join(JoinRelType.LEFT,
builder.and(
builder.call(SqlStdOperatorTable.EQUALS,
builder.field(2, 0, "DEPTNO"),
builder.field(2, 1, "DEPTNO")
),
builder.call(SqlStdOperatorTable.LIKE,
builder.field(2, 1, "DNAME"),
builder.literal("ACCOUNTING")
)
)).build();
final String sql = toSql(rel);
final String expectedSql = "SELECT *\n"
+ "FROM \"scott\".\"EMP\"\n"
+ "LEFT JOIN \"scott\".\"DEPT\" "
+ "ON \"EMP\".\"DEPTNO\" = \"DEPT\".\"DEPTNO\" "
+ "AND \"DEPT\".\"DNAME\" LIKE 'ACCOUNTING'";
assertThat(sql, isLinux(expectedSql));
}

@Test public void testSelectQueryWithGroupByAndProjectList1() {
String query =
"select count(*) from \"product\" group by \"product_class_id\", \"product_id\"";
Expand Down

0 comments on commit 3309396

Please sign in to comment.