You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/08/02 05:57:57 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #24980: [SPARK-28178][SQL] DataSourceV2: DataFrameWriter.insertInfo

cloud-fan commented on a change in pull request #24980: [SPARK-28178][SQL] DataSourceV2: DataFrameWriter.insertInfo
URL: https://github.com/apache/spark/pull/24980#discussion_r309991243
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameWriter.scala
 ##########
 @@ -370,6 +371,45 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) {
       )
     }
 
+    df.sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName) match {
+      case CatalogObjectIdentifier(Some(catalog), ident) =>
+        insertInto(catalog, ident)
+      case AsTableIdentifier(tableIdentifier) =>
+        insertInto(tableIdentifier)
+    }
+  }
+
+  private def insertInto(catalog: CatalogPlugin, ident: Identifier): Unit = {
+    import org.apache.spark.sql.catalog.v2.CatalogV2Implicits._
+
+    val table = DataSourceV2Relation.create(catalog.asTableCatalog.loadTable(ident))
+
+    val command = modeForDSV2 match {
+      case SaveMode.Append =>
+        AppendData.byName(table, df.logicalPlan)
 
 Review comment:
   I missed it. If you look at the doc of `insertInto`, it says
   ```
      * Inserts the content of the `DataFrame` to the specified table. It requires that
      * the schema of the `DataFrame` is the same as the schema of the table.
      *
      * @note Unlike `saveAsTable`, `insertInto` ignores the column names and just uses position-based
      * resolution. For example:
   ```
   
   We should use `byPosition` here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org