Skip to content

Commit

Permalink
[SPARK-24128][SQL] Mention configuration option in implicit CROSS JOI…
Browse files Browse the repository at this point in the history
…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 4dc6719
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions R/pkg/tests/fulltests/test_sparkSQL.R
Expand Up @@ -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"))
Expand Down
Expand Up @@ -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)
}
}
Expand Down
Expand Up @@ -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"))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions sql/core/src/test/scala/org/apache/spark/sql/JoinSuite.scala
Expand Up @@ -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"))
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4dc6719

Please sign in to comment.