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 2020/10/06 23:36:50 UTC

[GitHub] [spark] viirya commented on a change in pull request #29885: [SPARK-33010][SQL]Make DataFrameWriter.jdbc work for DataSource V2

viirya commented on a change in pull request #29885:
URL: https://github.com/apache/spark/pull/29885#discussion_r500652507



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameWriter.scala
##########
@@ -808,9 +808,24 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) {
     assertNotBucketed("jdbc")
     // connectionProperties should override settings in extraOptions.
     this.extraOptions ++= connectionProperties.asScala
-    // explicit url and dbtable should override all
-    this.extraOptions ++= Seq("url" -> url, "dbtable" -> table)
-    format("jdbc").save()
+    // explicit url should override all
+    this.extraOptions += "url" -> url
+
+    import df.sparkSession.sessionState.analyzer.NonSessionCatalogAndIdentifier
+    import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+    val session = df.sparkSession
+    this.source = "jdbc"
+
+    session.sessionState.sqlParser.parseMultipartIdentifier(table) match {
+      case nameParts @ NonSessionCatalogAndIdentifier(catalog, tableIdentifier) =>
+        saveAsTable(catalog.asTableCatalog, tableIdentifier, nameParts)

Review comment:
       Returned catalog is always a `TableCatalog`?

##########
File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameWriter.scala
##########
@@ -808,9 +808,24 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) {
     assertNotBucketed("jdbc")
     // connectionProperties should override settings in extraOptions.
     this.extraOptions ++= connectionProperties.asScala
-    // explicit url and dbtable should override all
-    this.extraOptions ++= Seq("url" -> url, "dbtable" -> table)
-    format("jdbc").save()
+    // explicit url should override all
+    this.extraOptions += "url" -> url
+
+    import df.sparkSession.sessionState.analyzer.NonSessionCatalogAndIdentifier
+    import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+    val session = df.sparkSession
+    this.source = "jdbc"
+
+    session.sessionState.sqlParser.parseMultipartIdentifier(table) match {
+      case nameParts @ NonSessionCatalogAndIdentifier(catalog, tableIdentifier) =>
+        saveAsTable(catalog.asTableCatalog, tableIdentifier, nameParts)

Review comment:
       Or do we need to check if `catalog` is `JDBCTableCatalog`?




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



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