beliefer commented on code in PR #39062:
URL: https://github.com/apache/spark/pull/39062#discussion_r1108081667
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala:
##########
@@ -491,6 +490,13 @@ abstract class JdbcDialect extends Serializable with
Logging {
s"COMMENT ON SCHEMA ${quoteIdentifier(schema)} IS '$comment'"
}
+ def getCreateTableQuery(
Review Comment:
Do we really need this public function? It seems just easy to test.
##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala:
##########
@@ -2007,7 +2007,7 @@ class JDBCSuite extends QueryTest with SharedSparkSession
{
StructField("dummy_col_b", LongType)
))
val strSchema = JdbcUtils.schemaString(schema,
sqlContext.conf.caseSensitiveAnalysis, url)
- assert(mySQLDialect.createTable("Dummy", strSchema, "") ===
+ assert(mySQLDialect.getCreateTableQuery("Dummy", strSchema, "") ===
Review Comment:
I think we should have an end-to-end test now.
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala:
##########
@@ -135,6 +135,34 @@ abstract class JdbcDialect extends Serializable with
Logging {
s""""$colName""""
}
+ /**
+ * Create the table if the table does not exist.
+ * To allow certain options to append when create a new table, which can be
+ * table_options or partition_options.
+ * E.g., "CREATE TABLE t (name string) ENGINE=InnoDB DEFAULT CHARSET=utf8"
+ * @param statement
+ * @param tableName
+ * @param strSchema
+ * @param options
+ */
+ def createTable(
+ statement: Statement,
+ tableName: String,
+ strSchema: String,
+ options: JdbcOptionsInWrite): Unit = {
+ val createTableOptions = options.createTableOptions
+ statement.executeUpdate(s"CREATE TABLE $tableName ($strSchema)
$createTableOptions")
+ if (options.tableComment.nonEmpty) {
+ try {
+ val tableCommentQuery = getTableCommentQuery(tableName,
options.tableComment)
+ statement.executeUpdate(tableCommentQuery)
Review Comment:
Create table and add comment share the same statement here. It will lead to
create table failed when adding comment occurs error if statement not be
committed.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]