Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15263#discussion_r82490916
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcRelationProvider.scala
 ---
    @@ -50,67 +51,52 @@ class JdbcRelationProvider extends 
CreatableRelationProvider
         JDBCRelation(jdbcOptions.url, jdbcOptions.table, parts, 
properties)(sqlContext.sparkSession)
       }
     
    -  /*
    -   * The following structure applies to this code:
    -   *                 |    tableExists            |          !tableExists
    -   
*------------------------------------------------------------------------------------
    -   * Ignore          | BaseRelation              | CreateTable, saveTable, 
BaseRelation
    -   * ErrorIfExists   | ERROR                     | CreateTable, saveTable, 
BaseRelation
    -   * Overwrite*      | (DropTable, CreateTable,) | CreateTable, saveTable, 
BaseRelation
    -   *                 | saveTable, BaseRelation   |
    -   * Append          | saveTable, BaseRelation   | CreateTable, saveTable, 
BaseRelation
    -   *
    -   * *Overwrite & tableExists with truncate, will not drop & create, but 
instead truncate
    -   */
       override def createRelation(
           sqlContext: SQLContext,
           mode: SaveMode,
           parameters: Map[String, String],
    -      data: DataFrame): BaseRelation = {
    -    val jdbcOptions = new JDBCOptions(parameters)
    -    val url = jdbcOptions.url
    -    val table = jdbcOptions.table
    -
    +      df: DataFrame): BaseRelation = {
    +    val options = new JDBCOptions(parameters)
    +    val url = options.url
    +    val table = options.table
    +    val createTableOptions = options.createTableOptions
    +    val isTruncate = options.isTruncate
         val props = new Properties()
         props.putAll(parameters.asJava)
    -    val conn = JdbcUtils.createConnectionFactory(url, props)()
     
    +    val conn = JdbcUtils.createConnectionFactory(url, props)()
         try {
           val tableExists = JdbcUtils.tableExists(conn, url, table)
    +      if (tableExists) {
    +        mode match {
    +          case SaveMode.Overwrite =>
    +            if (isTruncate && 
isCascadingTruncateTable(url).contains(false)) {
    --- End diff --
    
    one thing -- please avoid using Option.contains in the future. It is in 
general actually very confusing and more error prone, especially to people not 
super familiar with Scala, to use option as a collection (or monad).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to