diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala index 35fd800df4a4f..73884d7a09c21 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala @@ -445,7 +445,10 @@ object FunctionRegistry { // If there is an apply method that accepts Seq[Expression], use that one. Try(varargCtor.get.newInstance(expressions).asInstanceOf[Expression]) match { case Success(e) => e - case Failure(e) => throw new AnalysisException(e.getMessage) + case Failure(e) => + // the exception is an invocation exception. To get a meaningful message, we need the + // cause. + throw new AnalysisException(e.getCause.getMessage) } } else { // Otherwise, find a constructor method that matches the number of arguments, and use that. diff --git a/sql/core/src/test/resources/sql-tests/inputs/string-functions.sql b/sql/core/src/test/resources/sql-tests/inputs/string-functions.sql new file mode 100644 index 0000000000000..21a0aa66c098a --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/string-functions.sql @@ -0,0 +1,3 @@ +-- Argument number exception +select concat_ws(); +select format_string(); \ No newline at end of file diff --git a/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out b/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out new file mode 100644 index 0000000000000..6961e9b65922f --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out @@ -0,0 +1,20 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 2 + + +-- !query 0 +select concat_ws() +-- !query 0 schema +struct<> +-- !query 0 output +org.apache.spark.sql.AnalysisException +requirement failed: concat_ws requires at least one argument.; line 1 pos 7 + + +-- !query 1 +select format_string() +-- !query 1 schema +struct<> +-- !query 1 output +org.apache.spark.sql.AnalysisException +requirement failed: format_string() should take at least 1 argument; line 1 pos 7