Skip to content

Commit fb8cd54

Browse files
committed
[SPARK-24385][SQL] Resolve self-join condition ambiguity for EqualNullSafe
1 parent bc11146 commit fb8cd54

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,11 @@ class Dataset[T] private[sql](
10181018
catalyst.expressions.EqualTo(
10191019
withPlan(plan.left).resolve(a.name),
10201020
withPlan(plan.right).resolve(b.name))
1021+
case catalyst.expressions.EqualNullSafe(a: AttributeReference, b: AttributeReference)
1022+
if a.sameRef(b) =>
1023+
catalyst.expressions.EqualNullSafe(
1024+
withPlan(plan.left).resolve(a.name),
1025+
withPlan(plan.right).resolve(b.name))
10211026
}}
10221027

10231028
withPlan {

sql/core/src/test/scala/org/apache/spark/sql/DataFrameJoinSuite.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,12 @@ class DataFrameJoinSuite extends QueryTest with SharedSQLContext {
287287
dfOne.join(dfTwo, $"a" === $"b", "left").queryExecution.optimizedPlan
288288
}
289289
}
290+
291+
test("SPARK-24385: Resolve ambiguity in self-joins with EqualNullSafe") {
292+
withSQLConf(SQLConf.CROSS_JOINS_ENABLED.key -> "false") {
293+
val df = spark.range(2)
294+
// this throws an exception before the fix
295+
df.join(df, df("id") <=> df("id")).queryExecution.optimizedPlan
296+
}
297+
}
290298
}

0 commit comments

Comments
 (0)