-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-38054][SQL] Supports list namespaces in JDBC v2 MySQL dialect #35355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
2dd6350
c6a9542
f220c56
b6efaa8
29d8da5
4978c25
826c00f
b3a1c3b
19fb6cd
d3a004d
5182cdf
daa11d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -979,8 +979,23 @@ object JdbcUtils extends Logging with SQLConfHelper { | |
| namespace: String, | ||
| comment: String): Unit = { | ||
| val dialect = JdbcDialects.get(options.url) | ||
| val schemaCommentQuery = if (comment.isEmpty) { | ||
| comment | ||
| } else { | ||
| dialect.getSchemaCommentQuery(namespace, comment) | ||
| } | ||
| executeStatement(conn, options, s"CREATE SCHEMA ${dialect.quoteIdentifier(namespace)}") | ||
| if (!comment.isEmpty) createNamespaceComment(conn, options, namespace, comment) | ||
| if (comment.nonEmpty) executeStatement(conn, options, schemaCommentQuery) | ||
|
||
| } | ||
|
|
||
| def namespaceExists(conn: Connection, options: JDBCOptions, namespace: String): Boolean = { | ||
|
||
| val dialect = JdbcDialects.get(options.url) | ||
| dialect.namespacesExists(conn, options, namespace) | ||
| } | ||
|
|
||
| def listNamespaces(conn: Connection, options: JDBCOptions): Array[Array[String]] = { | ||
| val dialect = JdbcDialects.get(options.url) | ||
| dialect.listNamespaces(conn, options) | ||
| } | ||
|
|
||
| def createNamespaceComment( | ||
|
|
@@ -989,26 +1004,15 @@ object JdbcUtils extends Logging with SQLConfHelper { | |
| namespace: String, | ||
| comment: String): Unit = { | ||
| val dialect = JdbcDialects.get(options.url) | ||
| try { | ||
| executeStatement( | ||
| conn, options, dialect.getSchemaCommentQuery(namespace, comment)) | ||
| } catch { | ||
| case e: Exception => | ||
| logWarning("Cannot create JDBC catalog comment. The catalog comment will be ignored.") | ||
| } | ||
| executeStatement(conn, options, dialect.getSchemaCommentQuery(namespace, comment)) | ||
| } | ||
|
|
||
| def removeNamespaceComment( | ||
| conn: Connection, | ||
| options: JDBCOptions, | ||
| namespace: String): Unit = { | ||
| val dialect = JdbcDialects.get(options.url) | ||
| try { | ||
| executeStatement(conn, options, dialect.removeSchemaCommentQuery(namespace)) | ||
| } catch { | ||
| case e: Exception => | ||
| logWarning("Cannot drop JDBC catalog comment.") | ||
| } | ||
| executeStatement(conn, options, dialect.removeSchemaCommentQuery(namespace)) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1148,11 +1152,17 @@ object JdbcUtils extends Logging with SQLConfHelper { | |
| } | ||
| } | ||
|
|
||
| def executeQuery(conn: Connection, options: JDBCOptions, sql: String): ResultSet = { | ||
| def executeQuery(conn: Connection, options: JDBCOptions, sql: String)( | ||
| f: ResultSet => Unit): Unit = { | ||
| val statement = conn.createStatement | ||
| try { | ||
| statement.setQueryTimeout(options.queryTimeout) | ||
| statement.executeQuery(sql) | ||
| val rs = statement.executeQuery(sql) | ||
| try { | ||
| f(rs) | ||
| } finally { | ||
| rs.close() | ||
| } | ||
| } finally { | ||
| statement.close() | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,6 +229,29 @@ abstract class JdbcDialect extends Serializable with Logging{ | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check namespace exists or not. | ||
| */ | ||
| def namespacesExists(conn: Connection, options: JDBCOptions, namespace: String): Boolean = { | ||
|
||
| val rs = conn.getMetaData.getSchemas(null, namespace) | ||
| while (rs.next()) { | ||
| if (rs.getString(1) == namespace) return true; | ||
| } | ||
| false | ||
| } | ||
|
|
||
| /** | ||
| * Lists all the schemas in this table. | ||
| */ | ||
| def listNamespaces(conn: Connection, options: JDBCOptions): Array[Array[String]] = { | ||
| val schemaBuilder = ArrayBuilder.make[Array[String]] | ||
| val rs = conn.getMetaData.getSchemas() | ||
| while (rs.next()) { | ||
| schemaBuilder += Array(rs.getString(1)) | ||
| } | ||
| schemaBuilder.result | ||
| } | ||
|
|
||
| /** | ||
| * Return Some[true] iff `TRUNCATE TABLE` causes cascading default. | ||
| * Some[true] : TRUNCATE TABLE causes cascading. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the actual change here? Get rid of the try-catch in
createNamespaceComment?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want keep the atomic of create namespace with comment.