From 9cb63e1baee99cf0d47af08656baa57854b77143 Mon Sep 17 00:00:00 2001 From: dengziming Date: Fri, 20 Oct 2023 10:55:43 +0800 Subject: [PATCH] [SPARK-45614][SQL] Assign name to the error _LEGACY_ERROR_TEMP_215[6,7,8] --- .../main/resources/error/error-classes.json | 33 +++++++------- docs/sql-error-conditions.md | 18 ++++++++ .../sql/errors/QueryExecutionErrors.scala | 6 +-- .../CollectionExpressionsSuite.scala | 12 +++++ .../spark/sql/CollectionFunctionsSuite.scala | 45 +++++++++++++++++++ 5 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 sql/core/src/test/scala/org/apache/spark/sql/CollectionFunctionsSuite.scala diff --git a/common/utils/src/main/resources/error/error-classes.json b/common/utils/src/main/resources/error/error-classes.json index 5082165a4b3ec..c327b2f23fd22 100644 --- a/common/utils/src/main/resources/error/error-classes.json +++ b/common/utils/src/main/resources/error/error-classes.json @@ -3029,6 +3029,18 @@ ], "sqlState" : "42846" }, + "UNEXPECTED_VALUE_FOR_LENGTH_IN_SLICE_FUNCTION" : { + "message" : [ + "Unexpected value for length in function : 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 : SQL array indices start at 1." + ], + "sqlState" : "22003" + }, "UNKNOWN_PROTOBUF_MESSAGE_TYPE" : { "message" : [ "Attempting to treat as a Message, but it was ." @@ -3213,6 +3225,12 @@ ], "sqlState" : "0A000" }, + "UNSUPPORTED_DATA_TYPE_FOR_SIZE_FUNCTION" : { + "message" : [ + "The size function doesn't support the operand type ." + ], + "sqlState" : "42K09" + }, "UNSUPPORTED_DEFAULT_VALUE" : { "message" : [ "DEFAULT column values is not supported." @@ -5734,21 +5752,6 @@ " is not annotated with SQLUserDefinedType nor registered with UDTRegistration.}" ] }, - "_LEGACY_ERROR_TEMP_2156" : { - "message" : [ - "The size function doesn't support the operand type ." - ] - }, - "_LEGACY_ERROR_TEMP_2157" : { - "message" : [ - "Unexpected value for start in function : SQL array indices start at 1." - ] - }, - "_LEGACY_ERROR_TEMP_2158" : { - "message" : [ - "Unexpected value for length in function : length must be greater than or equal to 0." - ] - }, "_LEGACY_ERROR_TEMP_2159" : { "message" : [ "Unsuccessful try to concat arrays with elements due to exceeding the array size limit ." diff --git a/docs/sql-error-conditions.md b/docs/sql-error-conditions.md index f22e527374604..2537eca2e5484 100644 --- a/docs/sql-error-conditions.md +++ b/docs/sql-error-conditions.md @@ -1953,6 +1953,18 @@ Cannot invoke function `` because it contains positional argument( The class `` has an unexpected expression serializer. Expects "STRUCT" or "IF" which returns "STRUCT" but found ``. +### UNEXPECTED_VALUE_FOR_LENGTH_IN_SLICE_FUNCTION + +[SQLSTATE: 22003](sql-error-conditions-sqlstates.html#class-22-data-exception) + +Unexpected value for length in function ``: 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 ``: 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) @@ -2097,6 +2109,12 @@ Unsupported data type ``. The `` datasource doesn't support the column `` of the type ``. +### 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 ``. + ### [UNSUPPORTED_DEFAULT_VALUE](sql-error-conditions-unsupported-default-value-error-class.html) [SQLSTATE: 0A000](sql-error-conditions-sqlstates.html#class-0A-feature-not-supported) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala index a11b929919dd9..c71077e290d44 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala @@ -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)) } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala index ff393857c31ce..80febfd8cda92 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala @@ -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)) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/CollectionFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/CollectionFunctionsSuite.scala new file mode 100644 index 0000000000000..e967a9b8e4663 --- /dev/null +++ b/sql/core/src/test/scala/org/apache/spark/sql/CollectionFunctionsSuite.scala @@ -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") + ) + } + +}