sarutak commented on code in PR #59551:
URL: https://github.com/apache/spark/pull/59551#discussion_r4303758028


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/python/ArrowColumnarPythonUDFSuite.scala:
##########
@@ -103,6 +114,43 @@ class ArrowColumnarPythonUDFSuite extends 
SharedSparkSession {
     }
   }
 
+  test("Arrow-backed source that reuses its vectors: correct with the default 
configuration") {
+    assume(shouldTestPandasUDFs)
+    // The Arrow columnar path keeps the pass-through columns of a batch until 
its result comes
+    // back from Python, which is only correct if the batch stays valid until 
then. A reader may
+    // refill its vectors for the next batch, or release them once it is 
closed, as soon as it is
+    // exhausted, so columnar input is disabled by default.
+    withSQLConf(
+        SQLConf.ARROW_PYSPARK_EXECUTION_ENABLED.key -> "true",
+        SQLConf.ARROW_PYSPARK_UDF_COLUMNAR_INPUT_ENABLED.key ->
+          SQLConf.ARROW_PYSPARK_UDF_COLUMNAR_INPUT_ENABLED.defaultValueString) 
{
+      val pandasUDF = TestScalarPandasUDF(
+        name = "arrow_reuse_udf", returnType = Some(StringType))
+      registerTestUDF(pandasUDF, spark)
+
+      // Spark writes batches to Python before the results of the earlier ones 
come back. With
+      // two batches, the reader is closed once it is exhausted, before their 
results come back.
+      // With many, the reader refills its vectors with the next batches 
before then. The test
+      // UDF casts its input to string: on a string column, the cast is 
removed, so that the
+      // batches would take the Arrow columnar path if columnar input were 
enabled.
+      Seq(200, 200000).foreach { numRows =>
+        val result = readArrowSource(numRows = numRows, reuseVectors = true, 
batchSize = 100)
+          .selectExpr("id", "name", "value", "data", "arrow_reuse_udf(name) as 
udf_name")
+        val arrowExec = 
collectNodes[ArrowEvalPythonExec](result.queryExecution.executedPlan)
+        assert(arrowExec.nonEmpty && !arrowExec.head.supportsColumnar)

Review Comment:
   `!arrowExec.head.supportsColumnar` is also true in the Arrow cache case 
above, where the Arrow columnar path still runs, since `doExecute` decides on 
`child.supportsColumnar`. Could this assert that the child does not support 
columnar (`!arrowExec.head.child.supportsColumnar`), as the first test of the 
suite does for the opposite case? Then the assertion checks the path that runs.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to