Uh oh!
There was an error while loading. Please reload this page.
[SPARK-27234][SS][PYTHON] Use InheritableThreadLocal for current epoch in EpochTracker (to support Python UDFs) - #24946
[SPARK-27234][SS][PYTHON] Use InheritableThreadLocal for current epoch in EpochTracker (to support Python UDFs)#24946HyukjinKwon wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
There's similar case that uses |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
mengxr
commented
Jun 24, 2019
@HyukjinKwon How does |
HyukjinKwon
commented
Jun 25, 2019
It works after this PR as below: frompyspark.sql.functionsimportcol, pandas_udf, PandasUDFType@pandas_udf("int", PandasUDFType.SCALAR_ITER)defthe_udf(iterator):
forcol1_batchiniterator:
yieldcol1_batchspark \
.readStream \
.format("rate") \
.load() \
.withColumn("foo", the_udf(col("value"))) \
.writeStream \
.format("console") \
.trigger(continuous="5 second").start() Before: After: Because each epoch couldn't be referred in writer thread (to Python process). Each UDF will be executed each execution per each epoch. |
HyukjinKwon
commented
Jun 25, 2019
#24945 is merged. Let me rebase. |
e3d9908 to
aa34d9eCompare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
zsxwing
left a comment
There was a problem hiding this comment.
How do we handle other thread local variables that are not InheritableThreadLocal, such as org.apache.spark.TaskContext.get?
Uh oh!
There was an error while loading. Please reload this page.
In case of and the information are (de)serialized into Python worker, I think it works too but I thought it's better to isolate this logic out of Python. Python runners are in core and this code is in SQL FWIW. We should move the codes around to mimic this approach. |
This comment has been minimized.
This comment has been minimized.
HyukjinKwon
commented
Jul 1, 2019
gentle ping .. :-) .. |
This comment has been minimized.
This comment has been minimized.
SparkQA
commented
Jul 22, 2019
Test build #108000 has finished for PR 24946 at commit
|
zsxwing
commented
Jul 22, 2019
LGTM |
HyukjinKwon
commented
Jul 23, 2019
HyukjinKwon
commented
Jul 24, 2019
Merged to master. Thanks all. |
aurorazl
commented
Aug 13, 2019
@HyukjinKwon Was problem fixed in spark 3.0? What can i do to fix it in spark2.4.3? |
HyukjinKwon
commented
Aug 13, 2019
This fix will be included in Apache Spark 3.0. I think you should upgrade it later when this is released. |
dongjoon-hyun
commented
Aug 14, 2019
In the dev mailing list, this issue is discussed for 2.4.4. I'll follow the decision from @HyukjinKwon and @zsxwing . |
HyukjinKwon
commented
Aug 14, 2019
Am fine with backporting but @zsxwing WDYT? |
zsxwing
commented
Aug 14, 2019
I'm fine with backporting this small fix. |
dongjoon-hyun
commented
Aug 14, 2019
Thank you, @zsxwing and @HyukjinKwon . |
HyukjinKwon
commented
Aug 15, 2019
Yup. BTW |
…h in EpochTracker (to support Python UDFs) This PR proposes to use `InheritableThreadLocal` instead of `ThreadLocal` for current epoch in `EpochTracker`. Python UDF needs threads to write out to and read it from Python processes and when there are new threads, previously set epoch is lost. After this PR, Python UDFs can be used at Structured Streaming with the continuous mode. The test cases were written on the top of apache#24945. Unit tests were added. Manual tests. Closesapache#24946 from HyukjinKwon/SPARK-27234. Authored-by: HyukjinKwon <gurwls223@apache.org> Signed-off-by: HyukjinKwon <gurwls223@apache.org>
What changes were proposed in this pull request?
This PR proposes to use
InheritableThreadLocalinstead ofThreadLocalfor current epoch inEpochTracker. Python UDF needs threads to write out to and read it from Python processes and when there are new threads, previously set epoch is lost.After this PR, Python UDFs can be used at Structured Streaming with the continuous mode.
How was this patch tested?
The test cases were written on the top of #24945.
Unit tests were added.
Manual tests.