aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/sql/readwriter.py
diff options
context:
space:
mode:
authorDavies Liu <davies@databricks.com>2015-05-23 09:07:14 -0700
committerDavies Liu <davies@databricks.com>2015-05-23 09:07:14 -0700
commitbe47af1bdba469f84775c2b5936f8cb956c7c02b (patch)
tree3c4016d27ad15f908ae5e0307180189347df6247 /python/pyspark/sql/readwriter.py
parentefe3bfdf496aa6206ace2697e31dd4c0c3c824fb (diff)
downloadspark-be47af1bdba469f84775c2b5936f8cb956c7c02b.tar.gz
spark-be47af1bdba469f84775c2b5936f8cb956c7c02b.tar.bz2
spark-be47af1bdba469f84775c2b5936f8cb956c7c02b.zip
[SPARK-7840] add insertInto() to Writer
Add tests later. Author: Davies Liu <davies@databricks.com> Closes #6375 from davies/insertInto and squashes the following commits: 826423e [Davies Liu] add insertInto() to Writer
Diffstat (limited to 'python/pyspark/sql/readwriter.py')
-rw-r--r--python/pyspark/sql/readwriter.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/python/pyspark/sql/readwriter.py b/python/pyspark/sql/readwriter.py
index 02b3aab2b1..b6fd413bec 100644
--- a/python/pyspark/sql/readwriter.py
+++ b/python/pyspark/sql/readwriter.py
@@ -226,17 +226,25 @@ class DataFrameWriter(object):
else:
jwrite.save(path)
+ def insertInto(self, tableName, overwrite=False):
+ """
+ Inserts the content of the :class:`DataFrame` to the specified table.
+ It requires that the schema of the class:`DataFrame` is the same as the
+ schema of the table.
+
+ Optionally overwriting any existing data.
+ """
+ self._jwrite.mode("overwrite" if overwrite else "append").insertInto(tableName)
+
@since(1.4)
def saveAsTable(self, name, format=None, mode="error", **options):
"""
- Saves the contents of this :class:`DataFrame` to a data source as a table.
-
- The data source is specified by the ``source`` and a set of ``options``.
- If ``source`` is not specified, the default data source configured by
- ``spark.sql.sources.default`` will be used.
+ Saves the content of the :class:`DataFrame` as the specified table.
- Additionally, mode is used to specify the behavior of the saveAsTable operation when
- table already exists in the data source. There are four modes:
+ In the case the table already exists, behavior of this function depends on the
+ save mode, specified by the `mode` function (default to throwing an exception).
+ When `mode` is `Overwrite`, the schema of the [[DataFrame]] does not need to be
+ the same as that of the existing table.
* `append`: Append contents of this :class:`DataFrame` to existing data.
* `overwrite`: Overwrite existing data.