Adrian Bridgett created SPARK-22437:
---------------------------------------

             Summary: jdbc write fails to set default mode
                 Key: SPARK-22437
                 URL: https://issues.apache.org/jira/browse/SPARK-22437
             Project: Spark
          Issue Type: Bug
          Components: Java API
    Affects Versions: 2.2.0
         Environment: python3
            Reporter: Adrian Bridgett


With this bit of code:
{code}
        df.write.jdbc(jdbc_url, table)
{code}

We see this error:
{code}
09:54:22 2017-11-03 09:54:19,985 INFO       File 
"/opt/spark220/python/lib/pyspark.zip/pyspark/sql/readwriter.py", line 820, in 
jdbc
09:54:22 2017-11-03 09:54:19,985 INFO       File 
"/opt/spark220/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, 
in __call__
09:54:22 2017-11-03 09:54:19,986 INFO       File 
"/opt/spark220/python/lib/pyspark.zip/pyspark/sql/utils.py", line 63, in deco
09:54:22 2017-11-03 09:54:19,986 INFO       File 
"/opt/spark220/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py", line 319, in 
get_return_value
09:54:22 2017-11-03 09:54:19,987 INFO     py4j.protocol.Py4JJavaError: An error 
occurred while calling o106.jdbc.
09:54:22 2017-11-03 09:54:19,987 INFO     : scala.MatchError: null
09:54:22 2017-11-03 09:54:19,987 INFO           at 
org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:62)
09:54:22 2017-11-03 09:54:19,987 INFO           at 
org.apache.spark.sql.execution.datasources.DataSource.write(DataSource.scala:472)
09:54:22 2017-11-03 09:54:19,987 INFO           at 
org.apache.spark.sql.execution.datasources.SaveIntoDataSourceCommand.run(SaveIntoDataSourceCommand.scala:48)
...
{code}

This seems to be that "mode" isn't correctly picking up the "error" default as 
listed in 
https://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.DataFrame

Note that if it was erroring because of existing data it'd say "SaveMode: 
ErrorIfExists." as seen in 
./sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcRelationProvider.scala).

Changing our code to this worked:
{code}
        df.write.jdbc(jdbc_url, table, mode='append')
{code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to