jd-opensource/joyagent-jdgenie · error · CatalogException
获取数据库表失败
Error message
获取数据库表失败 %s
What it means
ClickhouseCatalog.listTables wraps any failure while reading the table list of a ClickHouse schema into CatalogException with the message '获取数据库表失败 <schema>'. The original exception (SQL errors, connection problems, bad query) is attached as the cause. It signals that the catalog metadata query could not complete for the given schema.
Solutions
- Verify the schema/database name exists in ClickHouse (SHOW DATABASES) and is spelled correctly.
- Check the ClickHouse JDBC connection (URL, user, password) is valid and the server is reachable.
- Inspect the wrapped cause (e.getCause()) for the underlying SQL/IO error.
- Grant the connecting user permission to read metadata tables.
Example fix
// before
catalog.listTables("mydb"); // throws CatalogException if 'mydb' misspelled
// after
List<SimpleTable> tables = catalog.listTables("my_db"); // verify with SHOW DATABASES first Defensive patterns
Strategy: try-catch
Validate before calling
// Java: check schema is provided and non-blank before the call
if (schema == null || schema.trim().isEmpty()) {
throw new IllegalArgumentException("schema is required for listTables");
} Try / catch
try {
List<SimpleTable> tables = catalog.listTables(schema);
} catch (CatalogException e) {
log.error("listTables failed for schema {} cause={}", schema, e.getCause(), e);
// fail fast or fall back to cached metadata
} Prevention
- Always log e.getCause() — CatalogException is only a wrapper.
- Validate the schema name against SHOW DATABASES output at startup.
- Monitor ClickHouse connectivity before metadata queries.
- Use quoted/lowercase identifiers consistently.
When it happens
Trigger: Calling listTables(schema) when the ClickHouse connection fails, the schema/database does not exist or is misspelled, or the metadata query (e.g. against system.tables) throws while iterating the ResultSet.
Common situations: Wrong database name passed in (case sensitivity), ClickHouse server unreachable or credentials invalid, insufficient privileges to read system tables, or driver version mismatch changing the metadata column names.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- 获取表字段信息失败
- 获取表字段信息失败
- Failed listing database in catalog
- Failed getting table
- Could not find any jdbc dialect factory that can handled
AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08).
Data as JSON: /api/errors/7f406f458adc29b3.
Report an issue: GitHub.
Appendix: source
Thrown at genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/clickhouse/ClickhouseCatalog.java:36
public class ClickhouseCatalog extends AbstractJdbcCatalog {
@Override
public List<SimpleTable> listTables(Connection connection, String schema) throws CatalogException {
String sql = "SELECT concat(database,'.',name) as name FROM system.tables WHERE database = '" + schema + "'";
try (Statement prepared = connection.createStatement();
ResultSet rs = prepared.executeQuery(sql)) {
List<SimpleTable> tables = new ArrayList<>();
while (rs.next()) {
SimpleTable st = new SimpleTable();
st.setTableSchema(schema);
st.setTableName(rs.getString("name"));
tables.add(st);
}
return tables;
} catch (Exception e) {
throw new CatalogException(
String.format("获取数据库表失败 %s ", schema), e);
}
}
public String getColumnType(String columnType) {
return switch (StandardColumnType.of(columnType)) {
case DECIMAL -> "Decimal64(4)";
case DATE -> "DateTime";
default -> "String";
};
}
public BigDecimal parseDecimal(String value, String fieldName) {
BigDecimal decimal = null;
if (StringUtils.isNotBlank(value)) {
try {View on GitHub (pinned to 2417e0b8b6)