fix(iotdb): load databases without duplicate schema
This commit is contained in:
1 parent
54dc3c1c18
commit
5c79c26954
3 files changed
+29
-1
No files matched your search
@@ -1,8 +1,13 @@
|
||||
package com.dbx.agent.iotdb;
|
||||
|
||||
import com.dbx.agent.ConfiguredJdbcAgent;
|
||||
import com.dbx.agent.DatabaseInfo;
|
||||
import com.dbx.agent.JdbcAgentProfile;
|
||||
import com.dbx.agent.JsonRpcServer;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class IoTDBAgent extends ConfiguredJdbcAgent {
|
||||
public static final JdbcAgentProfile IOTDB_PROFILE = new JdbcAgentProfile(
|
||||
@@ -16,6 +21,25 @@ public final class IoTDBAgent extends ConfiguredJdbcAgent {
|
||||
super(IOTDB_PROFILE);
|
||||
}
|
||||
|
||||
// IoTDB 的 database 是 `root.xxx` 路径前缀;JDBC metadata 会把同一路径同时投影成 catalog/schema。
|
||||
// 这里使用 IoTDB 原生语句作为 database 列表来源,避免依赖驱动的关系型兼容层。
|
||||
@Override
|
||||
public List<DatabaseInfo> listDatabases() {
|
||||
return unchecked(() -> {
|
||||
List<DatabaseInfo> result = new ArrayList<>();
|
||||
try (Statement stmt = requireConnection().createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SHOW DATABASES")) {
|
||||
while (rs.next()) {
|
||||
String name = rs.getString(1);
|
||||
if (name != null && !name.trim().isEmpty()) {
|
||||
result.add(new DatabaseInfo(name.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new JsonRpcServer(new IoTDBAgent()).run();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user