From d31c04c4c645323e191e604d1c368076b50b07ef Mon Sep 17 00:00:00 2001 From: Pranav Date: Thu, 3 Aug 2023 21:45:01 -0700 Subject: [PATCH] Fix the bug in getIndexInfo for mysql (#14750) --- .../druid/metadata/SQLMetadataConnector.java | 26 ++++++++++++++----- .../storage/derby/DerbyConnector.java | 18 +++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java b/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java index 5c8c9d39c26..a6e0dbe396e 100644 --- a/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java +++ b/server/src/main/java/org/apache/druid/metadata/SQLMetadataConnector.java @@ -864,13 +864,7 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector { DatabaseMetaData databaseMetaData = handle.getConnection().getMetaData(); // Fetch the index for given table - ResultSet resultSet = databaseMetaData.getIndexInfo( - null, - null, - StringUtils.toUpperCase(tableName), - false, - false - ); + ResultSet resultSet = getIndexInfo(databaseMetaData, tableName); while (resultSet.next()) { String indexName = resultSet.getString("INDEX_NAME"); if (org.apache.commons.lang.StringUtils.isNotBlank(indexName)) { @@ -887,6 +881,24 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector return ImmutableSet.copyOf(res); } + /** + * Get the ResultSet for indexInfo for given table + * + * @param databaseMetaData DatabaseMetaData + * @param tableName Name of table + * @return ResultSet with index info + */ + public ResultSet getIndexInfo(DatabaseMetaData databaseMetaData, String tableName) throws SQLException + { + return databaseMetaData.getIndexInfo( + null, + null, + tableName, // tableName is case-sensitive in mysql default setting + false, + false + ); + } + /** * create index on the table with retry if not already exist, to be called after createTable * diff --git a/server/src/main/java/org/apache/druid/metadata/storage/derby/DerbyConnector.java b/server/src/main/java/org/apache/druid/metadata/storage/derby/DerbyConnector.java index 19d0c6b04f1..a84b1e975c0 100644 --- a/server/src/main/java/org/apache/druid/metadata/storage/derby/DerbyConnector.java +++ b/server/src/main/java/org/apache/druid/metadata/storage/derby/DerbyConnector.java @@ -168,6 +168,24 @@ public class DerbyConnector extends SQLMetadataConnector ); } + /** + * Get the ResultSet for indexInfo for given table + * + * @param databaseMetaData DatabaseMetaData + * @param tableName Name of table + * @return ResultSet with index info + */ + @Override + public ResultSet getIndexInfo(DatabaseMetaData databaseMetaData, String tableName) throws SQLException + { + return databaseMetaData.getIndexInfo( + null, + null, + StringUtils.toUpperCase(tableName), // tableName needs to be uppercase in derby default setting + false, + false + ); + } @LifecycleStart public void start() {