fix(mysql): use database-specific catalog switching

This commit is contained in:
jischeng authored and GitHub committed 2026-07-29 20:41:09 +08:00
1 parent 9571519179
commit 2152f8cde8
31 files changed
+818 -182

No files matched your search

+45 -1
View File
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { buildSelectAllSql, isNewQueryPrefillSupported, resolveNewQueryInitialSql, resolveNewQueryTable, type ResolveNewQueryTableInput } from "@/lib/sql/newQueryContext";
import { buildSelectAllSql, isNewQueryPrefillSupported, resolveNewQueryInitialSql, resolveNewQueryTable, resolveNewQueryTarget } from "@/lib/sql/newQueryContext";
import type { ResolveNewQueryTableInput } from "@/lib/sql/newQueryContext";
import type { QueryTab, TreeNode } from "@/types/database";
function dataTab(overrides: Partial<Pick<QueryTab, "mode" | "connectionId" | "database" | "schema" | "tableMeta" | "structureTableName" | "title">> = {}): ResolveNewQueryTableInput["activeTab"] {
@@ -18,6 +19,46 @@ function tableNode(overrides: Partial<Pick<TreeNode, "type" | "connectionId" | "
return { type: "table", connectionId: "conn-1", database: "app_db", schema: "public", tableName: "orders", label: "orders", ...overrides };
}
describe("resolveNewQueryTarget", () => {
it("inherits an external catalog from the active object browser", () => {
expect(
resolveNewQueryTarget({
activeTab: {
connectionId: "conn-1",
database: "bi",
objectBrowser: { catalog: "paimon_catalog" },
},
connections: [{ id: "conn-1", database: "" }],
preferredSource: "tab",
}),
).toEqual({
connectionId: "conn-1",
database: "bi",
schema: undefined,
catalog: "paimon_catalog",
shouldRefreshDefaultDatabase: false,
});
});
it("inherits an external catalog from active table metadata", () => {
expect(
resolveNewQueryTarget({
activeTab: {
connectionId: "conn-1",
database: "bi",
tableMeta: {
catalog: "paimon_catalog",
tableName: "events",
columns: [],
primaryKeys: [],
},
},
connections: [{ id: "conn-1", database: "" }],
})?.catalog,
).toBe("paimon_catalog");
});
});
describe("resolveNewQueryTable", () => {
it("resolves the table from an active data tab", () => {
const table = resolveNewQueryTable({ activeTab: dataTab(), preferredSource: "tab" });
@@ -119,6 +160,9 @@ describe("buildSelectAllSql", () => {
expect(buildSelectAllSql("mysql", { tableName: "a`b" })).toBe("SELECT * FROM `a``b`");
expect(buildSelectAllSql("postgres", { tableName: 'a"b' })).toBe('SELECT * FROM "a""b"');
});
it("qualifies a StarRocks external-catalog table with catalog and database", () => {
expect(buildSelectAllSql("starrocks", { catalog: "paimon_catalog", database: "bi", tableName: "events" })).toBe("SELECT * FROM `paimon_catalog`.`bi`.`events`");
});
});
describe("isNewQueryPrefillSupported", () => {