[SPARK-48014][SQL] Change the makeFromJava error in EvaluatePython to a user-facing error
### What changes were proposed in this pull request?
This PR changes the error in EvaluatePython from an internal error to a user-facing error with an error class.
### Why are the changes needed?
To move an error from internal-facing to user-facing.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #46250 from allisonwang-db/spark-48014-eval-py-error.
Authored-by: allisonwang-db <allison.wang@databricks.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
diff --git a/common/utils/src/main/resources/error/error-conditions.json b/common/utils/src/main/resources/error/error-conditions.json
index ead1076..43af804 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -3798,6 +3798,12 @@
],
"sqlState" : "XXKST"
},
+ "STRUCT_ARRAY_LENGTH_MISMATCH" : {
+ "message" : [
+ "Input row doesn't have expected number of values required by the schema. <expected> fields are required while <actual> values are provided."
+ ],
+ "sqlState" : "2201E"
+ },
"SUM_OF_LIMIT_AND_OFFSET_EXCEEDS_MAX_INT" : {
"message" : [
"The sum of the LIMIT clause and the OFFSET clause must not be greater than the maximum 32-bit integer value (2,147,483,647) but found limit = <limit>, offset = <offset>."
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/python/EvaluatePython.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/python/EvaluatePython.scala
index d692135..fca277d 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/python/EvaluatePython.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/python/EvaluatePython.scala
@@ -24,7 +24,7 @@
import net.razorvine.pickle.{IObjectPickler, Opcodes, Pickler}
-import org.apache.spark.SparkException
+import org.apache.spark.SparkIllegalArgumentException
import org.apache.spark.api.python.SerDeUtil
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.catalyst.InternalRow
@@ -183,10 +183,11 @@
case c if c.getClass.isArray =>
val array = c.asInstanceOf[Array[_]]
if (array.length != fields.length) {
- throw SparkException.internalError(
- s"Input row doesn't have expected number of values required by the schema. " +
- s"${fields.length} fields are required while ${array.length} values are provided."
- )
+ throw new SparkIllegalArgumentException(
+ errorClass = "STRUCT_ARRAY_LENGTH_MISMATCH",
+ messageParameters = Map(
+ "expected" -> fields.length.toString,
+ "actual" -> array.length.toString))
}
val row = new GenericInternalRow(fields.length)