-
Notifications
You must be signed in to change notification settings - Fork 1k
[KYUUBI #7305] Route JDBC engine metadata calls through DatabaseMetaData #7442
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b699942
[KYUUBI #7305] Route JDBC engine metadata calls through DatabaseMetaData
wangzhigang1999 87a9785
[KYUUBI #7305] Hive JDBC metadata contract tests across 8 dialects
wangzhigang1999 1b11f73
[KYUUBI #7305] Extract metadata call lambdas to named vals for readab…
wangzhigang1999 e444fcb
[KYUUBI #7305] Apply URL catalog + fix PG getSchemas test assertion
wangzhigang1999 2c5d2d6
[KYUUBI #7305] Add phoenix-queryserver-client as test dep for jdbc-it
wangzhigang1999 15bdd03
[KYUUBI #7305] Inline DatabaseTermSupport into MySQL/ClickHouse dialects
wangzhigang1999 94883e4
[KYUUBI #7305] Polish ImpalaSchemaHelper comment with upstream source…
wangzhigang1999 d927966
[KYUUBI #7305] Replace higher-order function operations with concrete…
wangzhigang1999 7e6d727
[KYUUBI #7305] Address review nits
wangzhigang1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...dbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/DatabaseTermSupport.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kyuubi.engine.jdbc.dialect | ||
|
|
||
| import java.sql.{Connection, SQLFeatureNotSupportedException} | ||
|
|
||
| /** | ||
| * Mixin for dialects whose driver exposes the database as either the JDBC catalog or the | ||
| * JDBC schema. Writes both sides, reads the first non-empty one. Used by ClickHouse and the | ||
| * MySQL family (MySQL / Doris / StarRocks). | ||
| */ | ||
| trait DatabaseTermSupport extends JdbcDialect { | ||
|
|
||
| override def setSchema(conn: Connection, schema: String): Unit = { | ||
| setDatabase(conn, schema) | ||
| } | ||
|
|
||
| override def setCatalog(conn: Connection, catalog: String): Unit = { | ||
| setDatabase(conn, catalog) | ||
| } | ||
|
|
||
| override def getCurrentSchema(conn: Connection): String = { | ||
| readDatabase(conn.getSchema, conn.getCatalog) | ||
| } | ||
|
|
||
| override def getCatalog(conn: Connection): String = { | ||
| readDatabase(conn.getCatalog, conn.getSchema) | ||
| } | ||
|
|
||
| // Symmetric with setDatabase: tolerate drivers that reject one of the getters outright. | ||
| private def readDatabase(preferred: => String, fallback: => String): String = { | ||
| val first = | ||
| try Option(preferred).filter(_.nonEmpty) | ||
| catch { case _: SQLFeatureNotSupportedException => None } | ||
| first.getOrElse { | ||
| try fallback | ||
| catch { case _: SQLFeatureNotSupportedException => null } | ||
| } | ||
| } | ||
|
|
||
| // Suppress only the "setter not implemented" signal; real failures (missing db, permission | ||
| // denied) propagate. If neither setter accepts, throw rather than silently no-op. | ||
| protected def setDatabase(conn: Connection, database: String): Unit = { | ||
| var accepted = false | ||
| try { | ||
| conn.setCatalog(database) | ||
| accepted = true | ||
| } catch { | ||
| case _: SQLFeatureNotSupportedException => | ||
|
wangzhigang1999 marked this conversation as resolved.
Outdated
|
||
| } | ||
| try { | ||
| conn.setSchema(database) | ||
| accepted = true | ||
| } catch { | ||
| case _: SQLFeatureNotSupportedException => | ||
| } | ||
| if (!accepted) { | ||
| throw new SQLFeatureNotSupportedException( | ||
| s"Neither Connection.setCatalog nor Connection.setSchema is supported by this " + | ||
| s"driver; cannot switch to database '$database'") | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.