Skip to content

Commit

Permalink
branch-3.0: [opt](catalog) use table in db object return get db #46211 (
Browse files Browse the repository at this point in the history
#46228)

Cherry-picked from #46211

Co-authored-by: zy-kkk <[email protected]>
Co-authored-by: morningman <[email protected]>
  • Loading branch information
3 people authored Jan 1, 2025
1 parent f983411 commit fb2b67b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public abstract class ExternalCatalog
public static final String CREATE_TIME = "create_time";
public static final boolean DEFAULT_USE_META_CACHE = true;

public static final String FOUND_CONFLICTING = "Found conflicting";
public static final String FOUND_CONFLICTING = "Found conflicting";
public static final String ONLY_TEST_LOWER_CASE_TABLE_NAMES = "only_test_lower_case_table_names";

// Properties that should not be shown in the `show create catalog` result
Expand Down Expand Up @@ -746,6 +746,7 @@ public void replayInitCatalog(InitCatalogLog log) {
Preconditions.checkNotNull(db.get());
tmpDbNameToId.put(db.get().getFullName(), db.get().getId());
tmpIdToDb.put(db.get().getId(), db.get());
LOG.info("Synchronized database (refresh): [Name: {}, ID: {}]", db.get().getFullName(), db.get().getId());
}
for (int i = 0; i < log.getCreateCount(); i++) {
ExternalDatabase<? extends ExternalTable> db =
Expand All @@ -754,6 +755,8 @@ public void replayInitCatalog(InitCatalogLog log) {
if (db != null) {
tmpDbNameToId.put(db.getFullName(), db.getId());
tmpIdToDb.put(db.getId(), db);
LOG.info("Synchronized database (create): [Name: {}, ID: {}, Remote Name: {}]",
db.getFullName(), db.getId(), log.getRemoteDbNames().get(i));
}
}
dbNameToId = tmpDbNameToId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ public void replayInitDb(InitDatabaseLog log, ExternalCatalog catalog) {
if (table.isPresent()) {
tmpTableNameToId.put(table.get().getName(), table.get().getId());
tmpIdToTbl.put(table.get().getId(), table.get());

// Add logic to set the database if missing
if (table.get().getDb() == null) {
table.get().setDb(this);
}
LOG.info("Synchronized table (refresh): [Name: {}, ID: {}]", table.get().getName(),
table.get().getId());
}
}
for (int i = 0; i < log.getCreateCount(); i++) {
Expand All @@ -219,6 +226,13 @@ public void replayInitDb(InitDatabaseLog log, ExternalCatalog catalog) {
log.getCreateTableIds().get(i), catalog, this, false);
tmpTableNameToId.put(table.getName(), table.getId());
tmpIdToTbl.put(table.getId(), table);

// Add logic to set the database if missing
if (table.getDb() == null) {
table.setDb(this);
}
LOG.info("Synchronized table (create): [Name: {}, ID: {}, Remote Name: {}]",
table.getName(), table.getId(), log.getRemoteTableNames().get(i));
}
tableNameToId = tmpTableNameToId;
idToTbl = tmpIdToTbl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public BaseAnalysisTask createAnalysisTask(AnalysisInfo info) {

@Override
public DatabaseIf getDatabase() {
return catalog.getDbNullable(dbName);
return this.db;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
public class JdbcExternalTable extends ExternalTable {
private static final Logger LOG = LogManager.getLogger(JdbcExternalTable.class);

public static final String MYSQL_ROW_COUNT_SQL = "SELECT max(row_count) as rows FROM ("
public static final String MYSQL_ROW_COUNT_SQL = "SELECT max(row_count) as `rows` FROM ("
+ "(SELECT TABLE_ROWS AS row_count FROM INFORMATION_SCHEMA.TABLES "
+ "WHERE TABLE_SCHEMA = '${dbName}' AND TABLE_NAME = '${tblName}' "
+ "AND TABLE_TYPE = 'BASE TABLE') "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ p1=part1
p1=part2

-- !sql10 --
test_use_meta_cache_partitioned_tbl_hive
test_use_meta_cache_tbl_hive

-- !sql11 --

Expand Down Expand Up @@ -123,6 +125,8 @@ p1=part1
p1=part2

-- !sql10 --
test_use_meta_cache_partitioned_tbl_hive
test_use_meta_cache_tbl_hive

-- !sql11 --

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ suite("test_hive_parquet", "p0,external,hive,external_docker,external_docker_hiv
"type"="hms",
'hive.metastore.uris' = 'thrift://${externalEnvIp}:${hms_port}'
);"""
sql """use `${catalog_name}`.`default`"""
sql """switch ${catalog_name}"""
sql """use `default`"""

sql """set enable_fallback_to_original_planner=false;"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ suite("test_hudi_snapshot", "p2,external,hudi,external_remote,external_remote_hu
sql """ use regression_hudi;"""
sql """ set enable_fallback_to_original_planner=false """

// 创建groovy函数,接收table_name为参数
def test_hudi_snapshot_querys = { table_name ->
// Query users by event_time in descending order and limit output
qt_q01 """SELECT * FROM ${table_name} ORDER BY event_time DESC LIMIT 10;"""
Expand All @@ -49,7 +48,7 @@ suite("test_hudi_snapshot", "p2,external,hudi,external_remote,external_remote_hu
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;"""

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

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

0 comments on commit fb2b67b

Please sign in to comment.