[SPARK-57423][PYTHON][TEST] Share base mixin across MapInBatch Arrow/Pandas siblings#56483
Open
viirya wants to merge 1 commit into
Open
[SPARK-57423][PYTHON][TEST] Share base mixin across MapInBatch Arrow/Pandas siblings#56483viirya wants to merge 1 commit into
viirya wants to merge 1 commit into
Conversation
…Pandas siblings ### What changes were proposed in this pull request? Follow-up to SPARK-57137/57138/57414. Apply the sibling base-mixin pattern to the last remaining Arrow/Pandas pair in `python/benchmarks/bench_eval_type.py`: - `_MapPandasIterBenchMixin` now subclasses `_MapArrowIterBenchMixin`, dropping its duplicated `_build_scenario` (identical body) and `_write_scenario` (identical except the eval type constant and the `ret_type` handling). - The Arrow base gains the `_eval_type` class attribute and parameterizes `_write_scenario` on `self._eval_type`. The Pandas `_udfs` values are normalized from `(func, arg_offsets)` to the Arrow base's `(func, ret_type, arg_offsets)` shape so the inherited writer works unchanged. - Drive-by: convert the `_build_scenario` of the newly added `_TransformWithStatePandasBenchMixin` (SPARK-57020, developed in parallel with SPARK-57414) from `@staticmethod` with a hardcoded class-name lookup to `@classmethod` with `cls._scenario_configs`, matching the now-uniform convention. Net diff: +16 / -40 lines. ### Why are the changes needed? The two MapInBatch mixins were the last undeclared sibling pair: near-identical `_build_scenario` and `_write_scenario` bodies that had to be kept in lock-step manually. After this change, every Arrow/Pandas sibling pair in the file shares a base mixin, every `_build_scenario` resolves configs via `cls`, and no redundant protocol-writing copies remain. ### Does this PR introduce _any_ user-facing change? No. Test-only change in the benchmark module. ### How was this patch tested? - Verified the generated worker input is byte-identical to the pre-refactor output for all 21 `*TimeBench` classes across every (scenario, udf) cell, with the cloudpickled UDF command excluded and the TWS stub state-server port pinned (the port is freshly allocated per process; the UDF pickle embeds `co_firstlineno` and a random cloudpickle class-tracker id -- all environment/location metadata). - Compared the pickle opcode streams of all 63 pickled UDF/UDTF callables between old and new: only the metadata above differs; code, constants, and names are unchanged. - Ran `setup` + `time_worker` end-to-end for the affected `*TimeBench` classes (MapArrowIter, MapPandasIter, TransformWithStatePandas) across every UDF, and `peakmem_worker` for MapPandasIter and TransformWithStatePandas. ### Was this patch authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Code (claude-opus-4-8) Co-authored-by: Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Follow-up to SPARK-57137/57138/57414. Apply the sibling base-mixin pattern to the last remaining Arrow/Pandas pair in
python/benchmarks/bench_eval_type.py:_MapPandasIterBenchMixinnow subclasses_MapArrowIterBenchMixin, dropping its duplicated_build_scenario(identical body) and_write_scenario(identical except the eval type constant and theret_typehandling)._eval_typeclass attribute and parameterizes_write_scenarioonself._eval_type. The Pandas_udfsvalues are normalized from(func, arg_offsets)to the Arrow base's(func, ret_type, arg_offsets)shape so the inherited writer works unchanged._build_scenarioof the newly added_TransformWithStatePandasBenchMixin(SPARK-57020, developed in parallel with SPARK-57414) from@staticmethodwith a hardcoded class-name lookup to@classmethodwithcls._scenario_configs, matching the now-uniform convention.Net diff: +16 / -40 lines.
Why are the changes needed?
The two MapInBatch mixins were the last undeclared sibling pair: near-identical
_build_scenarioand_write_scenariobodies that had to be kept in lock-step manually. After this change, every Arrow/Pandas sibling pair in the file shares a base mixin, every_build_scenarioresolves configs viacls, and no redundant protocol-writing copies remain.Does this PR introduce any user-facing change?
No. Test-only change in the benchmark module.
How was this patch tested?
*TimeBenchclasses across every (scenario, udf) cell, with the cloudpickled UDF command excluded and the TWS stub state-server port pinned (the port is freshly allocated per process; the UDF pickle embedsco_firstlinenoand a random cloudpickle class-tracker id -- all environment/location metadata unaffected by this change).setup+time_workerend-to-end for the affected*TimeBenchclasses (MapArrowIter, MapPandasIter, TransformWithStatePandas) across every UDF, andpeakmem_workerfor MapPandasIter and TransformWithStatePandas.Was this patch authored or co-authored using generative AI tooling?
Yes. Generated-by: Claude Code (claude-opus-4-8)