You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "HyukjinKwon (via GitHub)" <gi...@apache.org> on 2025/03/07 03:20:31 UTC

[PR] [SPARK-51432][SQL][PYTHON] Throw a proper exception when Arrow schemas are mismatched [spark]

HyukjinKwon opened a new pull request, #50201:
URL: https://github.com/apache/spark/pull/50201

   ### What changes were proposed in this pull request?
   
   This PR proposes to raise a proper error instead of `assert` when the returned Arrow schema is mismatched with specified SQL return type. Users can see this error, and this is not an internal error mssage.
   
   ### Why are the changes needed?
   
   
   ```python
   import pandas as pd
   from pyspark.sql.functions import pandas_udf
   
   @pandas_udf("int")
   def func(s: pd.Series) -> pd.Series:
       return pd.Series([1.0] * len(s))
   
   spark.range(1).select(func("id")).show()
   ```
   
   Now it throws
   
   ```
   org.apache.spark.SparkException: [ARROW_TYPE_MISMATCH] Invalid schema from pandas_udf(): expected IntegerType, got IntegerType. SQLSTATE: 42K0G
   	at org.apache.spark.sql.errors.QueryExecutionErrors$.arrowDataTypeMismatchError(QueryExecutionErrors.scala:857)
   	at org.apache.spark.sql.execution.python.ArrowEvalPythonEvaluatorFactory.$anonfun$evaluate$2(ArrowEvalPythonExec.scala:131)
   	at scala.collection.Iterator$$anon$10.nextCur(Iterator.scala:594)
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, it changes the user-facing error mesasge.
   
   ### How was this patch tested?
   
   Manually tested as described above.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51432][SQL][PYTHON] Throw a proper exception when Arrow schemas are mismatched [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #50201: [SPARK-51432][SQL][PYTHON] Throw a proper exception when Arrow schemas are mismatched
URL: https://github.com/apache/spark/pull/50201


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51432][SQL][PYTHON] Throw a proper exception when Arrow schemas are mismatched [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #50201:
URL: https://github.com/apache/spark/pull/50201#issuecomment-2705692088

   Merged to master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51432][SQL][PYTHON] Throw a proper exception when Arrow schemas are mismatched [spark]

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #50201:
URL: https://github.com/apache/spark/pull/50201#discussion_r1984423181


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/objects.scala:
##########
@@ -252,8 +253,10 @@ case class MapPartitionsInRWithArrowExec(
       val outputProject = UnsafeProjection.create(output, output)
       columnarBatchIter.flatMap { batch =>
         val actualDataTypes = (0 until batch.numCols()).map(i => batch.column(i).dataType())
-        assert(outputTypes == actualDataTypes, "Invalid schema from dapply(): " +
-          s"expected ${outputTypes.mkString(", ")}, got ${actualDataTypes.mkString(", ")}")
+        if (outputTypes == actualDataTypes) {

Review Comment:
   It's opposite? should be ` != `?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51432][SQL][PYTHON] Throw a proper exception when Arrow schemas are mismatched [spark]

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #50201:
URL: https://github.com/apache/spark/pull/50201#discussion_r1984423181


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/objects.scala:
##########
@@ -252,8 +253,10 @@ case class MapPartitionsInRWithArrowExec(
       val outputProject = UnsafeProjection.create(output, output)
       columnarBatchIter.flatMap { batch =>
         val actualDataTypes = (0 until batch.numCols()).map(i => batch.column(i).dataType())
-        assert(outputTypes == actualDataTypes, "Invalid schema from dapply(): " +
-          s"expected ${outputTypes.mkString(", ")}, got ${actualDataTypes.mkString(", ")}")
+        if (outputTypes == actualDataTypes) {

Review Comment:
   It's opposite? should be ` != `?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51432][SQL][PYTHON] Throw a proper exception when Arrow schemas are mismatched [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #50201:
URL: https://github.com/apache/spark/pull/50201#issuecomment-2705494364

   Oops, I mistakenly removed your comment. Yes, it has to be != and fixed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org