Skip to content

Commit 1c8c47c

Browse files
belieferMaxGekk
authored andcommitted
[SPARK-43914][SQL] Assign names to the error class _LEGACY_ERROR_TEMP_[2433-2437]
### What changes were proposed in this pull request? The pr aims to assign names to the error class _LEGACY_ERROR_TEMP_[2433-2437]. ### Why are the changes needed? Improve the error framework. ### Does this PR introduce _any_ user-facing change? 'No'. ### How was this patch tested? Exists test cases updated. Closes #41476 from beliefer/SPARK-43914. Authored-by: Jiaan Geng <[email protected]> Signed-off-by: Max Gekk <[email protected]>
1 parent 3cd4860 commit 1c8c47c

File tree

4 files changed

+120
-67
lines changed

4 files changed

+120
-67
lines changed

core/src/main/resources/error/error-classes.json

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5637,40 +5637,6 @@
56375637
"Cannot change nullable column to non-nullable: <fieldName>."
56385638
]
56395639
},
5640-
"_LEGACY_ERROR_TEMP_2433" : {
5641-
"message" : [
5642-
"Only a single table generating function is allowed in a SELECT clause, found:",
5643-
"<sqlExprs>."
5644-
]
5645-
},
5646-
"_LEGACY_ERROR_TEMP_2434" : {
5647-
"message" : [
5648-
"Failure when resolving conflicting references in Join:",
5649-
"<plan>",
5650-
"Conflicting attributes: <conflictingAttributes>."
5651-
]
5652-
},
5653-
"_LEGACY_ERROR_TEMP_2435" : {
5654-
"message" : [
5655-
"Failure when resolving conflicting references in Intersect:",
5656-
"<plan>",
5657-
"Conflicting attributes: <conflictingAttributes>."
5658-
]
5659-
},
5660-
"_LEGACY_ERROR_TEMP_2436" : {
5661-
"message" : [
5662-
"Failure when resolving conflicting references in Except:",
5663-
"<plan>",
5664-
"Conflicting attributes: <conflictingAttributes>."
5665-
]
5666-
},
5667-
"_LEGACY_ERROR_TEMP_2437" : {
5668-
"message" : [
5669-
"Failure when resolving conflicting references in AsOfJoin:",
5670-
"<plan>",
5671-
"Conflicting attributes: <conflictingAttributes>."
5672-
]
5673-
},
56745640
"_LEGACY_ERROR_TEMP_2446" : {
56755641
"message" : [
56765642
"Operation not allowed: <cmd> only works on table with location provided: <tableIdentWithDB>"

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,8 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
674674
}
675675

676676
case p @ Project(exprs, _) if containsMultipleGenerators(exprs) =>
677-
p.failAnalysis(
678-
errorClass = "_LEGACY_ERROR_TEMP_2433",
679-
messageParameters = Map("sqlExprs" -> exprs.map(_.sql).mkString(",")))
677+
val generators = exprs.filter(expr => expr.exists(_.isInstanceOf[Generator]))
678+
throw QueryCompilationErrors.moreThanOneGeneratorError(generators, "SELECT")
680679

681680
case p @ Project(projectList, _) =>
682681
projectList.foreach(_.transformDownWithPruning(
@@ -686,36 +685,48 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
686685
})
687686

688687
case j: Join if !j.duplicateResolved =>
689-
val conflictingAttributes = j.left.outputSet.intersect(j.right.outputSet)
690-
j.failAnalysis(
691-
errorClass = "_LEGACY_ERROR_TEMP_2434",
692-
messageParameters = Map(
693-
"plan" -> plan.toString,
694-
"conflictingAttributes" -> conflictingAttributes.mkString(",")))
688+
val conflictingAttributes =
689+
j.left.outputSet.intersect(j.right.outputSet).map(toSQLExpr(_)).mkString(", ")
690+
throw SparkException.internalError(
691+
msg = s"""
692+
|Failure when resolving conflicting references in ${j.nodeName}:
693+
|${planToString(plan)}
694+
|Conflicting attributes: $conflictingAttributes.""".stripMargin,
695+
context = j.origin.getQueryContext,
696+
summary = j.origin.context.summary)
695697

696698
case i: Intersect if !i.duplicateResolved =>
697-
val conflictingAttributes = i.left.outputSet.intersect(i.right.outputSet)
698-
i.failAnalysis(
699-
errorClass = "_LEGACY_ERROR_TEMP_2435",
700-
messageParameters = Map(
701-
"plan" -> plan.toString,
702-
"conflictingAttributes" -> conflictingAttributes.mkString(",")))
699+
val conflictingAttributes =
700+
i.left.outputSet.intersect(i.right.outputSet).map(toSQLExpr(_)).mkString(", ")
701+
throw SparkException.internalError(
702+
msg = s"""
703+
|Failure when resolving conflicting references in ${i.nodeName}:
704+
|${planToString(plan)}
705+
|Conflicting attributes: $conflictingAttributes.""".stripMargin,
706+
context = i.origin.getQueryContext,
707+
summary = i.origin.context.summary)
703708

704709
case e: Except if !e.duplicateResolved =>
705-
val conflictingAttributes = e.left.outputSet.intersect(e.right.outputSet)
706-
e.failAnalysis(
707-
errorClass = "_LEGACY_ERROR_TEMP_2436",
708-
messageParameters = Map(
709-
"plan" -> plan.toString,
710-
"conflictingAttributes" -> conflictingAttributes.mkString(",")))
710+
val conflictingAttributes =
711+
e.left.outputSet.intersect(e.right.outputSet).map(toSQLExpr(_)).mkString(", ")
712+
throw SparkException.internalError(
713+
msg = s"""
714+
|Failure when resolving conflicting references in ${e.nodeName}:
715+
|${planToString(plan)}
716+
|Conflicting attributes: $conflictingAttributes.""".stripMargin,
717+
context = e.origin.getQueryContext,
718+
summary = e.origin.context.summary)
711719

712720
case j: AsOfJoin if !j.duplicateResolved =>
713-
val conflictingAttributes = j.left.outputSet.intersect(j.right.outputSet)
714-
j.failAnalysis(
715-
errorClass = "_LEGACY_ERROR_TEMP_2437",
716-
messageParameters = Map(
717-
"plan" -> plan.toString,
718-
"conflictingAttributes" -> conflictingAttributes.mkString(",")))
721+
val conflictingAttributes =
722+
j.left.outputSet.intersect(j.right.outputSet).map(toSQLExpr(_)).mkString(", ")
723+
throw SparkException.internalError(
724+
msg = s"""
725+
|Failure when resolving conflicting references in ${j.nodeName}:
726+
|${planToString(plan)}
727+
|Conflicting attributes: $conflictingAttributes.""".stripMargin,
728+
context = j.origin.getQueryContext,
729+
summary = j.origin.context.summary)
719730

720731
// TODO: although map type is not orderable, technically map type should be able to be
721732
// used in equality comparison, remove this type check once we support it.

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.apache.spark.sql.catalyst.dsl.plans._
2727
import org.apache.spark.sql.catalyst.expressions._
2828
import org.apache.spark.sql.catalyst.expressions.aggregate.{Count, Max}
2929
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser
30-
import org.apache.spark.sql.catalyst.plans.{Cross, LeftOuter, RightOuter}
30+
import org.apache.spark.sql.catalyst.plans.{AsOfJoinDirection, Cross, Inner, LeftOuter, RightOuter}
3131
import org.apache.spark.sql.catalyst.plans.logical._
3232
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, GenericArrayData, MapData}
3333
import org.apache.spark.sql.internal.SQLConf
@@ -781,11 +781,73 @@ class AnalysisErrorSuite extends AnalysisTest {
781781

782782
test("error test for self-join") {
783783
val join = Join(testRelation, testRelation, Cross, None, JoinHint.NONE)
784-
val error = intercept[AnalysisException] {
785-
SimpleAnalyzer.checkAnalysis(join)
786-
}
787-
assert(error.message.contains("Failure when resolving conflicting references in Join"))
788-
assert(error.message.contains("Conflicting attributes"))
784+
checkError(
785+
exception = intercept[SparkException] {
786+
SimpleAnalyzer.checkAnalysis(join)
787+
},
788+
errorClass = "INTERNAL_ERROR",
789+
parameters = Map("message" ->
790+
"""
791+
|Failure when resolving conflicting references in Join:
792+
|'Join Cross
793+
|:- LocalRelation <empty>, [a#x]
794+
|+- LocalRelation <empty>, [a#x]
795+
|
796+
|Conflicting attributes: "a".""".stripMargin))
797+
}
798+
799+
test("error test for self-intersect") {
800+
val intersect = Intersect(testRelation, testRelation, true)
801+
checkError(
802+
exception = intercept[SparkException] {
803+
SimpleAnalyzer.checkAnalysis(intersect)
804+
},
805+
errorClass = "INTERNAL_ERROR",
806+
parameters = Map("message" ->
807+
"""
808+
|Failure when resolving conflicting references in Intersect All:
809+
|'Intersect All true
810+
|:- LocalRelation <empty>, [a#x]
811+
|+- LocalRelation <empty>, [a#x]
812+
|
813+
|Conflicting attributes: "a".""".stripMargin))
814+
}
815+
816+
test("error test for self-except") {
817+
val except = Except(testRelation, testRelation, true)
818+
checkError(
819+
exception = intercept[SparkException] {
820+
SimpleAnalyzer.checkAnalysis(except)
821+
},
822+
errorClass = "INTERNAL_ERROR",
823+
parameters = Map("message" ->
824+
"""
825+
|Failure when resolving conflicting references in Except All:
826+
|'Except All true
827+
|:- LocalRelation <empty>, [a#x]
828+
|+- LocalRelation <empty>, [a#x]
829+
|
830+
|Conflicting attributes: "a".""".stripMargin))
831+
}
832+
833+
test("error test for self-asOfJoin") {
834+
val asOfJoin =
835+
AsOfJoin(testRelation, testRelation, testRelation.output(0), testRelation.output(0),
836+
None, Inner, tolerance = None, allowExactMatches = true,
837+
direction = AsOfJoinDirection("backward"))
838+
checkError(
839+
exception = intercept[SparkException] {
840+
SimpleAnalyzer.checkAnalysis(asOfJoin)
841+
},
842+
errorClass = "INTERNAL_ERROR",
843+
parameters = Map("message" ->
844+
"""
845+
|Failure when resolving conflicting references in AsOfJoin:
846+
|'AsOfJoin (a#x >= a#x), Inner
847+
|:- LocalRelation <empty>, [a#x]
848+
|+- LocalRelation <empty>, [a#x]
849+
|
850+
|Conflicting attributes: "a".""".stripMargin))
789851
}
790852

791853
test("check grouping expression data types") {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,20 @@ class DataFrameSuite extends QueryTest
364364
Row("a", Seq("a"), 1) :: Nil)
365365
}
366366

367+
test("more than one generator in SELECT clause") {
368+
val df = Seq((Array("a"), 1)).toDF("a", "b")
369+
370+
checkError(
371+
exception = intercept[AnalysisException] {
372+
df.select(explode($"a").as("a"), explode($"a").as("b"))
373+
},
374+
errorClass = "UNSUPPORTED_GENERATOR.MULTI_GENERATOR",
375+
parameters = Map(
376+
"clause" -> "SELECT",
377+
"num" -> "2",
378+
"generators" -> "\"explode(a)\", \"explode(a)\""))
379+
}
380+
367381
test("sort after generate with join=true") {
368382
val df = Seq((Array("a"), 1)).toDF("a", "b")
369383

0 commit comments

Comments
 (0)