ivoson commented on code in PR #59637:
URL: https://github.com/apache/spark/pull/59637#discussion_r4640773100


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/BatchEvalPythonExec.scala:
##########
@@ -186,6 +190,8 @@ object BatchEvalPythonExec {
             estimatedBytes += (dataType match {

Review Comment:
   Fixed in dfceed40d8b. Precomputed a primitive-returning sizer for each 
supported argument when building the estimator. The per-row loop checks nulls 
and reads the selected payload lengths without type matches or tuple 
destructuring.
   



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/BatchEvalPythonExec.scala:
##########
@@ -186,6 +190,8 @@ object BatchEvalPythonExec {
             estimatedBytes += (dataType match {
               case _: StringType => row.getUTF8String(ordinal).numBytes.toLong
               case BinaryType => row.getBinary(ordinal).length.toLong
+              case _: GeometryType | _: GeographyType =>
+                row.getBinaryView(ordinal).numBytes().toLong
               case _ => 0L

Review Comment:
   Fixed in dfceed40d8b. Removed isSupportedProjectedInputType and combined 
support selection with sizer construction. Unsupported storage returns None 
only during setup; there is no zero-byte fallback for a selected type in the 
per-row loop.
   



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/python/BatchEvalPythonExecSuite.scala:
##########
@@ -98,12 +98,32 @@ class BatchEvalPythonExecSuite extends SharedSparkSession
     assert(estimate(projectedRow) === 6000L)
     assert(estimate(InternalRow(null, null, 1)) === 0L)
 
+    // Geometry and Geography arguments are sized by their BinaryView byte 
count.
+    val geoRow = new GenericInternalRow(Array[Any](
+      BinaryView.fromBytes(Array.fill[Byte](1500)(1)),
+      BinaryView.fromBytes(Array.fill[Byte](700)(1))))
+    val geoEstimate = BatchEvalPythonExec
+      .projectedInputPayloadSizeEstimator(Seq(
+        GeometryType(GeometryType.GEOMETRY_DEFAULT_SRID),
+        GeographyType(GeographyType.GEOGRAPHY_DEFAULT_SRID)))
+      .get
+    assert(geoEstimate(geoRow) === 2200L)

Review Comment:
   Fixed in dfceed40d8b. Added getInputIterator coverage for both GEOMETRY and 
GEOGRAPHY with row-count and byte-bounded batching. Malformed oversized geo 
bytes must raise UDF_LIMITS.ROW_SIZE before parsing; tests also cover null geo 
values and combined STRING + geo payloads.
   



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/python/BatchEvalPythonExecSuite.scala:
##########
@@ -157,39 +177,43 @@ class BatchEvalPythonExecSuite extends SharedSparkSession
         "actualRowSize" -> "1200"))
   }
 
-  test("SPARK-59824: pickle UDF row-size guard uses SQLConf settings") {
+  test("SPARK-59824: pickle UDF row-size guard forwards SQLConf settings") {
     val configuredMaxRowSize = 1000L
     val maxRowHeapFraction = configuredMaxRowSize.toDouble / 
Runtime.getRuntime.maxMemory()
     val expectedMaxRowSize =
       (Runtime.getRuntime.maxMemory() * maxRowHeapFraction).toLong
-    withSQLConf(
-      SQLConf.PYTHON_UDF_ROW_SIZE_GUARD_ENABLED.key -> "true",
-      SQLConf.PYTHON_UDF_ROW_SIZE_GUARD_MAX_ROW_HEAP_FRACTION.key ->
-        maxRowHeapFraction.toString) {
-      val taskAttr = AttributeReference("s", StringType)()
-      val pythonUdf = PythonUDF(
-        "dummy", new DummyUDF, StringType, Seq(taskAttr), 
PythonEvalType.SQL_BATCHED_UDF,
-        udfDeterministic = true)
-      class TestBatchEvalPythonExec extends BatchEvalPythonExec(
-          Seq(pythonUdf),
-          Seq(AttributeReference("result", StringType)()),
-          LocalTableScanExec(Seq(taskAttr), Nil, None)) {
-        def testEvaluatorFactory: BatchEvalPythonEvaluatorFactory =
-          evaluatorFactory.asInstanceOf[BatchEvalPythonEvaluatorFactory]
-      }
-      val plan = new TestBatchEvalPythonExec
-      val oversizedRow = InternalRow(
-        UTF8String.fromString("x" * (expectedMaxRowSize.toInt + 1)))
-      checkError(
-        exception = intercept[SparkRuntimeException] {
-          plan.testEvaluatorFactory.getInputIterator(
-            Iterator(oversizedRow), StructType.fromDDL("s STRING")).next()
-        },
-        condition = "UDF_LIMITS.ROW_SIZE",
-        parameters = Map(
-          "maxRowSize" -> expectedMaxRowSize.toString,
-          "actualRowSize" -> (expectedMaxRowSize + 1).toString))
+    val taskAttr = AttributeReference("s", StringType)()
+    val pythonUdf = PythonUDF(
+      "dummy", new DummyUDF, StringType, Seq(taskAttr), 
PythonEvalType.SQL_BATCHED_UDF,
+      udfDeterministic = true)
+    class TestBatchEvalPythonExec extends BatchEvalPythonExec(
+        Seq(pythonUdf),
+        Seq(AttributeReference("result", StringType)()),
+        LocalTableScanExec(Seq(taskAttr), Nil, None)) {
+      def testEvaluatorFactory: BatchEvalPythonEvaluatorFactory =
+        evaluatorFactory.asInstanceOf[BatchEvalPythonEvaluatorFactory]
+    }
+    val plan = new TestBatchEvalPythonExec
+    val oversizedRow = InternalRow(
+      UTF8String.fromString("x" * (expectedMaxRowSize.toInt + 1)))
+    val schema = StructType.fromDDL("s STRING")
+    EvaluatePython.registerPicklers()
+    def inputIterator(enabled: Boolean): Iterator[Array[Byte]] = withSQLConf(
+        SQLConf.PYTHON_UDF_ROW_SIZE_GUARD_ENABLED.key -> enabled.toString,
+        SQLConf.PYTHON_UDF_ROW_SIZE_GUARD_MAX_ROW_HEAP_FRACTION.key ->
+          maxRowHeapFraction.toString) {
+      plan.testEvaluatorFactory.getInputIterator(Iterator(oversizedRow), 
schema)
     }
+
+    assert(inputIterator(enabled = false).next().nonEmpty)

Review Comment:
   Fixed in dfceed40d8b. The helper now calls next() inside withSQLConf. The 
disabled-guard case unpickles the batch and verifies the original oversized 
string instead of checking only that the bytes are nonempty.
   



-- 
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