Skip to content

Commit

Permalink
If mode is "error", do not call mode method.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhuai committed Jun 22, 2015
1 parent c40c461 commit 88eb6c4
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions python/pyspark/sql/readwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,15 @@ def save(self, path=None, format=None, mode="error", **options):
>>> df.write.mode('append').parquet(os.path.join(tempfile.mkdtemp(), 'data'))
"""
self.mode(mode).options(**options)
if mode is not "error":
# At the JVM side, the default value of mode is already set to "error".
# So, if mode at here is "error", we will not call mode method.
# This behavior is used to prevent us accidentally overriding the mode because
# user can call mode method directly.
# We leave "error" as the default in the method signature, so users can
# see what is the default value in Python doc.
self.mode(mode)
self.options(**options)
if format is not None:
self.format(format)
if path is None:
Expand Down Expand Up @@ -314,7 +322,15 @@ def saveAsTable(self, name, format=None, mode="error", **options):
:param mode: one of `append`, `overwrite`, `error`, `ignore` (default: error)
:param options: all other string options
"""
self.mode(mode).options(**options)
if mode is not "error":
# At the JVM side, the default value of mode is already set to "error".
# So, if mode at here is "error", we will not call mode method.
# This behavior is used to prevent us accidentally overriding the mode because
# user can call mode method directly.
# We leave "error" as the default in the method signature, so users can
# see what is the default value in Python doc.
self.mode(mode)
self.options(**options)
if format is not None:
self.format(format)
self._jwrite.saveAsTable(name)
Expand All @@ -333,7 +349,15 @@ def json(self, path, mode="error"):
>>> df.write.json(os.path.join(tempfile.mkdtemp(), 'data'))
"""
self._jwrite.mode(mode).json(path)
if mode is not "error":
# At the JVM side, the default value of mode is already set to "error".
# So, if mode at here is "error", we will not call mode method.
# This behavior is used to prevent us accidentally overriding the mode because
# user can call mode method directly.
# We leave "error" as the default in the method signature, so users can
# see what is the default value in Python doc.
self.mode(mode)
self._jwrite.json(path)

@since(1.4)
def parquet(self, path, mode="error"):
Expand All @@ -349,7 +373,15 @@ def parquet(self, path, mode="error"):
>>> df.write.parquet(os.path.join(tempfile.mkdtemp(), 'data'))
"""
self._jwrite.mode(mode).parquet(path)
if mode is not "error":
# At the JVM side, the default value of mode is already set to "error".
# So, if mode at here is "error", we will not call mode method.
# This behavior is used to prevent us accidentally overriding the mode because
# user can call mode method directly.
# We leave "error" as the default in the method signature, so users can
# see what is the default value in Python doc.
self.mode(mode)
self._jwrite.parquet(path)

@since(1.4)
def jdbc(self, url, table, mode="error", properties={}):
Expand All @@ -370,10 +402,18 @@ def jdbc(self, url, table, mode="error", properties={}):
arbitrary string tag/value. Normally at least a
"user" and "password" property should be included.
"""
if mode is not "error":
# At the JVM side, the default value of mode is already set to "error".
# So, if mode at here is "error", we will not call mode method.
# This behavior is used to prevent us accidentally overriding the mode because
# user can call mode method directly.
# We leave "error" as the default in the method signature, so users can
# see what is the default value in Python doc.
self.mode(mode)
jprop = JavaClass("java.util.Properties", self._sqlContext._sc._gateway._gateway_client)()
for k in properties:
jprop.setProperty(k, properties[k])
self._jwrite.mode(mode).jdbc(url, table, jprop)
self._jwrite.jdbc(url, table, jprop)


def _test():
Expand Down

0 comments on commit 88eb6c4

Please sign in to comment.