fix(mysql): use database-specific catalog switching
This commit is contained in:
1 parent
9571519179
commit
2152f8cde8
31 files changed
+818
-182
No files matched your search
@@ -338,6 +338,16 @@ describe("queryStore multi-statement errors", () => {
|
||||
|
||||
expect(mocks.executeMulti).toHaveBeenCalledWith("mysql-1", "app", "SELECT 1", undefined, expect.any(String), expect.objectContaining({ continueOnError: false }));
|
||||
});
|
||||
it("passes the selected external catalog to query execution", async () => {
|
||||
mocks.executeMulti.mockResolvedValue([{ columns: ["value"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 }]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("mysql-1", "bi", "Query", "query", undefined, undefined, "paimon_catalog");
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT * FROM events");
|
||||
|
||||
expect(mocks.executeMulti).toHaveBeenCalledWith("mysql-1", "bi", "SELECT * FROM events", undefined, expect.any(String), expect.objectContaining({ catalog: "paimon_catalog" }));
|
||||
});
|
||||
|
||||
it("keeps old and new executions as result runs, then lets normal execution replace the active run", async () => {
|
||||
mocks.executeMulti
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
|
||||
describe("queryStore switchTab", () => {
|
||||
beforeEach(() => {
|
||||
@@ -74,6 +75,44 @@ describe("queryStore switchTab", () => {
|
||||
expect(settingsStore.settingsPageActive).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps same-named tabs from different catalogs distinct", async () => {
|
||||
const queryStore = useQueryStore();
|
||||
|
||||
const paimonTabId = queryStore.createTab("sr-1", "bi", "events", "query", undefined, undefined, "paimon_catalog");
|
||||
const internalTabId = queryStore.createTab("sr-1", "bi", "events", "query", undefined, undefined, "internal");
|
||||
|
||||
expect(internalTabId).not.toBe(paimonTabId);
|
||||
expect(queryStore.tabs).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("preserves catalog context when duplicating a query tab", async () => {
|
||||
const queryStore = useQueryStore();
|
||||
const tabId = queryStore.createTab("sr-1", "bi", undefined, "query", undefined, "SELECT 1", "paimon_catalog");
|
||||
|
||||
queryStore.duplicateTab(tabId);
|
||||
|
||||
expect(queryStore.tabs).toHaveLength(2);
|
||||
expect(queryStore.tabs[1].catalog).toBe("paimon_catalog");
|
||||
});
|
||||
|
||||
it("switches catalog and database as one query context", () => {
|
||||
const queryStore = useQueryStore();
|
||||
const tabId = queryStore.createTab("sr-1", "internal_db", undefined, "query");
|
||||
const tab = queryStore.tabs.find((candidate) => candidate.id === tabId)!;
|
||||
tab.result = {
|
||||
columns: ["id"],
|
||||
rows: [[1]],
|
||||
affected_rows: 0,
|
||||
execution_time_ms: 1,
|
||||
};
|
||||
|
||||
queryStore.updateCatalog(tabId, "paimon_catalog", "bi");
|
||||
|
||||
expect(tab.catalog).toBe("paimon_catalog");
|
||||
expect(tab.database).toBe("bi");
|
||||
expect(tab.result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("stores local data-grid column filters on the tab result", async () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const queryStore = useQueryStore();
|
||||
|
||||
@@ -538,10 +538,11 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const sessionId = tab?.resultSessionId ?? tab?.result?.session_id;
|
||||
if (!tab || !sessionId || sessionId === preserveSessionId) return;
|
||||
try {
|
||||
const catalog = tab.mode === "data" ? tab.tableMeta?.catalog : undefined;
|
||||
const catalog = tab.mode === "data" ? tab.tableMeta?.catalog : tab.catalog;
|
||||
const connection = catalog ? useConnectionStore().getConfig(tab.connectionId) : undefined;
|
||||
const executionDatabase = dataTabExecutionDatabase(connection, tab.database, catalog);
|
||||
await api.closeQuerySession(tab.connectionId, executionDatabase, sessionId, tab.id);
|
||||
if (catalog) await api.closeQuerySession(tab.connectionId, executionDatabase, sessionId, tab.id, catalog);
|
||||
else await api.closeQuerySession(tab.connectionId, executionDatabase, sessionId, tab.id);
|
||||
} catch (error) {
|
||||
console.warn("[DBX][query-session:close:error]", { tabId: tab.id, sessionId, error });
|
||||
if (throwOnError) throw error;
|
||||
@@ -555,9 +556,10 @@ export const useQueryStore = defineStore("query", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function closeClientSessionId(connectionId: string, database: string, clientSessionId: string, logContext: Record<string, unknown> = {}, throwOnError = false) {
|
||||
async function closeClientSessionId(connectionId: string, database: string, clientSessionId: string, catalog: string | undefined, logContext: Record<string, unknown> = {}, throwOnError = false) {
|
||||
try {
|
||||
await api.closeClientConnectionSession(connectionId, database, clientSessionId);
|
||||
if (catalog) await api.closeClientConnectionSession(connectionId, database, clientSessionId, catalog);
|
||||
else await api.closeClientConnectionSession(connectionId, database, clientSessionId);
|
||||
} catch (error) {
|
||||
console.warn("[DBX][client-session:close:error]", { ...logContext, clientSessionId, error });
|
||||
if (throwOnError) throw error;
|
||||
@@ -566,12 +568,12 @@ export const useQueryStore = defineStore("query", () => {
|
||||
|
||||
async function closeClientConnectionSession(tab: QueryTab | undefined, throwOnError = false) {
|
||||
if (!tab?.connectionId) return;
|
||||
const catalog = tab.mode === "data" ? tab.tableMeta?.catalog : undefined;
|
||||
const catalog = tab.mode === "data" ? tab.tableMeta?.catalog : tab.catalog;
|
||||
const connection = catalog ? useConnectionStore().getConfig(tab.connectionId) : undefined;
|
||||
const executionDatabase = dataTabExecutionDatabase(connection, tab.database, catalog);
|
||||
const clientSessionIds = [...new Set([tabClientSessionId(tab), ...BACKGROUND_CLIENT_SESSION_SUFFIXES.map((suffix) => tabClientSessionId(tab, suffix)), tab.explainClientSessionId].filter((sessionId): sessionId is string => !!sessionId))];
|
||||
for (const clientSessionId of clientSessionIds) {
|
||||
await closeClientSessionId(tab.connectionId, executionDatabase, clientSessionId, { tabId: tab.id }, throwOnError);
|
||||
await closeClientSessionId(tab.connectionId, executionDatabase, clientSessionId, catalog, { tabId: tab.id }, throwOnError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1153,13 +1155,13 @@ export const useQueryStore = defineStore("query", () => {
|
||||
return saveTabs(tabs.value, activeTabId.value);
|
||||
}
|
||||
|
||||
function findTabByIdentity(connectionId: string, database: string, title: string, mode: QueryTab["mode"], schema?: string) {
|
||||
return tabs.value.find((tab) => tab.connectionId === connectionId && tab.database === database && tab.title === title && tab.mode === mode && (tab.schema || "") === (schema || ""));
|
||||
function findTabByIdentity(connectionId: string, database: string, title: string, mode: QueryTab["mode"], schema?: string, catalog?: string) {
|
||||
return tabs.value.find((tab) => tab.connectionId === connectionId && tab.database === database && tab.title === title && tab.mode === mode && (tab.schema || "") === (schema || "") && (tab.catalog || "") === (catalog || ""));
|
||||
}
|
||||
|
||||
function createTab(connectionId: string, database: string, title?: string, mode: QueryTab["mode"] = "query", schema?: string, initialSql?: string, catalog?: string, options: { forceNew?: boolean } = {}) {
|
||||
if (title && !options.forceNew) {
|
||||
const existing = findTabByIdentity(connectionId, database, title, mode, schema);
|
||||
const existing = findTabByIdentity(connectionId, database, title, mode, schema, catalog);
|
||||
if (existing) {
|
||||
switchTab(existing.id);
|
||||
return existing.id;
|
||||
@@ -1937,6 +1939,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
connectionId: original.connectionId,
|
||||
database: original.database,
|
||||
schema: original.schema,
|
||||
catalog: original.catalog,
|
||||
sql: original.sql,
|
||||
originalSql: "",
|
||||
savedSqlId: undefined,
|
||||
@@ -2409,6 +2412,24 @@ export const useQueryStore = defineStore("query", () => {
|
||||
tab.tableMeta = undefined;
|
||||
}
|
||||
|
||||
function updateCatalog(id: string, catalog: string | undefined, database: string) {
|
||||
const tab = tabs.value.find((candidate) => candidate.id === id);
|
||||
if (!tab || (tab.catalog === catalog && tab.database === database)) return;
|
||||
rollbackTabTransaction(tab);
|
||||
void closeResultSession(tab);
|
||||
void closeClientConnectionSession(tab);
|
||||
tab.catalog = catalog;
|
||||
tab.database = database;
|
||||
tab.schema = undefined;
|
||||
tab.objectBrowser = undefined;
|
||||
clearResultPayload(tab);
|
||||
tab.lastExecutedSql = undefined;
|
||||
tab.resultBaseSql = undefined;
|
||||
tab.resultSortedSql = undefined;
|
||||
clearExplain(tab);
|
||||
tab.tableMeta = undefined;
|
||||
}
|
||||
|
||||
function updateSchema(id: string, schema: string | undefined) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (!tab || tab.schema === schema) return;
|
||||
@@ -2434,6 +2455,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
void closeClientConnectionSession(tab);
|
||||
tab.connectionId = connectionId;
|
||||
tab.database = database;
|
||||
tab.catalog = undefined;
|
||||
tab.objectBrowser = undefined;
|
||||
tab.schema = undefined;
|
||||
clearResultPayload(tab);
|
||||
tab.lastExecutedSql = undefined;
|
||||
@@ -2978,6 +3001,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
connectionId: string;
|
||||
database: string;
|
||||
schema?: string;
|
||||
catalog?: string;
|
||||
countSql?: string;
|
||||
countSqlTarget?: () => Promise<TotalRowCountSqlTarget | undefined>;
|
||||
result: QueryResult;
|
||||
@@ -3022,6 +3046,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
queryExecutionLog("info", "count:start", { traceId: options.traceId, elapsed: options.elapsed() });
|
||||
const countResult = await api.executeQuery(options.connectionId, options.database, countTarget.sql, countTarget.schema, countExecutionId, {
|
||||
clientSessionId,
|
||||
catalog: options.catalog,
|
||||
timeoutSecs: options.timeoutSecs,
|
||||
});
|
||||
const total = Number(countResult.rows?.[0]?.[0] ?? 0);
|
||||
@@ -3043,7 +3068,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
error,
|
||||
});
|
||||
} finally {
|
||||
void closeClientSessionId(options.connectionId, options.database, clientSessionId, { tabId: options.tabId });
|
||||
void closeClientSessionId(options.connectionId, options.database, clientSessionId, options.catalog, { tabId: options.tabId });
|
||||
}
|
||||
})();
|
||||
}
|
||||
@@ -3678,7 +3703,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
if (tab.autoCommit === false) {
|
||||
if (!tab.txnSessionId) {
|
||||
queryExecutionLog("info", "begin-manual-txn:start", { traceId, elapsed: elapsed() });
|
||||
tab.txnSessionId = await api.beginManualTransaction(tab.connectionId, executionDatabase, executionSchema);
|
||||
tab.txnSessionId = await api.beginManualTransaction(tab.connectionId, executionDatabase, executionSchema, tab.catalog);
|
||||
queryExecutionLog("info", "begin-manual-txn:done", { traceId, txnSessionId: tab.txnSessionId, elapsed: elapsed() });
|
||||
}
|
||||
queryExecutionLog("info", "execute-in-txn:invoke", { traceId, txnSessionId: tab.txnSessionId, elapsed: elapsed() });
|
||||
@@ -3704,6 +3729,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
: {}),
|
||||
...(clientSessionId ? { clientSessionId } : {}),
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
catalog: tab.catalog,
|
||||
continueOnError: settingsStore.editorSettings.continueOnErrorOnBatch,
|
||||
};
|
||||
queryExecutionLog("info", "execute-multi:invoke", {
|
||||
@@ -3839,6 +3865,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
connectionId: current.connectionId,
|
||||
database: executionDatabase,
|
||||
schema: current.schema,
|
||||
catalog: current.catalog,
|
||||
countSql,
|
||||
countSqlTarget: dataCountTarget
|
||||
? async () => ({
|
||||
@@ -4084,6 +4111,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
try {
|
||||
tableResult = await api.executeQuery(tab.connectionId, tab.database, tableSql, tab.schema, executionId, {
|
||||
clientSessionId,
|
||||
catalog: tab.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
@@ -4095,6 +4123,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
try {
|
||||
tableResult = await api.executeQuery(tab.connectionId, tab.database, tableSql, tab.schema, executionId, {
|
||||
clientSessionId,
|
||||
catalog: tab.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
});
|
||||
} catch (fallbackError: unknown) {
|
||||
@@ -4135,6 +4164,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
if (latest?.explainExecutionId === executionId) latest.explainSql = jsonBuilt.sql;
|
||||
const jsonResult = await api.executeQuery(tab.connectionId, tab.database, jsonBuilt.sql, tab.schema, executionId, {
|
||||
clientSessionId,
|
||||
catalog: tab.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
});
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
@@ -4158,7 +4188,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
current.explainExecutionId = undefined;
|
||||
}
|
||||
if (current?.explainClientSessionId === clientSessionId) current.explainClientSessionId = undefined;
|
||||
void closeClientSessionId(tab.connectionId, tab.database, clientSessionId, { tabId: tab.id, explainExecutionId: executionId });
|
||||
void closeClientSessionId(tab.connectionId, tab.database, clientSessionId, tab.catalog, { tabId: tab.id, explainExecutionId: executionId });
|
||||
}
|
||||
return { ok: true as const, sql: tab.explainSql ?? tableSql };
|
||||
}
|
||||
@@ -4238,7 +4268,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
current.explainExecutionId = undefined;
|
||||
}
|
||||
if (current?.explainClientSessionId === clientSessionId) current.explainClientSessionId = undefined;
|
||||
await closeClientSessionId(tab.connectionId, tab.database, clientSessionId, { tabId: tab.id, explainExecutionId: executionId });
|
||||
await closeClientSessionId(tab.connectionId, tab.database, clientSessionId, tab.catalog, { tabId: tab.id, explainExecutionId: executionId });
|
||||
}
|
||||
return { ok: true as const, sql: built.sql };
|
||||
}
|
||||
@@ -4257,6 +4287,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
try {
|
||||
const result = await api.executeQuery(tab.connectionId, tab.database, built.sql, tab.schema, executionId, {
|
||||
clientSessionId,
|
||||
catalog: tab.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
});
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
@@ -4276,7 +4307,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
current.isExplaining = false;
|
||||
current.explainExecutionId = undefined;
|
||||
}
|
||||
void closeClientSessionId(tab.connectionId, tab.database, clientSessionId, { tabId: tab.id });
|
||||
void closeClientSessionId(tab.connectionId, tab.database, clientSessionId, tab.catalog, { tabId: tab.id });
|
||||
}
|
||||
return { ok: true as const, sql: built.sql };
|
||||
}
|
||||
@@ -4650,6 +4681,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
maxRows: pageLimit,
|
||||
fetchSize: pageLimit,
|
||||
clientSessionId,
|
||||
catalog: tableMeta.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
});
|
||||
const result = results[0];
|
||||
@@ -4662,7 +4694,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
offset += result.rows.length;
|
||||
}
|
||||
} finally {
|
||||
void closeClientSessionId(tab.connectionId, executionDatabase, clientSessionId, { tabId: tab.id });
|
||||
void closeClientSessionId(tab.connectionId, executionDatabase, clientSessionId, tableMeta.catalog, { tabId: tab.id });
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -4722,9 +4754,10 @@ export const useQueryStore = defineStore("query", () => {
|
||||
pageSize: plan.pageLimit,
|
||||
resultSessionId: sessionId,
|
||||
clientSessionId,
|
||||
catalog: tab.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
}
|
||||
: { maxRows: plan.pageLimit, fetchSize: plan.pageLimit, clientSessionId, timeoutSecs: queryTimeoutSecs };
|
||||
: { maxRows: plan.pageLimit, fetchSize: plan.pageLimit, clientSessionId, catalog: tab.catalog, timeoutSecs: queryTimeoutSecs };
|
||||
const results = await api.executeMulti(tab.connectionId, tab.database, plan.sqlToExecute, tab.schema, exportExecutionId, executionOptions);
|
||||
const result = results[0];
|
||||
if (!result) break;
|
||||
@@ -4738,8 +4771,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
offset += result.rows.length;
|
||||
}
|
||||
} finally {
|
||||
if (sessionId) void api.closeQuerySession(tab.connectionId, tab.database, sessionId, clientSessionId);
|
||||
void closeClientSessionId(tab.connectionId, tab.database, clientSessionId, { tabId: tab.id });
|
||||
if (sessionId) void api.closeQuerySession(tab.connectionId, tab.database, sessionId, clientSessionId, tab.catalog);
|
||||
void closeClientSessionId(tab.connectionId, tab.database, clientSessionId, tab.catalog, { tabId: tab.id });
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -4929,6 +4962,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
togglePinnedTab,
|
||||
reorderTab,
|
||||
updateDatabase,
|
||||
updateCatalog,
|
||||
updateSchema,
|
||||
updateConnection,
|
||||
setTableMeta,
|
||||
|
||||
Reference in new issue
Block a user