【业务影响】
【是否存算分离】
【StarRocks版本】3.3.13
package org.aurafin;
import java.sql.*;
import java.util.*;
public class StarrocksCatalogTableFetcher {
public static Set<String> fetchTableNames(String jdbcUrl, String user, String password) throws Exception {
Set<String> tables = new HashSet<>();
try (Connection conn = DriverManager.getConnection(jdbcUrl, user, password)) {
// 确保连接已经切换到了正确的 catalog.db(即 jdbcUrl 中的路径是 hive_catalog.db)
String schema = conn.getSchema(); // 对于 StarRocks,相当于 database
DatabaseMetaData metadata = conn.getMetaData();
try (ResultSet rs = metadata.getTables(null, schema, "%", new String[] {"TABLE", "VIEW", "EXTERNAL TABLE"})) {
while (rs.next()) {
String tableName = rs.getString(3); // 或 rs.getString(3)
tables.add(tableName);
}
}
}
return tables;
}
public static void main(String[] args) {
String jdbcUrl = "jdbc:mysql://kura:9030/hive_catalog_hms.aurafin?userInformationSchema=false";
String user = "root"; // 替换为你实际用户名
String password = ""; // 替换为你实际密码
try {
Set<String> tables = fetchTableNames(jdbcUrl, user, password);
for (String table : tables) {
System.out.println("Found table: " + table);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
console:
Found table: casionxia_snap_marm_model_record_v2__createbyhive
Found table: partition_tbl_1
Process finished with exit code 0