feat(doris): show external catalogs in sidebar
This commit is contained in:
1 parent
47d9257ac2
commit
d9bb92d1e9
36 files changed
+1680
-174
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { connectionIsDorisFamilyCatalogCapable, isDorisFamilyCatalogCapable, isInternalDorisCatalog } from "@/lib/database/databaseFeatureSupport";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
function conn(db_type: ConnectionConfig["db_type"], driver_profile?: string | null): Pick<ConnectionConfig, "db_type" | "driver_profile"> {
|
||||
return { db_type, driver_profile: driver_profile ?? null };
|
||||
}
|
||||
|
||||
describe("isDorisFamilyCatalogCapable", () => {
|
||||
it("matches Doris and StarRocks by db_type", () => {
|
||||
expect(isDorisFamilyCatalogCapable("doris")).toBe(true);
|
||||
expect(isDorisFamilyCatalogCapable("starrocks")).toBe(true);
|
||||
});
|
||||
|
||||
it("matches Doris / SelectDB / StarRocks driver profiles", () => {
|
||||
expect(isDorisFamilyCatalogCapable("mysql", "doris")).toBe(true);
|
||||
expect(isDorisFamilyCatalogCapable("mysql", "selectdb")).toBe(true);
|
||||
expect(isDorisFamilyCatalogCapable("mysql", "starrocks")).toBe(true);
|
||||
});
|
||||
|
||||
it("excludes ManticoreSearch (no catalog concept)", () => {
|
||||
expect(isDorisFamilyCatalogCapable("manticoresearch")).toBe(false);
|
||||
expect(isDorisFamilyCatalogCapable("mysql", "manticoresearch")).toBe(false);
|
||||
});
|
||||
|
||||
it("excludes plain MySQL / Postgres", () => {
|
||||
expect(isDorisFamilyCatalogCapable("mysql")).toBe(false);
|
||||
expect(isDorisFamilyCatalogCapable("postgres")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("connectionIsDorisFamilyCatalogCapable", () => {
|
||||
it("returns false for undefined connection", () => {
|
||||
expect(connectionIsDorisFamilyCatalogCapable(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true for a Doris connection", () => {
|
||||
expect(connectionIsDorisFamilyCatalogCapable(conn("doris"))).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for a plain MySQL connection", () => {
|
||||
expect(connectionIsDorisFamilyCatalogCapable(conn("mysql"))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isInternalDorisCatalog", () => {
|
||||
it("detects Doris internal catalog by type", () => {
|
||||
expect(isInternalDorisCatalog("internal", "internal")).toBe(true);
|
||||
});
|
||||
|
||||
it("detects StarRocks internal catalog by type (case-insensitive)", () => {
|
||||
expect(isInternalDorisCatalog("Internal", "default_catalog")).toBe(true);
|
||||
expect(isInternalDorisCatalog("INTERNAL", "default_catalog")).toBe(true);
|
||||
});
|
||||
|
||||
it("treats external catalogs as non-internal", () => {
|
||||
expect(isInternalDorisCatalog("iceberg", "iceberg_catalog")).toBe(false);
|
||||
expect(isInternalDorisCatalog("hive", "hive_catalog")).toBe(false);
|
||||
// A catalog literally named `internal` but with an external type is not built-in.
|
||||
expect(isInternalDorisCatalog("iceberg", "internal")).toBe(false);
|
||||
});
|
||||
|
||||
it("falls back to the Doris name when the type is absent", () => {
|
||||
expect(isInternalDorisCatalog("", "internal")).toBe(true);
|
||||
expect(isInternalDorisCatalog(null, "internal")).toBe(true);
|
||||
expect(isInternalDorisCatalog("", "default_catalog")).toBe(false);
|
||||
expect(isInternalDorisCatalog(undefined, undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { qualifiedTableName, quoteTableIdentifier } from "@/lib/table/tableSelectSql";
|
||||
|
||||
describe("qualifiedTableName — Doris/StarRocks multi-catalog", () => {
|
||||
it("prefixes external catalog for Doris (no schema)", () => {
|
||||
expect(qualifiedTableName({ databaseType: "doris", catalog: "iceberg_catalog", tableName: "orders" })).toBe("`iceberg_catalog`.`orders`");
|
||||
});
|
||||
|
||||
it("prefixes external catalog for Doris (with schema)", () => {
|
||||
expect(qualifiedTableName({ databaseType: "doris", catalog: "iceberg_catalog", schema: "sales", tableName: "orders" })).toBe("`iceberg_catalog`.`sales`.`orders`");
|
||||
});
|
||||
|
||||
it("prefixes external catalog for StarRocks", () => {
|
||||
expect(qualifiedTableName({ databaseType: "starrocks", catalog: "hive_catalog", tableName: "orders" })).toBe("`hive_catalog`.`orders`");
|
||||
});
|
||||
|
||||
it("treats the internal catalog as no catalog", () => {
|
||||
expect(qualifiedTableName({ databaseType: "doris", catalog: "internal", tableName: "orders" })).toBe("`orders`");
|
||||
});
|
||||
|
||||
it("omits the catalog for non-Doris engines", () => {
|
||||
// MySQL has no 3-part catalog naming; the catalog must be ignored.
|
||||
expect(qualifiedTableName({ databaseType: "mysql", catalog: "iceberg_catalog", tableName: "orders" })).toBe("`orders`");
|
||||
});
|
||||
|
||||
it("escapes embedded backticks in catalog and table identifiers", () => {
|
||||
expect(qualifiedTableName({ databaseType: "doris", catalog: "a`b", schema: "c`d", tableName: "e`f" })).toBe("`a``b`.`c``d`.`e``f`");
|
||||
});
|
||||
});
|
||||
|
||||
describe("quoteTableIdentifier", () => {
|
||||
it("backtick-quotes mysql identifiers", () => {
|
||||
expect(quoteTableIdentifier("mysql", "orders")).toBe("`orders`");
|
||||
});
|
||||
|
||||
it("bracket-quotes sqlserver identifiers", () => {
|
||||
expect(quoteTableIdentifier("sqlserver", "orders")).toBe("[orders]");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user