aboutsummaryrefslogtreecommitdiff
path: root/examples/src/main/python/sql/datasource.py
diff options
context:
space:
mode:
authorJustin Pihony <justin.pihony@gmail.com>2016-09-26 09:54:22 +0100
committerSean Owen <sowen@cloudera.com>2016-09-26 09:54:22 +0100
commit50b89d05b7bffc212cc9b9ae6e0bca7cb90b9c77 (patch)
tree004018c95e9fedc204d683c210af79ac43bd4212 /examples/src/main/python/sql/datasource.py
parentac65139be96dbf87402b9a85729a93afd3c6ff17 (diff)
downloadspark-50b89d05b7bffc212cc9b9ae6e0bca7cb90b9c77.tar.gz
spark-50b89d05b7bffc212cc9b9ae6e0bca7cb90b9c77.tar.bz2
spark-50b89d05b7bffc212cc9b9ae6e0bca7cb90b9c77.zip
[SPARK-14525][SQL] Make DataFrameWrite.save work for jdbc
## What changes were proposed in this pull request? This change modifies the implementation of DataFrameWriter.save such that it works with jdbc, and the call to jdbc merely delegates to save. ## How was this patch tested? This was tested via unit tests in the JDBCWriteSuite, of which I added one new test to cover this scenario. ## Additional details rxin This seems to have been most recently touched by you and was also commented on in the JIRA. This contribution is my original work and I license the work to the project under the project's open source license. Author: Justin Pihony <justin.pihony@gmail.com> Author: Justin Pihony <justin.pihony@typesafe.com> Closes #12601 from JustinPihony/jdbc_reconciliation.
Diffstat (limited to 'examples/src/main/python/sql/datasource.py')
-rw-r--r--examples/src/main/python/sql/datasource.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/src/main/python/sql/datasource.py b/examples/src/main/python/sql/datasource.py
index b36c901d2b..e9aa9d9ac2 100644
--- a/examples/src/main/python/sql/datasource.py
+++ b/examples/src/main/python/sql/datasource.py
@@ -143,6 +143,8 @@ def json_dataset_example(spark):
def jdbc_dataset_example(spark):
# $example on:jdbc_dataset$
+ # Note: JDBC loading and saving can be achieved via either the load/save or jdbc methods
+ # Loading data from a JDBC source
jdbcDF = spark.read \
.format("jdbc") \
.option("url", "jdbc:postgresql:dbserver") \
@@ -150,6 +152,23 @@ def jdbc_dataset_example(spark):
.option("user", "username") \
.option("password", "password") \
.load()
+
+ jdbcDF2 = spark.read \
+ .jdbc("jdbc:postgresql:dbserver", "schema.tablename",
+ properties={"user": "username", "password": "password"})
+
+ # Saving data to a JDBC source
+ jdbcDF.write \
+ .format("jdbc") \
+ .option("url", "jdbc:postgresql:dbserver") \
+ .option("dbtable", "schema.tablename") \
+ .option("user", "username") \
+ .option("password", "password") \
+ .save()
+
+ jdbcDF2.write \
+ .jdbc("jdbc:postgresql:dbserver", "schema.tablename",
+ properties={"user": "username", "password": "password"})
# $example off:jdbc_dataset$