Skip to content
Permalink
Browse files

[SPARK-24128][SQL] Mention configuration option in implicit CROSS JOI…

…N 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 <henry@apache.org>

Closes #21201 from henryr/spark-24128.

(cherry picked from commit cd12c5c)
Signed-off-by: hyukjinkwon <gurwls223@apache.org>
  • Loading branch information...
henryr authored and HyukjinKwon committed May 8, 2018
1 parent 3a22fea commit 4dc6719e9afdd0f0ba134bfc69f042f7796ff2cd
@@ -2186,8 +2186,8 @@ test_that("join(), crossJoin() and merge() on a DataFrame", {
expect_equal(count(where(join(df, df2), df$name == df2$name)), 3)
# cartesian join
expect_error(tryCatch(count(join(df, df2)), error = function(e) { stop(e) }),
paste0(".*(org.apache.spark.sql.AnalysisException: Detected cartesian product for",
" INNER join between logical plans).*"))
paste0(".*(org.apache.spark.sql.AnalysisException: Detected implicit cartesian",
" product for INNER join between logical plans).*"))

joined <- crossJoin(df, df2)
expect_equal(names(joined), c("age", "name", "name", "test"))
@@ -1122,12 +1122,14 @@ object CheckCartesianProducts extends Rule[LogicalPlan] with PredicateHelper {
case j @ Join(left, right, Inner | LeftOuter | RightOuter | FullOuter, _)
if isCartesianProduct(j) =>
throw new AnalysisException(
s"""Detected cartesian product for ${j.joinType.sql} join between logical plans
s"""Detected implicit cartesian product for ${j.joinType.sql} join between logical plans
|${left.treeString(false).trim}
|and
|${right.treeString(false).trim}
|Join condition is missing or trivial.
|Use the CROSS JOIN syntax to allow cartesian products between these relations."""
|Either: use the CROSS JOIN syntax to allow cartesian products between these
|relations, or: enable implicit cartesian products by setting the configuration
|variable spark.sql.crossJoin.enabled=true"""
.stripMargin)
}
}
@@ -56,7 +56,7 @@ class CheckCartesianProductsSuite extends PlanTest {
val thrownException = the [AnalysisException] thrownBy {
performCartesianProductCheck(joinType)
}
assert(thrownException.message.contains("Detected cartesian product"))
assert(thrownException.message.contains("Detected implicit cartesian product"))
}
}
}
@@ -239,7 +239,7 @@ class JoinSuite extends QueryTest with SharedSQLContext {
Row(2, 2, 1, null) ::
Row(2, 2, 2, 2) :: Nil)
}
assert(e.getMessage.contains("Detected cartesian product for INNER join " +
assert(e.getMessage.contains("Detected implicit cartesian product for INNER join " +
"between logical plans"))
}
}
@@ -611,7 +611,7 @@ class JoinSuite extends QueryTest with SharedSQLContext {
val e = intercept[Exception] {
checkAnswer(sql(query), Nil);
}
assert(e.getMessage.contains("Detected cartesian product"))
assert(e.getMessage.contains("Detected implicit cartesian product"))
}

cartesianQueries.foreach(checkCartesianDetection)

0 comments on commit 4dc6719

Please sign in to comment.
You can’t perform that action at this time.