linghengqian commented on code in PR #33762:
URL: https://github.com/apache/shardingsphere/pull/33762#discussion_r1853931000
##########
infra/common/src/main/java/org/apache/shardingsphere/infra/database/DatabaseTypeEngine.java:
##########
@@ -117,27 +115,29 @@ public static Map<String, DatabaseType>
getStorageTypes(final DatabaseConfigurat
/**
* Get storage type.
- * Similar to apache/hive 4.0.0's
`org.apache.hive.jdbc.HiveDatabaseMetaData`, it does not implement {@link
java.sql.DatabaseMetaData#getURL()}.
- * So use {@link CatalogSwitchableDataSource#getUrl()} and {@link
ReflectionUtils#getFieldValue(Object, String)} to try fuzzy matching.
+ * Similar to apache/hive 4.0.1's
`org.apache.hive.jdbc.HiveDatabaseMetaData`, it does not implement {@link
DatabaseMetaData#getURL()}.
+ * So use {@link java.sql.Wrapper#isWrapperFor(Class)} to try fuzzy
matching.
*
* @param dataSource data source
* @return storage type
* @throws SQLWrapperException SQL wrapper exception
+ * @throws RuntimeException Runtime exception
*/
public static DatabaseType getStorageType(final DataSource dataSource) {
try (Connection connection = dataSource.getConnection()) {
return DatabaseTypeFactory.get(connection.getMetaData().getURL());
} catch (final SQLFeatureNotSupportedException
sqlFeatureNotSupportedException) {
- if (dataSource instanceof CatalogSwitchableDataSource) {
- return DatabaseTypeFactory.get(((CatalogSwitchableDataSource)
dataSource).getUrl());
+ try (Connection connection = dataSource.getConnection()) {
+ Class<?> hiveConnectionClass =
Class.forName("org.apache.hive.jdbc.HiveConnection");
+ if (connection.isWrapperFor(hiveConnectionClass)) {
+ Object hiveConnection =
connection.unwrap(hiveConnectionClass);
+ String connectedUrl = (String)
hiveConnectionClass.getMethod("getConnectedUrl").invoke(hiveConnection);
+ return DatabaseTypeFactory.get(connectedUrl);
+ }
+ throw new SQLWrapperException(sqlFeatureNotSupportedException);
+ } catch (final SQLException | ClassNotFoundException |
NoSuchMethodException | InvocationTargetException | IllegalAccessException
exception) {
+ throw new RuntimeException(exception);
Review Comment:
- I have opened https://github.com/apache/hive/pull/5554 to try to
completely end this funny logic. The internal structure of HiveServer2 JDBC
Driver is simply a world of Otome mobile game.
--
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]