дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-28 13:32:29 +02:00
feat(database): support DuckDB SQL and browse attached catalogs (#6254)
DuckDB sources get DuckDB's SQL dialect (highlighting, completion, formatting and resolution) and the database tree lists attached catalogs with their schemas, tables and columns. The JDBC bridge gains a catalogs command and catalog-scoped schema and table metadata, matched by exact catalog and schema names; tables in another catalog open and page through the source session. DDL that attaches, detaches or changes a catalog refreshes the tree. Co-authored-by: principalwater <[email protected]>
Цей коміт міститься в:
1 джерело
c04d9381be
коміт
bd396485c2
38 files changed
+1743
-318
No files matched your search
@@ -36,13 +36,36 @@ public class SelfTest {
|
||||
case "getDatabaseProductVersion" -> "1";
|
||||
case "getIdentifierQuoteString" -> "\"";
|
||||
case "getSearchStringEscape" -> "\\";
|
||||
case "getSchemas" -> rows(List.of(Map.of("TABLE_SCHEM", "app")));
|
||||
case "getTables" -> rows(List.of(Map.of(
|
||||
"TABLE_NAME", "orders", "TABLE_TYPE", "TABLE", "REMARKS", "Orders table")));
|
||||
case "getColumns" -> "app".equals(a[1]) && "%".equals(a[2]) ? rows(List.of(
|
||||
Map.of("TABLE_NAME", "orders", "COLUMN_NAME", "id", "TYPE_NAME", "INT", "NULLABLE", 0),
|
||||
Map.of("TABLE_NAME", "orders", "COLUMN_NAME", "note", "TYPE_NAME", "VARCHAR", "NULLABLE", 1,
|
||||
"COLUMN_DEF", "'none'", "REMARKS", "free text"))) : rows(List.of());
|
||||
case "getCatalogs" -> rows(List.of(
|
||||
Map.of("TABLE_CAT", "root"), Map.of("TABLE_CAT", "archive.db:1")));
|
||||
case "getSchemas" -> a == null
|
||||
? rows(List.of(Map.of("TABLE_SCHEM", "app")))
|
||||
: Arrays.equals(a, new Object[]{"archive.db:1", "%"})
|
||||
? rows(List.of(
|
||||
Map.of("TABLE_CATALOG", "archive.db:1", "TABLE_SCHEM", "qa_%"),
|
||||
Map.of("TABLE_CATALOG", "root", "TABLE_SCHEM", "outside_catalog")))
|
||||
: rows(List.of());
|
||||
case "getTables" -> Arrays.equals(a, new Object[]{"archive.db:1", "qa\\_\\%", "%", null})
|
||||
? rows(List.of(
|
||||
Map.of("TABLE_CAT", "archive.db:1", "TABLE_SCHEM", "qa_%", "TABLE_NAME", "items",
|
||||
"TABLE_TYPE", "BASE TABLE", "REMARKS", "Archived items"),
|
||||
Map.of("TABLE_CAT", "root", "TABLE_SCHEM", "qa_%", "TABLE_NAME", "outside_catalog",
|
||||
"TABLE_TYPE", "BASE TABLE", "REMARKS", "Wrong catalog comment"),
|
||||
Map.of("TABLE_CAT", "archive.db:1", "TABLE_SCHEM", "qaABC", "TABLE_NAME", "outside_schema",
|
||||
"TABLE_TYPE", "BASE TABLE", "REMARKS", "Wrong schema comment")))
|
||||
: Arrays.equals(a, new Object[]{"root", "app", "%", null})
|
||||
? rows(List.of(Map.of("TABLE_NAME", "orders", "TABLE_TYPE", "TABLE", "REMARKS", "Orders table")))
|
||||
: rows(List.of());
|
||||
case "getColumns" -> Arrays.equals(a, new Object[]{"archive.db:1", "qa\\_\\%", "%", "%"})
|
||||
? rows(List.of(
|
||||
Map.of("TABLE_CAT", "archive.db:1", "TABLE_SCHEM", "qa_%", "TABLE_NAME", "items",
|
||||
"COLUMN_NAME", "note", "TYPE_NAME", "VARCHAR", "NULLABLE", 1, "REMARKS", "archive label"),
|
||||
Map.of("TABLE_CAT", "root", "TABLE_SCHEM", "qa_%", "TABLE_NAME", "outside_catalog",
|
||||
"COLUMN_NAME", "note", "TYPE_NAME", "VARCHAR", "NULLABLE", 1, "REMARKS", "outside label")))
|
||||
: "app".equals(a[1]) && "%".equals(a[2]) ? rows(List.of(
|
||||
Map.of("TABLE_NAME", "orders", "COLUMN_NAME", "id", "TYPE_NAME", "INT", "NULLABLE", 0),
|
||||
Map.of("TABLE_NAME", "orders", "COLUMN_NAME", "note", "TYPE_NAME", "VARCHAR", "NULLABLE", 1,
|
||||
"COLUMN_DEF", "'none'", "REMARKS", "free text"))) : rows(List.of());
|
||||
default -> throw new SQLFeatureNotSupportedException();
|
||||
});
|
||||
return proxy(Connection.class, (p, m, a) -> switch (m.getName()) {
|
||||
@@ -55,7 +78,7 @@ public class SelfTest {
|
||||
case "createStatement" -> statement();
|
||||
case "isClosed" -> false;
|
||||
case "isValid" -> !dropped;
|
||||
case "getCatalog" -> null;
|
||||
case "getCatalog" -> "root";
|
||||
default -> throw new SQLFeatureNotSupportedException();
|
||||
});
|
||||
}
|
||||
@@ -434,9 +457,30 @@ public class SelfTest {
|
||||
var columns = new String(reply(in), StandardCharsets.UTF_8);
|
||||
assert columns.contains("orders") && columns.contains("note") && columns.contains("'none'") : columns;
|
||||
assert columns.contains("comment") && columns.contains("free text") : columns;
|
||||
send(out, 10, "tables", "app");
|
||||
send(out, 10, "catalogs");
|
||||
var catalogs = reply(in);
|
||||
assert catalogs[0] == 1 : new String(catalogs, StandardCharsets.UTF_8);
|
||||
var catalogRows = new String(catalogs, StandardCharsets.UTF_8);
|
||||
assert catalogRows.contains("archive.db:1") && catalogRows.contains("root") : catalogRows;
|
||||
send(out, 11, "schemas", "archive.db:1");
|
||||
var scoped = new String(reply(in), StandardCharsets.UTF_8);
|
||||
assert scoped.contains("qa_%") && !scoped.contains("outside_catalog") : scoped;
|
||||
send(out, 12, "tables", "qa_%", "archive.db:1");
|
||||
var tables = new String(reply(in), StandardCharsets.UTF_8);
|
||||
assert tables.contains("orders") && tables.contains("Orders table") : tables;
|
||||
assert tables.contains("items") && tables.contains("Archived items")
|
||||
&& !tables.contains("outside_catalog") && !tables.contains("outside_schema")
|
||||
&& !tables.contains("Wrong catalog comment") && !tables.contains("Wrong schema comment") : tables;
|
||||
send(out, 13, "schemas");
|
||||
var unscoped = new String(reply(in), StandardCharsets.UTF_8);
|
||||
assert unscoped.contains("app") && !unscoped.contains("qa_%") : unscoped;
|
||||
send(out, 14, "tables", "app");
|
||||
var genericTables = new String(reply(in), StandardCharsets.UTF_8);
|
||||
assert genericTables.contains("orders") && genericTables.contains("Orders table")
|
||||
&& !genericTables.contains("items") : genericTables;
|
||||
send(out, 15, "schemaColumns", "qa_%", "archive.db:1");
|
||||
var scopedComments = new String(reply(in), StandardCharsets.UTF_8);
|
||||
assert scopedComments.contains("comment") && scopedComments.contains("archive label")
|
||||
&& !scopedComments.contains("outside label") : scopedComments;
|
||||
} finally {
|
||||
child.destroyForcibly().waitFor();
|
||||
}
|
||||
|
||||
Reference in new issue
Заблокувати користувача