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

    https://github.com/apache/spark/pull/7623#discussion_r35346342
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/DataFrameWriter.scala ---
    @@ -183,35 +188,37 @@ final class DataFrameWriter private[sql](df: 
DataFrame) {
        * @since 1.4.0
        */
       def saveAsTable(tableName: String): Unit = {
    -    if (df.sqlContext.catalog.tableExists(tableName :: Nil) && mode != 
SaveMode.Overwrite) {
    -      mode match {
    -        case SaveMode.Ignore =>
    -          // Do nothing
    -
    -        case SaveMode.ErrorIfExists =>
    -          throw new AnalysisException(s"Table $tableName already exists.")
    -
    -        case SaveMode.Append =>
    -          // If it is Append, we just ask insertInto to handle it. We will 
not use insertInto
    -          // to handle saveAsTable with Overwrite because saveAsTable can 
change the schema of
    -          // the table. But, insertInto with Overwrite requires the schema 
of data be the same
    -          // the schema of the table.
    -          insertInto(tableName)
    -
    -        case SaveMode.Overwrite =>
    -          throw new UnsupportedOperationException("overwrite mode 
unsupported.")
    -      }
    -    } else {
    -      val cmd =
    -        CreateTableUsingAsSelect(
    -          tableName,
    -          source,
    -          temporary = false,
    -          
partitioningColumns.map(_.toArray).getOrElse(Array.empty[String]),
    -          mode,
    -          extraOptions.toMap,
    -          df.logicalPlan)
    -      df.sqlContext.executePlan(cmd).toRdd
    +    saveAsTable(new SqlParser().parseTableIdentifier(tableName))
    +  }
    +
    +  private def saveAsTable(tableIdent: TableIdentifier): Unit = {
    +    val tableExists = df.sqlContext.catalog.tableExists(tableIdent.toSeq)
    +
    +    (tableExists, mode) match {
    +      case (true, SaveMode.Ignore) =>
    +        // Do nothing
    +
    +      case (true, SaveMode.ErrorIfExists) =>
    +        throw new AnalysisException(s"Table $tableIdent already exists.")
    +
    +      case (true, SaveMode.Append) =>
    +        // If it is Append, we just ask insertInto to handle it. We will 
not use insertInto
    +        // to handle saveAsTable with Overwrite because saveAsTable can 
change the schema of
    +        // the table. But, insertInto with Overwrite requires the schema 
of data be the same
    +        // the schema of the table.
    +        insertInto(tableIdent)
    +
    +      case _ =>
    +        val cmd =
    +          CreateTableUsingAsSelect(
    --- End diff --
    
    Should refactor `CreateTableUsingAsSelect` to used `TableIdentifier`.


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