Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tdas committed May 29, 2018
1 parent 9d95c12 commit 2ea9cbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/pyspark/taskcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ def getLocalProperty(self, key):
"""
Get a local property set upstream in the driver, or None if it is missing.
"""
return self._localProperties[key]
return self._localProperties.get(key, default=None)
10 changes: 6 additions & 4 deletions python/pyspark/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,17 @@ def test_tc_on_driver(self):

def test_get_local_property(self):
"""Verify that local properties set on the driver are available in TaskContext."""
key = "testkey"
value = "testvalue"
self.sc.setLocalProperty(key, value)
try:
self.sc.setLocalProperty("testkey", "testvalue")
rdd = self.sc.parallelize(range(1), 1)
prop1 = rdd.map(lambda x: TaskContext.get().getLocalProperty("testkey")).collect()[0]
self.assertEqual(prop1, "testvalue")
prop1 = rdd.map(lambda x: TaskContext.get().getLocalProperty(key)).collect()[0]
self.assertEqual(prop1, value)
prop2 = rdd.map(lambda x: TaskContext.get().getLocalProperty("otherkey")).collect()[0]
self.assertTrue(prop2 is None)
finally:
self.sc.setLocalProperty("testkey", None)
self.sc.setLocalProperty(key, None)


class RDDTests(ReusedPySparkTestCase):
Expand Down

0 comments on commit 2ea9cbc

Please sign in to comment.