Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-22437

jdbc write fails to set default mode

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.3.0
    • Component/s: Java API
    • Labels:
      None
    • Environment:

      python3

      Description

      With this bit of code:

              df.write.jdbc(jdbc_url, table)
      

      We see this error:

      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)
      ...
      

      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:

              df.write.jdbc(jdbc_url, table, mode='append')
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mgaido Marco Gaido
                Reporter:
                abridgett Adrian Bridgett
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: