You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "Kimahriman (via GitHub)" <gi...@apache.org> on 2025/11/03 16:19:11 UTC
[PR] [SPARK-54153] Support profiling iterator based Python UDFs [spark]
Kimahriman opened a new pull request, #52853:
URL: https://github.com/apache/spark/pull/52853
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Updates the v2 Spark-session based Python UDF profiler to support profiling iterator based UDFs.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
To add valuable profiling support to all types of UDFs.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
Yes, iterator based Python UDFs can now be profiled with the SQL config based profiler.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
Updated UTs that were specifically testing that this wasn't supported to show they are now supported.
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2551119055
##########
python/pyspark/sql/tests/test_udf_profiler.py:
##########
@@ -575,6 +585,34 @@ def summarize(left, right):
for id in self.profile_results:
self.assert_udf_profile_present(udf_id=id, expected_line_count_prefix=2)
+ def test_perf_profiler_data_source(self):
Review Comment:
Unfortunately, it turns out that we need skip this test when `pyarrow` doesn't exist.
- https://github.com/apache/spark/actions/runs/19574648782/job/56056836234
```
======================================================================
ERROR: test_perf_profiler_data_source (pyspark.sql.tests.test_udf_profiler.UDFProfiler2Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/__w/spark/spark/python/pyspark/sql/tests/test_udf_profiler.py", line 609, in test_perf_profiler_data_source
self.spark.read.format("TestDataSource").load().collect()
File "/__w/spark/spark/python/pyspark/sql/classic/dataframe.py", line 469, in collect
sock_info = self._jdf.collectToPython()
File "/__w/spark/spark/python/lib/py4j-0.10.9.9-src.zip/py4j/java_gateway.py", line 1362, in __call__
return_value = get_return_value(
File "/__w/spark/spark/python/pyspark/errors/exceptions/captured.py", line 263, in deco
return f(*a, **kw)
File "/__w/spark/spark/python/lib/py4j-0.10.9.9-src.zip/py4j/protocol.py", line 327, in get_return_value
raise Py4JJavaError(
py4j.protocol.Py4JJavaError: An error occurred while calling o235.collectToPython.
: org.apache.spark.SparkException:
Error from python worker:
Traceback (most recent call last):
File "/usr/local/pypy/pypy3.10/lib/pypy3.10/runpy.py", line 199, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/pypy/pypy3.10/lib/pypy3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/__w/spark/spark/python/lib/pyspark.zip/pyspark/daemon.py", line 37, in <module>
File "/usr/local/pypy/pypy3.10/lib/pypy3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<builtin>/frozen importlib._bootstrap_external", line 897, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/__w/spark/spark/python/lib/pyspark.zip/pyspark/sql/worker/plan_data_source_read.py", line 21, in <module>
import pyarrow as pa
ModuleNotFoundError: No module named 'pyarrow'
```
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488565286
##########
python/pyspark/worker.py:
##########
@@ -1178,38 +1180,84 @@ def wrap_perf_profiler(f, result_id):
SpecialAccumulatorIds.SQL_UDF_PROFIER, None, ProfileResultsParam
)
- def profiling_func(*args, **kwargs):
- with cProfile.Profile() as pr:
- ret = f(*args, **kwargs)
- st = pstats.Stats(pr)
- st.stream = None # make it picklable
- st.strip_dirs()
+ if _is_iter_based(eval_type):
- accumulator.add({result_id: (st, None)})
+ def profiling_func(*args, **kwargs):
+ iterator = iter(f(*args, **kwargs))
+ pr = cProfile.Profile()
+ while True:
+ try:
+ with pr:
+ item = next(iterator)
+ yield item
+ except StopIteration:
+ break
- return ret
+ st = pstats.Stats(pr)
+ st.stream = None # make it picklable
+ st.strip_dirs()
+
+ accumulator.add({result_id: (st, None)})
+
+ else:
+
+ def profiling_func(*args, **kwargs):
+ with cProfile.Profile() as pr:
+ ret = f(*args, **kwargs)
+ st = pstats.Stats(pr)
+ st.stream = None # make it picklable
+ st.strip_dirs()
+
+ accumulator.add({result_id: (st, None)})
+
+ return ret
return profiling_func
-def wrap_memory_profiler(f, result_id):
+def wrap_memory_profiler(f, eval_type, result_id):
from pyspark.sql.profiler import ProfileResultsParam
from pyspark.profiler import UDFLineProfilerV2
accumulator = _deserialize_accumulator(
SpecialAccumulatorIds.SQL_UDF_PROFIER, None, ProfileResultsParam
)
- def profiling_func(*args, **kwargs):
- profiler = UDFLineProfilerV2()
+ if _is_iter_based(eval_type):
- wrapped = profiler(f)
- ret = wrapped(*args, **kwargs)
- codemap_dict = {
- filename: list(line_iterator) for filename, line_iterator in profiler.code_map.items()
- }
- accumulator.add({result_id: (None, codemap_dict)})
- return ret
+ def profiling_func(*args, **kwargs):
+ profiler = UDFLineProfilerV2()
+ profiler.add_function(f)
+
+ iterator = iter(f(*args, **kwargs))
+
+ while True:
+ try:
+ with profiler:
+ item = next(iterator)
+ yield item
+ except StopIteration:
+ break
+
+ codemap_dict = {
+ filename: list(line_iterator)
+ for filename, line_iterator in profiler.code_map.items()
+ }
+ accumulator.add({result_id: (None, codemap_dict)})
+
+ else:
+
+ def profiling_func(*args, **kwargs):
+ profiler = UDFLineProfilerV2()
+
+ wrapped = profiler(f)
Review Comment:
Yeah I agree, updated to use the same context manager approach. And yeah the explicit add_function is necessary for the iterator approach to work
--
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-54153] Support profiling iterator based Python UDFs [spark]
Posted by "gaogaotiantian (via GitHub)" <gi...@apache.org>.
gaogaotiantian commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2487946629
##########
python/pyspark/worker.py:
##########
@@ -1192,6 +1194,36 @@ def profiling_func(*args, **kwargs):
return profiling_func
+def wrap_iter_perf_profiler(f, result_id):
Review Comment:
Do we need a new wrap function here? We only need a different `profiling_func` right? Should we do `wrap_perf_profiler(f, eval_type, result_id)` and do all the logic inside this function?
--
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-54153] Support profiling iterator based Python UDFs [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488340353
##########
python/pyspark/worker.py:
##########
@@ -1158,17 +1158,19 @@ def func(*args):
return f, args_offsets
-def _supports_profiler(eval_type: int) -> bool:
Review Comment:
There is some code to support memory profiler: https://github.com/apache/spark/pull/52853/files#diff-e91c3ea5c69ba1ce65bbaae56a7164a927bb013aac053d5167936ce9c9522051R1228?
Also the description contains the example output.
--
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-54153] Support profiling iterator based Python UDFs [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #52853:
URL: https://github.com/apache/spark/pull/52853#issuecomment-3483306490
cc @allisonwang-db too
--
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-54153] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on PR #52853:
URL: https://github.com/apache/spark/pull/52853#issuecomment-3481375747
@zhengruifeng
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488397004
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/python/UserDefinedPythonDataSource.scala:
##########
@@ -172,7 +172,8 @@ case class UserDefinedPythonDataSource(dataSourceCls: PythonFunction) {
pythonRunnerConf,
metrics,
jobArtifactUUID,
- sessionUUID)
+ sessionUUID,
+ None)
Review Comment:
Can we also enable it here? IIUC, this will run on executors, so it would help to debug python datasources. cc @allisonwang-db
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2553120557
##########
python/pyspark/sql/tests/test_udf_profiler.py:
##########
@@ -575,6 +585,34 @@ def summarize(left, right):
for id in self.profile_results:
self.assert_udf_profile_present(udf_id=id, expected_line_count_prefix=2)
+ def test_perf_profiler_data_source(self):
Review Comment:
Sorry about that! thanks for the fix
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "gaogaotiantian (via GitHub)" <gi...@apache.org>.
gaogaotiantian commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488537093
##########
python/pyspark/worker.py:
##########
@@ -1178,38 +1180,84 @@ def wrap_perf_profiler(f, result_id):
SpecialAccumulatorIds.SQL_UDF_PROFIER, None, ProfileResultsParam
)
- def profiling_func(*args, **kwargs):
- with cProfile.Profile() as pr:
- ret = f(*args, **kwargs)
- st = pstats.Stats(pr)
- st.stream = None # make it picklable
- st.strip_dirs()
+ if _is_iter_based(eval_type):
- accumulator.add({result_id: (st, None)})
+ def profiling_func(*args, **kwargs):
+ iterator = iter(f(*args, **kwargs))
+ pr = cProfile.Profile()
+ while True:
+ try:
+ with pr:
+ item = next(iterator)
+ yield item
+ except StopIteration:
+ break
- return ret
+ st = pstats.Stats(pr)
+ st.stream = None # make it picklable
+ st.strip_dirs()
+
+ accumulator.add({result_id: (st, None)})
+
+ else:
+
+ def profiling_func(*args, **kwargs):
+ with cProfile.Profile() as pr:
+ ret = f(*args, **kwargs)
+ st = pstats.Stats(pr)
+ st.stream = None # make it picklable
+ st.strip_dirs()
+
+ accumulator.add({result_id: (st, None)})
+
+ return ret
return profiling_func
-def wrap_memory_profiler(f, result_id):
+def wrap_memory_profiler(f, eval_type, result_id):
from pyspark.sql.profiler import ProfileResultsParam
from pyspark.profiler import UDFLineProfilerV2
accumulator = _deserialize_accumulator(
SpecialAccumulatorIds.SQL_UDF_PROFIER, None, ProfileResultsParam
)
- def profiling_func(*args, **kwargs):
- profiler = UDFLineProfilerV2()
+ if _is_iter_based(eval_type):
- wrapped = profiler(f)
- ret = wrapped(*args, **kwargs)
- codemap_dict = {
- filename: list(line_iterator) for filename, line_iterator in profiler.code_map.items()
- }
- accumulator.add({result_id: (None, codemap_dict)})
- return ret
+ def profiling_func(*args, **kwargs):
+ profiler = UDFLineProfilerV2()
+ profiler.add_function(f)
+
+ iterator = iter(f(*args, **kwargs))
+
+ while True:
+ try:
+ with profiler:
+ item = next(iterator)
+ yield item
+ except StopIteration:
+ break
+
+ codemap_dict = {
+ filename: list(line_iterator)
+ for filename, line_iterator in profiler.code_map.items()
+ }
+ accumulator.add({result_id: (None, codemap_dict)})
+
+ else:
+
+ def profiling_func(*args, **kwargs):
+ profiler = UDFLineProfilerV2()
+
+ wrapped = profiler(f)
Review Comment:
I would highly suggest making the two `profiling_func` use the same path. We should either use `add_function` then `with`, or call `profiler`. I'm assuming the `wrapped` way is not easily applicable to iterators. I think it will eliminate a lot of confusion.
##########
python/pyspark/sql/tests/test_udf_profiler.py:
##########
@@ -325,59 +325,57 @@ def add2(x):
not have_pandas or not have_pyarrow,
cast(str, pandas_requirement_message or pyarrow_requirement_message),
)
- def test_perf_profiler_pandas_udf_iterator_not_supported(self):
+ def test_perf_profiler_pandas_udf_iterator(self):
import pandas as pd
@pandas_udf("long")
- def add1(x):
- return x + 1
+ def add1(iter: Iterator[pd.Series]) -> Iterator[pd.Series]:
Review Comment:
The original code has 2 UDFs because one of them is not supported. It tests how an unsupported UDF works with a supported UDF. Now having two exact same UDFs does not make sense anymore. It's a bit confusing actually.
I would suggest to make this simple enough. Just test how a single iterator UDF works with profiler and confirm that we can read profiling data.
##########
python/pyspark/worker.py:
##########
@@ -1254,17 +1302,14 @@ def read_single_udf(pickleSer, infile, eval_type, runner_conf, udf_index, profil
if profiler == "perf":
result_id = read_long(infile)
- if _supports_profiler(eval_type):
- profiling_func = wrap_perf_profiler(chained_func, result_id)
- else:
- profiling_func = chained_func
+ profiling_func = wrap_perf_profiler(chained_func, eval_type, result_id)
elif profiler == "memory":
result_id = read_long(infile)
- if _supports_profiler(eval_type) and has_memory_profiler:
- profiling_func = wrap_memory_profiler(chained_func, result_id)
- else:
+ if not has_memory_profiler:
Review Comment:
We can probably move this check to `wrap_memory_profiler()` and let it handle the logic. I always think we should handle these logic in one location.
--
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-54153] Support profiling iterator based Python UDFs [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488315032
##########
python/pyspark/worker.py:
##########
@@ -1158,17 +1158,19 @@ def func(*args):
return f, args_offsets
-def _supports_profiler(eval_type: int) -> bool:
Review Comment:
cc @ueshin to check whether iterator-based UDFs can be supported in memory profiler now
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #52853:
URL: https://github.com/apache/spark/pull/52853#issuecomment-3506656775
I merged this to master/4.1 for Apache Spark 4.1.0 as the release manager of Apache Spark 4.1.0.
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488397004
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/python/UserDefinedPythonDataSource.scala:
##########
@@ -172,7 +172,8 @@ case class UserDefinedPythonDataSource(dataSourceCls: PythonFunction) {
pythonRunnerConf,
metrics,
jobArtifactUUID,
- sessionUUID)
+ sessionUUID,
+ None)
Review Comment:
Can we also enable it here? IIUC, this will run on executors, so it would help to debug python datasources.
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488564512
##########
python/pyspark/worker.py:
##########
@@ -1254,17 +1302,14 @@ def read_single_udf(pickleSer, infile, eval_type, runner_conf, udf_index, profil
if profiler == "perf":
result_id = read_long(infile)
- if _supports_profiler(eval_type):
- profiling_func = wrap_perf_profiler(chained_func, result_id)
- else:
- profiling_func = chained_func
+ profiling_func = wrap_perf_profiler(chained_func, eval_type, result_id)
elif profiler == "memory":
result_id = read_long(infile)
- if _supports_profiler(eval_type) and has_memory_profiler:
- profiling_func = wrap_memory_profiler(chained_func, result_id)
- else:
+ if not has_memory_profiler:
Review Comment:
Makes sense, done
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488556088
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/python/UserDefinedPythonDataSource.scala:
##########
@@ -172,7 +172,8 @@ case class UserDefinedPythonDataSource(dataSourceCls: PythonFunction) {
pythonRunnerConf,
metrics,
jobArtifactUUID,
- sessionUUID)
+ sessionUUID,
+ None)
Review Comment:
Yep added it and a simple test for it
--
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-54153] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2487974797
##########
python/pyspark/worker.py:
##########
@@ -1192,6 +1194,36 @@ def profiling_func(*args, **kwargs):
return profiling_func
+def wrap_iter_perf_profiler(f, result_id):
Review Comment:
Yeah I thought about doing that, I can update
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on code in PR #52853:
URL: https://github.com/apache/spark/pull/52853#discussion_r2488556569
##########
python/pyspark/sql/tests/test_udf_profiler.py:
##########
@@ -325,59 +325,57 @@ def add2(x):
not have_pandas or not have_pyarrow,
cast(str, pandas_requirement_message or pyarrow_requirement_message),
)
- def test_perf_profiler_pandas_udf_iterator_not_supported(self):
+ def test_perf_profiler_pandas_udf_iterator(self):
import pandas as pd
@pandas_udf("long")
- def add1(x):
- return x + 1
+ def add1(iter: Iterator[pd.Series]) -> Iterator[pd.Series]:
Review Comment:
yeah I wasn't sure how much to modify things, I can update
--
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-54153] Support profiling iterator based Python UDFs [spark]
Posted by "Kimahriman (via GitHub)" <gi...@apache.org>.
Kimahriman commented on PR #52853:
URL: https://github.com/apache/spark/pull/52853#issuecomment-3481383856
The OG profilers via `spark.python.profile` and `spark.python.profile.memory`are a little trickier because of the `Profiler` instances wrapping all the logic. I can try to tackle those separately
--
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-54153][PYTHON] Support profiling iterator based Python UDFs [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun closed pull request #52853: [SPARK-54153][PYTHON] Support profiling iterator based Python UDFs
URL: https://github.com/apache/spark/pull/52853
--
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