Skip to content

Commit

Permalink
[SPARK-50096][SQL] Assign appropriate error condition for `_LEGACY_ER…
Browse files Browse the repository at this point in the history
…ROR_TEMP_2150`: `TUPLE_SIZE_EXCEEDS_LIMIT`

### What changes were proposed in this pull request?

This PR proposes to assign proper error condition & sqlstate for `_LEGACY_ERROR_TEMP_2150`: `TUPLE_SIZE_EXCEEDS_LIMIT`

### Why are the changes needed?

To improve the error message by assigning proper error condition and SQLSTATE

### Does this PR introduce _any_ user-facing change?

No, only user-facing error message improved

### How was this patch tested?

Updated the existing tests

### Was this patch authored or co-authored using generative AI tooling?

No

Closes #48631 from itholic/LEGACY_2150.

Lead-authored-by: Haejoon Lee <[email protected]>
Co-authored-by: Haejoon Lee <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
  • Loading branch information
2 people authored and MaxGekk committed Nov 6, 2024
1 parent 4418f24 commit 737a65e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
17 changes: 12 additions & 5 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4641,6 +4641,18 @@
],
"sqlState" : "42K09"
},
"TUPLE_IS_EMPTY" : {
"message" : [
"Due to Scala's limited support of tuple, empty tuple is not supported."
],
"sqlState" : "22004"
},
"TUPLE_SIZE_EXCEEDS_LIMIT" : {
"message" : [
"Due to Scala's limited support of tuple, tuples with more than 22 elements are not supported."
],
"sqlState" : "54011"
},
"UDTF_ALIAS_NUMBER_MISMATCH" : {
"message" : [
"The number of aliases supplied in the AS clause does not match the number of columns output by the UDTF.",
Expand Down Expand Up @@ -7249,11 +7261,6 @@
"null value found but field <name> is not nullable."
]
},
"_LEGACY_ERROR_TEMP_2150" : {
"message" : [
"Due to Scala's limited support of tuple, tuple with more than 22 elements are not supported."
]
},
"_LEGACY_ERROR_TEMP_2154" : {
"message" : [
"Failed to get outer pointer for <innerCls>."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ object AgnosticEncoders {
encoders: Seq[AgnosticEncoder[_]],
elementsCanBeNull: Boolean = false): AgnosticEncoder[_] = {
val numElements = encoders.size
if (numElements < 1 || numElements > MAX_TUPLE_ELEMENTS) {
if (numElements < 1) {
throw ExecutionErrors.emptyTupleNotSupportedError()
} else if (numElements > MAX_TUPLE_ELEMENTS) {
throw ExecutionErrors.elementsOfTupleExceedLimitError()
}
val fields = encoders.zipWithIndex.map { case (e, id) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ private[sql] trait ExecutionErrors extends DataTypeErrorsBase {
}

def elementsOfTupleExceedLimitError(): SparkUnsupportedOperationException = {
new SparkUnsupportedOperationException("_LEGACY_ERROR_TEMP_2150")
new SparkUnsupportedOperationException("TUPLE_SIZE_EXCEEDS_LIMIT")
}

def emptyTupleNotSupportedError(): SparkUnsupportedOperationException = {
new SparkUnsupportedOperationException("TUPLE_IS_EMPTY")
}

def invalidAgnosticEncoderError(encoder: AnyRef): Throwable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,18 @@ class ExpressionEncoderSuite extends CodegenInterpretedPlanTest with AnalysisTes
exception = intercept[SparkUnsupportedOperationException] {
Encoders.tupleEncoder(encoders: _*)
},
condition = "_LEGACY_ERROR_TEMP_2150",
condition = "TUPLE_SIZE_EXCEEDS_LIMIT",
parameters = Map.empty)
}

test("throw exception for empty tuple") {
val encoders = Seq.empty[Encoder[Int]]

checkError(
exception = intercept[SparkUnsupportedOperationException] {
Encoders.tupleEncoder(encoders: _*)
},
condition = "TUPLE_IS_EMPTY",
parameters = Map.empty)
}

Expand Down

0 comments on commit 737a65e

Please sign in to comment.