Skip to content

Commit 4dc6719

Browse files
henryrHyukjinKwon
authored andcommitted
[SPARK-24128][SQL] Mention configuration option in implicit CROSS JOIN error
## What changes were proposed in this pull request? Mention `spark.sql.crossJoin.enabled` in error message when an implicit `CROSS JOIN` is detected. ## How was this patch tested? `CartesianProductSuite` and `JoinSuite`. Author: Henry Robinson <[email protected]> Closes #21201 from henryr/spark-24128. (cherry picked from commit cd12c5c) Signed-off-by: hyukjinkwon <[email protected]>
1 parent 3a22fea commit 4dc6719

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

R/pkg/tests/fulltests/test_sparkSQL.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,8 +2186,8 @@ test_that("join(), crossJoin() and merge() on a DataFrame", {
21862186
expect_equal(count(where(join(df, df2), df$name == df2$name)), 3)
21872187
# cartesian join
21882188
expect_error(tryCatch(count(join(df, df2)), error = function(e) { stop(e) }),
2189-
paste0(".*(org.apache.spark.sql.AnalysisException: Detected cartesian product for",
2190-
" INNER join between logical plans).*"))
2189+
paste0(".*(org.apache.spark.sql.AnalysisException: Detected implicit cartesian",
2190+
" product for INNER join between logical plans).*"))
21912191

21922192
joined <- crossJoin(df, df2)
21932193
expect_equal(names(joined), c("age", "name", "name", "test"))

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,12 +1122,14 @@ object CheckCartesianProducts extends Rule[LogicalPlan] with PredicateHelper {
11221122
case j @ Join(left, right, Inner | LeftOuter | RightOuter | FullOuter, _)
11231123
if isCartesianProduct(j) =>
11241124
throw new AnalysisException(
1125-
s"""Detected cartesian product for ${j.joinType.sql} join between logical plans
1125+
s"""Detected implicit cartesian product for ${j.joinType.sql} join between logical plans
11261126
|${left.treeString(false).trim}
11271127
|and
11281128
|${right.treeString(false).trim}
11291129
|Join condition is missing or trivial.
1130-
|Use the CROSS JOIN syntax to allow cartesian products between these relations."""
1130+
|Either: use the CROSS JOIN syntax to allow cartesian products between these
1131+
|relations, or: enable implicit cartesian products by setting the configuration
1132+
|variable spark.sql.crossJoin.enabled=true"""
11311133
.stripMargin)
11321134
}
11331135
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/CheckCartesianProductsSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CheckCartesianProductsSuite extends PlanTest {
5656
val thrownException = the [AnalysisException] thrownBy {
5757
performCartesianProductCheck(joinType)
5858
}
59-
assert(thrownException.message.contains("Detected cartesian product"))
59+
assert(thrownException.message.contains("Detected implicit cartesian product"))
6060
}
6161
}
6262
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class JoinSuite extends QueryTest with SharedSQLContext {
239239
Row(2, 2, 1, null) ::
240240
Row(2, 2, 2, 2) :: Nil)
241241
}
242-
assert(e.getMessage.contains("Detected cartesian product for INNER join " +
242+
assert(e.getMessage.contains("Detected implicit cartesian product for INNER join " +
243243
"between logical plans"))
244244
}
245245
}
@@ -611,7 +611,7 @@ class JoinSuite extends QueryTest with SharedSQLContext {
611611
val e = intercept[Exception] {
612612
checkAnswer(sql(query), Nil);
613613
}
614-
assert(e.getMessage.contains("Detected cartesian product"))
614+
assert(e.getMessage.contains("Detected implicit cartesian product"))
615615
}
616616

617617
cartesianQueries.foreach(checkCartesianDetection)

0 commit comments

Comments
 (0)