Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,20 @@
},
"WRONG_NUM_ARGS" : {
"message" : [
"The <functionName> requires <expectedNum> parameters but the actual number is <actualNum>."
]
"Invalid number of arguments for the function <functionName>."
],
"subClass" : {
"WITHOUT_SUGGESTION" : {
"message" : [
"Please, refer to 'https://spark.apache.org/docs/latest/sql-ref-functions.html' for a fix."
]
},
"WITH_SUGGESTION" : {
"message" : [
"Consider to change the number of arguments because the function requires <expectedNum> parameters but the actual number is <actualNum>."
]
}
}
},
"_LEGACY_ERROR_TEMP_0001" : {
"message" : [
Expand Down Expand Up @@ -2007,11 +2019,6 @@
"Undefined function <name>."
]
},
"_LEGACY_ERROR_TEMP_1043" : {
"message" : [
"Invalid arguments for function <name>."
]
},
"_LEGACY_ERROR_TEMP_1045" : {
"message" : [
"ALTER TABLE SET LOCATION does not support partition for v2 tables."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase {
def invalidFunctionArgumentsError(
name: String, expectedNum: String, actualNum: Int): Throwable = {
new AnalysisException(
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
messageParameters = Map(
"functionName" -> toSQLId(name),
"expectedNum" -> expectedNum,
Expand All @@ -649,10 +649,10 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase {

def invalidFunctionArgumentNumberError(
validParametersCount: Seq[Int], name: String, actualNumber: Int): Throwable = {
if (validParametersCount.length == 0) {
if (validParametersCount.isEmpty) {
new AnalysisException(
errorClass = "_LEGACY_ERROR_TEMP_1043",
messageParameters = Map("name" -> name))
errorClass = "WRONG_NUM_ARGS.WITHOUT_SUGGESTION",
messageParameters = Map("functionName" -> toSQLId(name)))
} else {
val expectedNumberOfParameters = if (validParametersCount.length == 1) {
validParametersCount.head.toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "1",
"expectedNum" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "0",
"expectedNum" : "2",
Expand All @@ -844,7 +844,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "1",
"expectedNum" : "2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "3",
"expectedNum" : "2",
Expand Down Expand Up @@ -297,7 +297,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "3",
"expectedNum" : "2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "0",
"expectedNum" : "[2, 3]",
Expand Down
2 changes: 1 addition & 1 deletion sql/core/src/test/resources/sql-tests/results/date.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "1",
"expectedNum" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "1",
"expectedNum" : "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "0",
"expectedNum" : "[1, 2]",
Expand Down Expand Up @@ -231,7 +231,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "0",
"expectedNum" : "[2, 3]",
Expand Down Expand Up @@ -572,7 +572,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "0",
"expectedNum" : "1",
Expand Down Expand Up @@ -659,7 +659,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "0",
"expectedNum" : "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "2",
"expectedNum" : "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "0",
"expectedNum" : "2",
Expand All @@ -776,7 +776,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "1",
"expectedNum" : "2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ org.apache.spark.sql.AnalysisException
"errorClass" : "_LEGACY_ERROR_TEMP_1179",
"messageParameters" : {
"arguments" : "integer, integer, integer, integer, integer",
"details" : "[WRONG_NUM_ARGS] The `range` requires [1, 2, 3, 4] parameters but the actual number is 5.",
"details" : "[WRONG_NUM_ARGS.WITH_SUGGESTION] Invalid number of arguments for the function `range`. Consider to change the number of arguments because the function requires [1, 2, 3, 4] parameters but the actual number is 5.",
"name" : "range",
"usage" : "\n range(start: long, end: long, step: long, numSlices: integer)\n range(start: long, end: long, step: long)\n range(start: long, end: long)\n range(end: long)"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "7",
"expectedNum" : "6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "2",
"expectedNum" : "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "WRONG_NUM_ARGS",
"errorClass" : "WRONG_NUM_ARGS.WITH_SUGGESTION",
"messageParameters" : {
"actualNum" : "2",
"expectedNum" : "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4881,7 +4881,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
exception = intercept[AnalysisException] {
df.selectExpr("zip_with(a1, a2, (acc, x) -> x, (acc, x) -> x)")
},
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
parameters = Map(
"functionName" -> toSQLId("zip_with"),
"expectedNum" -> "3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DateFunctionsSuite extends QueryTest with SharedSparkSession {
exception = intercept[AnalysisException] {
sql("SELECT CURDATE(1)")
},
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
parameters = Map(
"functionName" -> "`curdate`",
"expectedNum" -> "0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2634,7 +2634,7 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
exception = intercept[AnalysisException] {
sql("SELECT nvl(1, 2, 3)")
},
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
parameters = Map(
"functionName" -> toSQLId("nvl"),
"expectedNum" -> "2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class StringFunctionsSuite extends QueryTest with SharedSparkSession {
exception = intercept[AnalysisException] {
df.selectExpr("sentences()")
},
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
parameters = Map(
"functionName" -> toSQLId("sentences"),
"expectedNum" -> "[1, 2, 3]",
Expand Down
11 changes: 2 additions & 9 deletions sql/core/src/test/scala/org/apache/spark/sql/UDFSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class UDFSuite extends QueryTest with SharedSparkSession {
exception = intercept[AnalysisException] {
df.selectExpr("substr('abcd', 2, 3, 4)")
},
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
parameters = Map(
"functionName" -> toSQLId("substr"),
"expectedNum" -> "[2, 3]",
Expand All @@ -125,7 +125,7 @@ class UDFSuite extends QueryTest with SharedSparkSession {
spark.udf.register("foo", (_: String).length)
df.selectExpr("foo(2, 3, 4)")
},
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
parameters = Map(
"functionName" -> toSQLId("foo"),
"expectedNum" -> "1",
Expand Down Expand Up @@ -637,13 +637,6 @@ class UDFSuite extends QueryTest with SharedSparkSession {
assert(spark.range(2).select(nonDeterministicJavaUDF()).distinct().count() == 2)
}

test("SPARK-28521 error message for CAST(parameter types contains DataType)") {
val e = intercept[AnalysisException] {
spark.sql("SELECT CAST(1)")
}
assert(e.getMessage.contains("Invalid arguments for function cast"))
}

test("only one case class parameter") {
val f = (d: TestData) => d.key * d.value.toInt
val myUdf = udf(f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,19 @@ class QueryCompilationErrorsSuite
errorClass = "DATATYPE_MISMATCH.INVALID_JSON_SCHEMA",
parameters = Map("schema" -> "\"INT\"", "sqlExpr" -> "\"from_json(a)\""))
}

test("WRONG_NUM_ARGS.WITHOUT_SUGGESTION: wrong args of CAST(parameter types contains DataType)") {
checkError(
exception = intercept[AnalysisException] {
sql("SELECT CAST(1)")
},
errorClass = "WRONG_NUM_ARGS.WITHOUT_SUGGESTION",
parameters = Map(
"functionName" -> "`cast`"
),
context = ExpectedContext("", "", 7, 13, "CAST(1)")
)
}
}

class MyCastToString extends SparkUserDefinedFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class HiveUDAFSuite extends QueryTest
exception = intercept[AnalysisException] {
sql(s"SELECT $functionName(100)")
},
errorClass = "WRONG_NUM_ARGS",
errorClass = "WRONG_NUM_ARGS.WITH_SUGGESTION",
parameters = Map(
"functionName" -> toSQLId("longProductSum"),
"expectedNum" -> "2",
Expand Down