Skip to content

Commit dcce21c

Browse files
zy-kkkmorningman
authored andcommitted
[opt](catalog) use table in db object return get db (#46211)
### What problem does this PR solve? This pull request includes several changes across multiple files to improve logging, add missing logic, and correct SQL syntax. The most important changes include adding logging for synchronization actions, setting the database if missing, and correcting SQL syntax for MySQL queries. Co-authored-by: morningman <[email protected]>
1 parent 6645035 commit dcce21c

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public abstract class ExternalCatalog
110110
public static final String CREATE_TIME = "create_time";
111111
public static final boolean DEFAULT_USE_META_CACHE = true;
112112

113-
public static final String FOUND_CONFLICTING = "Found conflicting";
113+
public static final String FOUND_CONFLICTING = "Found conflicting";
114114
public static final String ONLY_TEST_LOWER_CASE_TABLE_NAMES = "only_test_lower_case_table_names";
115115

116116
// Properties that should not be shown in the `show create catalog` result
@@ -746,6 +746,7 @@ public void replayInitCatalog(InitCatalogLog log) {
746746
Preconditions.checkNotNull(db.get());
747747
tmpDbNameToId.put(db.get().getFullName(), db.get().getId());
748748
tmpIdToDb.put(db.get().getId(), db.get());
749+
LOG.info("Synchronized database (refresh): [Name: {}, ID: {}]", db.get().getFullName(), db.get().getId());
749750
}
750751
for (int i = 0; i < log.getCreateCount(); i++) {
751752
ExternalDatabase<? extends ExternalTable> db =
@@ -754,6 +755,8 @@ public void replayInitCatalog(InitCatalogLog log) {
754755
if (db != null) {
755756
tmpDbNameToId.put(db.getFullName(), db.getId());
756757
tmpIdToDb.put(db.getId(), db);
758+
LOG.info("Synchronized database (create): [Name: {}, ID: {}, Remote Name: {}]",
759+
db.getFullName(), db.getId(), log.getRemoteDbNames().get(i));
757760
}
758761
}
759762
dbNameToId = tmpDbNameToId;

fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalDatabase.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ public void replayInitDb(InitDatabaseLog log, ExternalCatalog catalog) {
211211
if (table.isPresent()) {
212212
tmpTableNameToId.put(table.get().getName(), table.get().getId());
213213
tmpIdToTbl.put(table.get().getId(), table.get());
214+
215+
// Add logic to set the database if missing
216+
if (table.get().getDb() == null) {
217+
table.get().setDb(this);
218+
}
219+
LOG.info("Synchronized table (refresh): [Name: {}, ID: {}]", table.get().getName(),
220+
table.get().getId());
214221
}
215222
}
216223
for (int i = 0; i < log.getCreateCount(); i++) {
@@ -219,6 +226,13 @@ public void replayInitDb(InitDatabaseLog log, ExternalCatalog catalog) {
219226
log.getCreateTableIds().get(i), catalog, this, false);
220227
tmpTableNameToId.put(table.getName(), table.getId());
221228
tmpIdToTbl.put(table.getId(), table);
229+
230+
// Add logic to set the database if missing
231+
if (table.getDb() == null) {
232+
table.setDb(this);
233+
}
234+
LOG.info("Synchronized table (create): [Name: {}, ID: {}, Remote Name: {}]",
235+
table.getName(), table.getId(), log.getRemoteTableNames().get(i));
222236
}
223237
tableNameToId = tmpTableNameToId;
224238
idToTbl = tmpIdToTbl;

fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public BaseAnalysisTask createAnalysisTask(AnalysisInfo info) {
308308

309309
@Override
310310
public DatabaseIf getDatabase() {
311-
return catalog.getDbNullable(dbName);
311+
return this.db;
312312
}
313313

314314
@Override

fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/JdbcExternalTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
public class JdbcExternalTable extends ExternalTable {
5252
private static final Logger LOG = LogManager.getLogger(JdbcExternalTable.class);
5353

54-
public static final String MYSQL_ROW_COUNT_SQL = "SELECT max(row_count) as rows FROM ("
54+
public static final String MYSQL_ROW_COUNT_SQL = "SELECT max(row_count) as `rows` FROM ("
5555
+ "(SELECT TABLE_ROWS AS row_count FROM INFORMATION_SCHEMA.TABLES "
5656
+ "WHERE TABLE_SCHEMA = '${dbName}' AND TABLE_NAME = '${tblName}' "
5757
+ "AND TABLE_TYPE = 'BASE TABLE') "

regression-test/data/external_table_p0/hive/test_hive_use_meta_cache.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ p1=part1
3434
p1=part2
3535

3636
-- !sql10 --
37+
test_use_meta_cache_partitioned_tbl_hive
38+
test_use_meta_cache_tbl_hive
3739

3840
-- !sql11 --
3941

@@ -123,6 +125,8 @@ p1=part1
123125
p1=part2
124126

125127
-- !sql10 --
128+
test_use_meta_cache_partitioned_tbl_hive
129+
test_use_meta_cache_tbl_hive
126130

127131
-- !sql11 --
128132

regression-test/suites/external_table_p0/hive/test_hive_parquet.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ suite("test_hive_parquet", "p0,external,hive,external_docker,external_docker_hiv
186186
"type"="hms",
187187
'hive.metastore.uris' = 'thrift://${externalEnvIp}:${hms_port}'
188188
);"""
189-
sql """use `${catalog_name}`.`default`"""
189+
sql """switch ${catalog_name}"""
190+
sql """use `default`"""
190191

191192
sql """set enable_fallback_to_original_planner=false;"""
192193

regression-test/suites/external_table_p2/hudi/test_hudi_snapshot.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ suite("test_hudi_snapshot", "p2,external,hudi,external_remote,external_remote_hu
3434
sql """ use regression_hudi;"""
3535
sql """ set enable_fallback_to_original_planner=false """
3636

37-
// 创建groovy函数,接收table_name为参数
3837
def test_hudi_snapshot_querys = { table_name ->
3938
// Query users by event_time in descending order and limit output
4039
qt_q01 """SELECT * FROM ${table_name} ORDER BY event_time DESC LIMIT 10;"""
@@ -49,7 +48,7 @@ suite("test_hudi_snapshot", "p2,external,hudi,external_remote,external_remote_hu
4948
qt_q04 """SELECT * FROM ${table_name} WHERE event_time BETWEEN '2024-01-01 00:00:00' AND '2024-12-31 23:59:59' ORDER BY event_time LIMIT 10;"""
5049

5150
// Count users by age group and limit output
52-
qt_q05 """SELECT age, COUNT(*) AS user_count FROM ${table_name} GROUP BY age ORDER BY user_count DESC LIMIT 5;"""
51+
qt_q05 """SELECT age, COUNT(*) AS user_count FROM ${table_name} GROUP BY age ORDER BY user_count, age DESC LIMIT 5;"""
5352

5453
// Query users with purchase records and limit output
5554
qt_q06 """SELECT user_id, purchases FROM ${table_name} WHERE array_size(purchases) > 0 ORDER BY user_id LIMIT 5;"""

0 commit comments

Comments
 (0)