spark-test commented on code in PR #59845:
URL: https://github.com/apache/spark/pull/59845#discussion_r4506253567
##########
python/pyspark/eval_handlers/tests/test_arrow_eval_type_handlers.py:
##########
@@ -366,13 +366,44 @@ def test_concurrency_level(self):
out = list(handler.run(0, iter([self._batch(a=list(range(10)), b=[0] *
10)])))
self.assertEqual(out[0].column(0).to_pylist(), [v * 2 for v in
range(10)])
+ def test_concurrency_level_multi_and_zero_arg(self):
+ conf =
RunnerConf({"spark.sql.execution.pythonUDF.arrow.concurrency.level": "4"})
+ handler = self._handler((lambda a, b: a - b, [0, 1], {}, LongType()),
runner_conf=conf)
+ out = list(handler.run(0, iter([self._batch(a=list(range(10)), b=[1] *
10)])))
+ self.assertEqual(out[0].column(0).to_pylist(), [v - 1 for v in
range(10)])
+
+ handler = self._handler((lambda x, y: x - y, [0], {"y": 1},
LongType()), runner_conf=conf)
+ out = list(handler.run(0, iter([self._batch(a=list(range(10)), b=[1] *
10)])))
+ self.assertEqual(out[0].column(0).to_pylist(), [v - 1 for v in
range(10)])
+
+ handler = self._handler(
+ (lambda: 7, [], {}, LongType()), runner_conf=conf,
input_type=StructType()
+ )
+ empty = pa.RecordBatch.from_pydict({"a": [1, 2, 3]}).select([])
+ out = list(handler.run(0, iter([empty])))
+ self.assertEqual(out[0].column(0).to_pylist(), [7, 7, 7])
+
def test_stop_iteration_raises_runtime_error(self):
- def stop(a):
+ def stop(*args, **kwargs):
raise StopIteration()
- handler = self._handler((stop, [0], {}, LongType()))
- with self.assertRaises(PySparkRuntimeError):
- list(handler.run(0, iter([self._batch(a=[1], b=[0])])))
+ batch = self._batch(a=[1, 2], b=[0, 0])
+ empty = batch.select([])
+ # (args_offsets, kwargs_offsets, input_type, batch): one case per
evaluation branch.
Review Comment:
**Nit (P3):** These four cases are one per argument shape on the serial path
rather than one per evaluation branch. Each builds the handler with the default
`RunnerConf`, where `arrow_concurrency_level` is -1, so only the serial
branches of `_evaluate_batch_udf` run; `keyword_arg` is flattened by
`wrap_kwargs_support` to offsets `[0, 1]` and takes the same `zip(*args)`
branch as `multi_arg`, and neither thread-pool branch has a case. The
thread-pool path is also where StopIteration behaves differently: with
`spark.sql.execution.pythonUDF.arrow.concurrency.level` set to 4, the same
cases fail with `RuntimeError('generator raised StopIteration')` instead of
`STOP_ITERATION_OCCURRED`, as on the base branch. As written, the comment makes
that path look covered. Rewording it is enough, and thread-pool cases can wait
for your follow-up:
```suggestion
# (args_offsets, kwargs_offsets, input_type, batch): one case per
argument shape on
# the default (non-thread-pool) path.
```
This extends an [existing
discussion](https://github.com/apache/spark/pull/59845#discussion_r4464058657).
**Verification:**
- **Inspection:** The comment above the StopIteration cases matches what
they run: every case uses the default concurrency setting, and the comment
claims neither one case per evaluation branch nor coverage of the thread-pool
branches.
- **Behavior:** The StopIteration test still passes and still asserts the
STOP_ITERATION_OCCURRED error condition for the zero-argument, single-argument,
multi-argument and keyword-argument cases.
--
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]