Skip to content

Commit

Permalink
[SPARK-45614][SQL] Assign name to the error _LEGACY_ERROR_TEMP_215[6,…
Browse files Browse the repository at this point in the history
…7,8]
  • Loading branch information
dengziming committed Oct 20, 2023
1 parent b9ac7d3 commit 9cb63e1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 18 deletions.
33 changes: 18 additions & 15 deletions common/utils/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,18 @@
],
"sqlState" : "42846"
},
"UNEXPECTED_VALUE_FOR_LENGTH_IN_SLICE_FUNCTION" : {
"message" : [
"Unexpected value for length in function <prettyName>: length must be greater than or equal to 0."
],
"sqlState" : "22003"
},
"UNEXPECTED_VALUE_FOR_START_IN_SLICE_FUNCTION" : {
"message" : [
"Unexpected value for start in function <prettyName>: SQL array indices start at 1."
],
"sqlState" : "22003"
},
"UNKNOWN_PROTOBUF_MESSAGE_TYPE" : {
"message" : [
"Attempting to treat <descriptorName> as a Message, but it was <containingType>."
Expand Down Expand Up @@ -3213,6 +3225,12 @@
],
"sqlState" : "0A000"
},
"UNSUPPORTED_DATA_TYPE_FOR_SIZE_FUNCTION" : {
"message" : [
"The size function doesn't support the operand type <dataType>."
],
"sqlState" : "42K09"
},
"UNSUPPORTED_DEFAULT_VALUE" : {
"message" : [
"DEFAULT column values is not supported."
Expand Down Expand Up @@ -5734,21 +5752,6 @@
"<userClass> is not annotated with SQLUserDefinedType nor registered with UDTRegistration.}"
]
},
"_LEGACY_ERROR_TEMP_2156" : {
"message" : [
"The size function doesn't support the operand type <dataType>."
]
},
"_LEGACY_ERROR_TEMP_2157" : {
"message" : [
"Unexpected value for start in function <prettyName>: SQL array indices start at 1."
]
},
"_LEGACY_ERROR_TEMP_2158" : {
"message" : [
"Unexpected value for length in function <prettyName>: length must be greater than or equal to 0."
]
},
"_LEGACY_ERROR_TEMP_2159" : {
"message" : [
"Unsuccessful try to concat arrays with <numberOfElements> elements due to exceeding the array size limit <maxRoundedArrayLength>."
Expand Down
18 changes: 18 additions & 0 deletions docs/sql-error-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,18 @@ Cannot invoke function `<functionName>` because it contains positional argument(

The class `<className>` has an unexpected expression serializer. Expects "STRUCT" or "IF" which returns "STRUCT" but found `<expr>`.

### UNEXPECTED_VALUE_FOR_LENGTH_IN_SLICE_FUNCTION

[SQLSTATE: 22003](sql-error-conditions-sqlstates.html#class-22-data-exception)

Unexpected value for length in function `<prettyName>`: length must be greater than or equal to 0.

### UNEXPECTED_VALUE_FOR_START_IN_SLICE_FUNCTION

[SQLSTATE: 22003](sql-error-conditions-sqlstates.html#class-22-data-exception)

Unexpected value for start in function `<prettyName>`: SQL array indices start at 1.

### UNKNOWN_PROTOBUF_MESSAGE_TYPE

[SQLSTATE: 42K0G](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation)
Expand Down Expand Up @@ -2097,6 +2109,12 @@ Unsupported data type `<typeName>`.

The `<format>` datasource doesn't support the column `<columnName>` of the type `<columnType>`.

### UNSUPPORTED_DATA_TYPE_FOR_SIZE_FUNCTION

[SQLSTATE: 42K09](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation)

The size function doesn't support the operand type `<dataType>`.

### [UNSUPPORTED_DEFAULT_VALUE](sql-error-conditions-unsupported-default-value-error-class.html)

[SQLSTATE: 0A000](sql-error-conditions-sqlstates.html#class-0A-feature-not-supported)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,21 +1370,21 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
def unsupportedOperandTypeForSizeFunctionError(
dataType: DataType): SparkUnsupportedOperationException = {
new SparkUnsupportedOperationException(
errorClass = "_LEGACY_ERROR_TEMP_2156",
errorClass = "UNSUPPORTED_DATA_TYPE_FOR_SIZE_FUNCTION",
messageParameters = Map(
"dataType" -> dataType.getClass.getCanonicalName))
}

def unexpectedValueForStartInFunctionError(prettyName: String): SparkRuntimeException = {
new SparkRuntimeException(
errorClass = "_LEGACY_ERROR_TEMP_2157",
errorClass = "UNEXPECTED_VALUE_FOR_START_IN_SLICE_FUNCTION",
messageParameters = Map(
"prettyName" -> prettyName))
}

def unexpectedValueForLengthInFunctionError(prettyName: String): SparkRuntimeException = {
new SparkRuntimeException(
errorClass = "_LEGACY_ERROR_TEMP_2158",
errorClass = "UNEXPECTED_VALUE_FOR_LENGTH_IN_SLICE_FUNCTION",
messageParameters = Map(
"prettyName" -> prettyName))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
}
}

test("Unsupported data type for size()") {
val exception = intercept[org.apache.spark.SparkUnsupportedOperationException] {
Size(Literal.create("str", StringType)).eval(EmptyRow)
}
checkError(
exception = exception,
errorClass = "UNSUPPORTED_DATA_TYPE_FOR_SIZE_FUNCTION",
parameters = Map(
"dataType" -> StringType.getClass.getCanonicalName
))
}

test("MapKeys/MapValues") {
val m0 = Literal.create(Map("a" -> "1", "b" -> "2"), MapType(StringType, StringType))
val m1 = Literal.create(Map[String, String](), MapType(StringType, StringType))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.sql

import org.apache.spark.{SparkFunSuite, SparkRuntimeException}
import org.apache.spark.sql.test.SharedSparkSession

class CollectionFunctionsSuite extends SparkFunSuite with SharedSparkSession {

test("Unexpected `start` for slice()") {
checkError(
exception = intercept[SparkRuntimeException] {
sql("select slice(array(1,2,3), 0, 1)").collect()
},
errorClass = "UNEXPECTED_VALUE_FOR_START_IN_SLICE_FUNCTION",
parameters = Map("prettyName" -> "slice")
)
}

test("Unexpected `length` for slice()") {
checkError(
exception = intercept[SparkRuntimeException] {
sql("select slice(array(1,2,3), 1, -1)").collect()
},
errorClass = "UNEXPECTED_VALUE_FOR_LENGTH_IN_SLICE_FUNCTION",
parameters = Map("prettyName" -> "slice")
)
}

}

0 comments on commit 9cb63e1

Please sign in to comment.