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
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
11 changes: 11 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,17 @@ def test_conf(self):
spark.conf.unset("bogo")
self.assertEqual(spark.conf.get("bogo", "colombia"), "colombia")

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

# This returns 'STATIC' because it's the default value of
# 'spark.sql.sources.partitionOverwriteMode', and `defaultValue` in
# `spark.conf.get` is unset.
self.assertEqual(spark.conf.get("spark.sql.sources.partitionOverwriteMode"), "STATIC")

# This returns None because 'spark.sql.sources.partitionOverwriteMode' is unset, but
# `defaultValue` in `spark.conf.get` is set to None.
self.assertEqual(spark.conf.get("spark.sql.sources.partitionOverwriteMode", None), None)

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