Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions python/pyspark/sql/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import sys

from pyspark import since
from pyspark import since, _NoValue
from pyspark.rdd import ignore_unicode_prefix


Expand All @@ -39,15 +39,16 @@ def set(self, key, value):

@ignore_unicode_prefix
@since(2.0)
def get(self, key, default=None):
def get(self, key, default=_NoValue):
"""Returns the value of Spark runtime configuration property for the given key,
assuming it is set.
"""
self._checkType(key, "key")
if default is None:
if default is _NoValue:
return self._jconf.get(key)
else:
self._checkType(default, "default")
if default is not None:
self._checkType(default, "default")
return self._jconf.get(key, default)

@ignore_unicode_prefix
Expand Down
8 changes: 4 additions & 4 deletions python/pyspark/sql/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if sys.version >= '3':
basestring = unicode = str

from pyspark import since
from pyspark import since, _NoValue
from pyspark.rdd import ignore_unicode_prefix
from pyspark.sql.session import _monkey_patch_RDD, SparkSession
from pyspark.sql.dataframe import DataFrame
Expand Down Expand Up @@ -124,11 +124,11 @@ def setConf(self, key, value):

@ignore_unicode_prefix
@since(1.3)
def getConf(self, key, defaultValue=None):
def getConf(self, key, defaultValue=_NoValue):
"""Returns the value of Spark SQL configuration property for the given key.

If the key is not set and defaultValue is not None, return
defaultValue. If the key is not set and defaultValue is None, return
If the key is not set and defaultValue is set, return
defaultValue. If the key is not set and defaultValue is not set, return
the system default value.

>>> sqlContext.getConf("spark.sql.shuffle.partitions")
Expand Down
4 changes: 4 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,10 @@ def test_conf(self):
spark.conf.unset("bogo")
self.assertEqual(spark.conf.get("bogo", "colombia"), "colombia")

self.assertRaisesRegexp(Exception, "hyukjin", lambda: spark.conf.get("hyukjin"))

@HyukjinKwon HyukjinKwon Mar 17, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BryanCutler, so this test case prompted you. It's not related with this PR:

Before

>>> spark.conf.get("hyukjin")
...
: java.util.NoSuchElementException: hyukjin
...

After

>>> spark.conf.get("hyukjin")
...
: java.util.NoSuchElementException: hyukjin
...

Let me take this out.

self.assertEqual(spark.conf.get("hyukjin", None), None)
self.assertEqual(spark.conf.get("spark.sql.sources.partitionOverwriteMode", None), None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add one more test to get "spark.sql.sources.partitionOverwriteMode" without None to see the difference between with and without None? Hopefully with a simple comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.


def test_current_database(self):
spark = self.spark
spark.catalog._reset()
Expand Down