diff --git a/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala b/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala index 07f9101375ce..dcae4920d01c 100644 --- a/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala +++ b/backends-velox/src/test/scala/org/apache/gluten/execution/TestOperator.scala @@ -1442,6 +1442,68 @@ class TestOperator extends VeloxWholeStageTransformerSuite with AdaptiveSparkPla } } + test("test sort merge join") { + withTable("t1", "t2") { + sql(""" + |create table t1 using parquet as + |select cast(id as int) as c1, cast(id as string) c2 from range(100) + |""".stripMargin) + sql(""" + |create table t2 using parquet as + |select cast(id as int) as c1, cast(id as string) c2 from range(100) order by c1 desc; + |""".stripMargin) + withSQLConf("spark.gluten.sql.columnar.forceShuffledHashJoin" -> "false") { + runQueryAndCompare( + """ + |select * from t1 inner join t2 on t1.c1 = t2.c1 and t1.c1 > 50; + |""".stripMargin + ) { + checkGlutenOperatorMatch[SortMergeJoinExecTransformer] + } + } + + withSQLConf("spark.gluten.sql.columnar.forceShuffledHashJoin" -> "false") { + runQueryAndCompare( + """ + |select * from t1 left join t2 on t1.c1 = t2.c1 and t1.c1 > 50; + |""".stripMargin + ) { + checkGlutenOperatorMatch[SortMergeJoinExecTransformer] + } + } + + withSQLConf("spark.gluten.sql.columnar.forceShuffledHashJoin" -> "false") { + runQueryAndCompare( + """ + |select * from t1 left semi join t2 on t1.c1 = t2.c1 and t1.c1 > 50; + |""".stripMargin + ) { + checkGlutenOperatorMatch[SortMergeJoinExecTransformer] + } + } + + withSQLConf("spark.gluten.sql.columnar.forceShuffledHashJoin" -> "false") { + runQueryAndCompare( + """ + |select * from t1 right join t2 on t1.c1 = t2.c1 and t1.c1 > 50; + |""".stripMargin + ) { + checkGlutenOperatorMatch[SortMergeJoinExecTransformer] + } + } + + withSQLConf("spark.gluten.sql.columnar.forceShuffledHashJoin" -> "false") { + runQueryAndCompare( + """ + |select * from t1 left anti join t2 on t1.c1 = t2.c1 and t1.c1 > 50; + |""".stripMargin + ) { + checkGlutenOperatorMatch[SortMergeJoinExecTransformer] + } + } + } + } + test("Fix incorrect path by decode") { val c = "?.+<_>|/" val path = rootPath + "/test +?.+<_>|" diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc index 6f0b9fadec21..c229ca84fe19 100644 --- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc +++ b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc @@ -906,11 +906,13 @@ bool SubstraitToVeloxPlanValidator::validate(const ::substrait::JoinRel& joinRel switch (joinRel.type()) { case ::substrait::JoinRel_JoinType_JOIN_TYPE_INNER: case ::substrait::JoinRel_JoinType_JOIN_TYPE_LEFT: + case ::substrait::JoinRel_JoinType_JOIN_TYPE_RIGHT: case ::substrait::JoinRel_JoinType_JOIN_TYPE_LEFT_SEMI: case ::substrait::JoinRel_JoinType_JOIN_TYPE_RIGHT_SEMI: + case ::substrait::JoinRel_JoinType_JOIN_TYPE_ANTI: break; default: - LOG_VALIDATION_MSG("Sort merge join only support inner, left, left semi and right semi join."); + LOG_VALIDATION_MSG("Sort merge join type is not supported: " + std::to_string(joinRel.type())); return false; } }