cloud-fan commented on a change in pull request #29324: URL: https://github.com/apache/spark/pull/29324#discussion_r464794637
########## File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala ########## @@ -900,10 +889,52 @@ object JdbcUtils extends Logging { newTable: String, options: JDBCOptions): Unit = { val dialect = JdbcDialects.get(options.url) + executeStatement(conn, options, dialect.renameTable(oldTable, newTable)) + } + + /** + * Update a table from the JDBC database. + */ + def alterTable( + conn: Connection, + tableName: String, + changes: Seq[TableChange], + options: JDBCOptions): Unit = { + val dialect = JdbcDialects.get(options.url) + if (changes.length == 1) { + executeStatement(conn, options, dialect.alterTable(tableName, changes)(0)) + } else { + val metadata = conn.getMetaData + if (!metadata.supportsTransactions) { + throw new SQLFeatureNotSupportedException(s"${this.getClass.getName}.alterTable doesn't" + + s" support multiple alter table changes simultaneously for database server" + + s" that doesn't have transaction support.") + } else { + conn.setAutoCommit(false) + val statement = conn.createStatement + try { + statement.setQueryTimeout(options.queryTimeout) + for (sql <- dialect.alterTable(tableName, changes)) { + statement.executeUpdate(sql) + } + conn.commit() + } catch { + case e: SQLException => + if (conn != null) conn.rollback() + throw e Review comment: +1 ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org