-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-8532][SQL] In Python's DataFrameWriter, save/saveAsTable/json/parquet/jdbc always override mode #6937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c40c461
Regression test.
yhuai 88eb6c4
If mode is "error", do not call mode method.
yhuai d696dff
Python style.
yhuai 7fbc24b
Use None instead of "error" as the default value of mode since JVM-si…
yhuai 889eb25
Minor refactoring and add partitionBy to save, saveAsTable, and parquet.
yhuai d21290a
Python doc.
yhuai d37abd2
style.
yhuai f972d5d
davies's comment.
yhuai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,7 +218,10 @@ def mode(self, saveMode): | |
|
|
||
| >>> df.write.mode('append').parquet(os.path.join(tempfile.mkdtemp(), 'data')) | ||
| """ | ||
| self._jwrite = self._jwrite.mode(saveMode) | ||
| # At the JVM side, the default value of mode is already set to "error". | ||
| # So, if the given saveMode is None, we will not call JVM-side's mode method. | ||
| if saveMode is not None: | ||
| self._jwrite = self._jwrite.mode(saveMode) | ||
| return self | ||
|
|
||
| @since(1.4) | ||
|
|
@@ -253,11 +256,12 @@ def partitionBy(self, *cols): | |
| """ | ||
| if len(cols) == 1 and isinstance(cols[0], (list, tuple)): | ||
| cols = cols[0] | ||
| self._jwrite = self._jwrite.partitionBy(_to_seq(self._sqlContext._sc, cols)) | ||
| if len(cols) > 0: | ||
| self._jwrite = self._jwrite.partitionBy(_to_seq(self._sqlContext._sc, cols)) | ||
| return self | ||
|
|
||
| @since(1.4) | ||
| def save(self, path=None, format=None, mode="error", **options): | ||
| def save(self, path=None, format=None, mode=None, partitionBy=(), **options): | ||
| """Saves the contents of the :class:`DataFrame` to a data source. | ||
|
|
||
| The data source is specified by the ``format`` and a set of ``options``. | ||
|
|
@@ -272,11 +276,12 @@ def save(self, path=None, format=None, mode="error", **options): | |
| * ``overwrite``: Overwrite existing data. | ||
| * ``ignore``: Silently ignore this operation if data already exists. | ||
| * ``error`` (default case): Throw an exception if data already exists. | ||
| :param partitionBy: names of partitioning columns | ||
| :param options: all other string options | ||
|
|
||
| >>> df.write.mode('append').parquet(os.path.join(tempfile.mkdtemp(), 'data')) | ||
| """ | ||
| self.mode(mode).options(**options) | ||
| self.partitionBy(partitionBy).mode(mode).options(**options) | ||
| if format is not None: | ||
| self.format(format) | ||
| if path is None: | ||
|
|
@@ -296,7 +301,7 @@ def insertInto(self, tableName, overwrite=False): | |
| self._jwrite.mode("overwrite" if overwrite else "append").insertInto(tableName) | ||
|
|
||
| @since(1.4) | ||
| def saveAsTable(self, name, format=None, mode="error", **options): | ||
| def saveAsTable(self, name, format=None, mode=None, partitionBy=(), **options): | ||
| """Saves the content of the :class:`DataFrame` as the specified table. | ||
|
|
||
| In the case the table already exists, behavior of this function depends on the | ||
|
|
@@ -312,15 +317,16 @@ def saveAsTable(self, name, format=None, mode="error", **options): | |
| :param name: the table name | ||
| :param format: the format used to save | ||
| :param mode: one of `append`, `overwrite`, `error`, `ignore` (default: error) | ||
| :param partitionBy: names of partitioning columns | ||
| :param options: all other string options | ||
| """ | ||
| self.mode(mode).options(**options) | ||
| self.partitionBy(partitionBy).mode(mode).options(**options) | ||
| if format is not None: | ||
| self.format(format) | ||
| self._jwrite.saveAsTable(name) | ||
|
|
||
| @since(1.4) | ||
| def json(self, path, mode="error"): | ||
| def json(self, path, mode=None): | ||
| """Saves the content of the :class:`DataFrame` in JSON format at the specified path. | ||
|
|
||
| :param path: the path in any Hadoop supported file system | ||
|
|
@@ -336,7 +342,7 @@ def json(self, path, mode="error"): | |
| self._jwrite.mode(mode).json(path) | ||
|
|
||
| @since(1.4) | ||
| def parquet(self, path, mode="error"): | ||
| def parquet(self, path, mode=None, partitionBy=()): | ||
| """Saves the content of the :class:`DataFrame` in Parquet format at the specified path. | ||
|
|
||
| :param path: the path in any Hadoop supported file system | ||
|
|
@@ -346,13 +352,14 @@ def parquet(self, path, mode="error"): | |
| * ``overwrite``: Overwrite existing data. | ||
| * ``ignore``: Silently ignore this operation if data already exists. | ||
| * ``error`` (default case): Throw an exception if data already exists. | ||
|
|
||
| :param partitionBy: names of partitioning columns | ||
| >>> df.write.parquet(os.path.join(tempfile.mkdtemp(), 'data')) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line here |
||
| """ | ||
| self._jwrite.mode(mode).parquet(path) | ||
| self.partitionBy(partitionBy).mode(mode) | ||
| self._jwrite.parquet(path) | ||
|
|
||
| @since(1.4) | ||
| def jdbc(self, url, table, mode="error", properties={}): | ||
| def jdbc(self, url, table, mode=None, properties={}): | ||
| """Saves the content of the :class:`DataFrame` to a external database table via JDBC. | ||
|
|
||
| .. note:: Don't create too many partitions in parallel on a large cluster;\ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.