Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/10312#discussion_r47928583
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala ---
@@ -108,6 +108,33 @@ abstract class JdbcDialect extends Serializable {
def beforeFetch(connection: Connection, properties: Map[String,
String]): Unit = {
}
+ /**
+ * Get the SQL statement that should be used to insert new records into
the table.
+ * Dialects can override this method to return a statement that works
best in a particular
+ * database.
+ * @param table The name of the table.
+ * @param rddSchema The schema of DataFrame to be inserted
+ * @param columnMapping An optional mapping from DataFrame field names
to database column
+ * names
+ * @return The SQL statement to use for inserting into the table.
+ */
+ def getInsertStatement(table: String,
+ rddSchema: StructType,
+ columnMapping: scala.collection.Map[String,
String] = null): String = {
+ if (columnMapping == null) {
+ rddSchema.fields.map(field => "?")
+ .mkString( s"INSERT INTO $table VALUES (", ", ", " ) ")
--- End diff --
There's still an extra space before the first arg in both `mkString` calls.
Also `field => "?"` could be `_ => "?"` for a touch more clarity. Finally I
think the `match` statement actually reduces to
`columnMapping.getOrElse(field.name, field.name)`?
---
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]