pick part of #52989
This commit is contained in:
committed by
GitHub
parent
da917573f4
commit
c6b18e7075
@ -135,6 +135,7 @@ public abstract class ExternalDatabase<T extends ExternalTable>
|
||||
public synchronized void setUnInitialized(boolean invalidCache) {
|
||||
this.initialized = false;
|
||||
this.invalidCacheInInit = invalidCache;
|
||||
this.lowerCaseToTableName = Maps.newConcurrentMap();
|
||||
if (extCatalog.getUseMetaCache().isPresent()) {
|
||||
if (extCatalog.getUseMetaCache().get() && metaCache != null) {
|
||||
metaCache.invalidateAll();
|
||||
@ -318,6 +319,7 @@ public abstract class ExternalDatabase<T extends ExternalTable>
|
||||
|
||||
private List<Pair<String, String>> listTableNames() {
|
||||
List<Pair<String, String>> tableNames;
|
||||
this.lowerCaseToTableName.clear();
|
||||
if (name.equals(InfoSchemaDb.DATABASE_NAME)) {
|
||||
tableNames = ExternalInfoSchemaDatabase.listTableNames().stream()
|
||||
.map(tableName -> {
|
||||
@ -583,37 +585,36 @@ public abstract class ExternalDatabase<T extends ExternalTable>
|
||||
@Override
|
||||
public T getTableNullable(String tableName) {
|
||||
makeSureInitialized();
|
||||
String finalName = tableName;
|
||||
if (this.isStoredTableNamesLowerCase()) {
|
||||
tableName = tableName.toLowerCase();
|
||||
finalName = tableName.toLowerCase();
|
||||
}
|
||||
if (this.isTableNamesCaseInsensitive()) {
|
||||
String realTableName = lowerCaseToTableName.get(tableName.toLowerCase());
|
||||
if (realTableName == null) {
|
||||
finalName = lowerCaseToTableName.get(tableName.toLowerCase());
|
||||
if (finalName == null) {
|
||||
// Here we need to execute listTableNames() once to fill in lowerCaseToTableName
|
||||
// to prevent lowerCaseToTableName from being empty in some cases
|
||||
listTableNames();
|
||||
tableName = lowerCaseToTableName.get(tableName.toLowerCase());
|
||||
if (tableName == null) {
|
||||
finalName = lowerCaseToTableName.get(tableName.toLowerCase());
|
||||
if (finalName == null) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
tableName = realTableName;
|
||||
}
|
||||
}
|
||||
if (extCatalog.getLowerCaseMetaNames().equalsIgnoreCase("true")
|
||||
&& (this.isTableNamesCaseInsensitive())) {
|
||||
tableName = tableName.toLowerCase();
|
||||
finalName = tableName.toLowerCase();
|
||||
}
|
||||
if (extCatalog.getUseMetaCache().get()) {
|
||||
// must use full qualified name to generate id.
|
||||
// otherwise, if 2 databases have the same table name, the id will be the same.
|
||||
return metaCache.getMetaObj(tableName,
|
||||
Util.genIdByName(extCatalog.getName(), name, tableName)).orElse(null);
|
||||
return metaCache.getMetaObj(finalName,
|
||||
Util.genIdByName(extCatalog.getName(), name, finalName)).orElse(null);
|
||||
} else {
|
||||
if (!tableNameToId.containsKey(tableName)) {
|
||||
if (!tableNameToId.containsKey(finalName)) {
|
||||
return null;
|
||||
}
|
||||
return idToTbl.get(tableNameToId.get(tableName));
|
||||
return idToTbl.get(tableNameToId.get(finalName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user