Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ private[spark] abstract class BasePythonRunner[IN, OUT](
// the decrypted data to python
val idsAndFiles = broadcastVars.flatMap { broadcast =>
if (!oldBids.contains(broadcast.id)) {
oldBids.add(broadcast.id)
Some((broadcast.id, broadcast.value.path))
} else {
None
Expand All @@ -416,7 +417,6 @@ private[spark] abstract class BasePythonRunner[IN, OUT](
idsAndFiles.foreach { case (id, _) =>
// send new broadcast
dataOut.writeLong(id)
oldBids.add(id)
}
dataOut.flush()
logTrace("waiting for python to read decrypted broadcast data from server")
Expand Down
14 changes: 14 additions & 0 deletions python/pyspark/tests/test_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pyspark import SparkConf, SparkContext, Broadcast
from pyspark.java_gateway import launch_gateway
from pyspark.serializers import ChunkedStream
from pyspark.sql import SparkSession, Row


class BroadcastTest(unittest.TestCase):
Expand Down Expand Up @@ -126,6 +127,19 @@ def test_broadcast_for_error_condition(self):
with self.assertRaisesRegex(Py4JJavaError, "RuntimeError.*Broadcast.*unpersisted.*driver"):
self.sc.parallelize([1]).map(lambda x: bs.unpersist()).collect()

def test_broadcast_in_udfs_with_encryption(self):
conf = SparkConf()
conf.set("spark.io.encryption.enabled", "true")
conf.setMaster("local-cluster[2,1,1024]")
self.sc = SparkContext(conf=conf)
bar = {"a": "aa", "b": "bb"}
foo = self.sc.broadcast(bar)
spark = SparkSession(self.sc)
spark.udf.register("MYUDF", lambda x: foo.value[x] if x else "")
sel = spark.sql("SELECT MYUDF('a') AS a, MYUDF('b') AS b")
self.assertEqual(sel.collect(), [Row(a="aa", b="bb")])
spark.stop()


class BroadcastFrameProtocolTest(unittest.TestCase):
@classmethod
Expand Down