From bbc23dace0d63c1237d4c1a58f9b79c2241dfbd8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 9 Oct 2025 09:40:03 +0000 Subject: [PATCH] Fix join type ambiguous issue when specify the join type with sql-like join criteria (#4474) Signed-off-by: Lantao Jin (cherry picked from commit 3d2043d4d02d035b2cd41345823535545d4e1f16) Signed-off-by: github-actions[bot] --- .../opensearch/sql/ppl/parser/AstBuilder.java | 2 +- .../sql/ppl/calcite/CalcitePPLJoinTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java index 2b332e5205c..6d4f5382f5a 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java @@ -224,7 +224,7 @@ public UnresolvedPlan visitJoinCommand(OpenSearchPPLParser.JoinCommandContext ct Argument.ArgumentMap argumentMap = Argument.ArgumentMap.of(arguments); if (argumentMap.get("type") != null) { Join.JoinType joinTypeFromArgument = ArgumentFactory.getJoinType(argumentMap); - if (sqlLike && joinType != joinTypeFromArgument) { + if (sqlLike && joinType != joinTypeFromArgument && ctx.sqlLikeJoinType() != null) { throw new SemanticCheckException( "Join type is ambiguous, remove either the join type before JOIN keyword or 'type='" + " option."); diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLJoinTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLJoinTest.java index 150121448f4..a837509b160 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLJoinTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLJoinTest.java @@ -1068,4 +1068,26 @@ public void testJoinWithMaxLessThanZero() { Throwable t = Assert.assertThrows(SemanticCheckException.class, () -> getRelNode(ppl)); verifyErrorMessageContains(t, "max option must be a positive integer"); } + + @Test + public void testSqlLikeJoinWithSpecificJoinType() { + String ppl = "source=EMP | join type=left left=l right=r on l.DEPTNO=r.DEPTNO DEPT"; + RelNode root = getRelNode(ppl); + String expectedLogical = + "LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5]," + + " COMM=[$6], DEPTNO=[$7], r.DEPTNO=[$8], DNAME=[$9], LOC=[$10])\n" + + " LogicalJoin(condition=[=($7, $8)], joinType=[left])\n" + + " LogicalTableScan(table=[[scott, EMP]])\n" + + " LogicalTableScan(table=[[scott, DEPT]])\n"; + verifyLogical(root, expectedLogical); + verifyResultCount(root, 14); + + String expectedSparkSql = + "SELECT `EMP`.`EMPNO`, `EMP`.`ENAME`, `EMP`.`JOB`, `EMP`.`MGR`, `EMP`.`HIREDATE`," + + " `EMP`.`SAL`, `EMP`.`COMM`, `EMP`.`DEPTNO`, `DEPT`.`DEPTNO` `r.DEPTNO`," + + " `DEPT`.`DNAME`, `DEPT`.`LOC`\n" + + "FROM `scott`.`EMP`\n" + + "LEFT JOIN `scott`.`DEPT` ON `EMP`.`DEPTNO` = `DEPT`.`DEPTNO`"; + verifyPPLToSparkSQL(root, expectedSparkSql); + } }