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

    https://github.com/apache/spark/pull/10380#discussion_r48252291
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
 ---
    @@ -63,14 +63,11 @@ object JdbcUtils extends Logging {
        * Returns a PreparedStatement that inserts a row into table via conn.
        */
       def insertStatement(conn: Connection, table: String, rddSchema: 
StructType): PreparedStatement = {
    -    val sql = new StringBuilder(s"INSERT INTO $table VALUES (")
    -    var fieldsLeft = rddSchema.fields.length
    -    while (fieldsLeft > 0) {
    -      sql.append("?")
    -      if (fieldsLeft > 1) sql.append(", ") else sql.append(")")
    -      fieldsLeft = fieldsLeft - 1
    -    }
    -    conn.prepareStatement(sql.toString())
    +    val sql = rddSchema.fields.map(field => field.name)
    --- End diff --
    
    Yes, very close now. I think that can be tightened up in a few minor ways, 
like `map(_.name)` and `map(_ => "?")`. There's an extra space inside the paren 
in line 67, and the VALUES clause inserts extra spaces before between and after 
?s. Finally the wrapping is a little funny. Maybe break this down into a `val` 
for the column names clause, and a `val` for the ? placeholders clause, and 
then return their interpolation into the final single format string `INSERT 
INTO $table $columns VALUES $placeholders` or something.


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