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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]