fix(doris): qualify external catalog tables

This commit is contained in:
jischeng authored and GitHub committed 2026-07-13 23:56:53 +08:00
1 parent c9c2fddfe2
commit a9ca66a829
21 files changed
+222 -44

No files matched your search

@@ -5,6 +5,7 @@ export type GridCellValue = string | number | boolean | null | unknown[] | { [ke
export interface DataGridTableMeta {
catalog?: string;
database?: string;
schema?: string;
tableName: string;
primaryKeys: string[];
@@ -81,6 +82,7 @@ export interface DataGridColumnValuesFilterConditionOptions {
export interface DataGridColumnDistinctValuesSqlOptions {
databaseType?: DatabaseType;
catalog?: string;
database?: string;
schema?: string;
tableName: string;
columnName: string;
@@ -95,6 +97,7 @@ export interface DataGridCountSqlOptions {
databaseType?: DatabaseType;
identifierQuote?: string;
catalog?: string;
database?: string;
schema?: string;
tableName: string;
whereInput?: string;
@@ -34,6 +34,16 @@ export function effectiveDatabaseTypeForConnection(connection?: JdbcDialectConne
if (!connection) return undefined;
if (connection.db_type === "gbase" && isGbase8sProfile(connection.driver_profile)) return "informix";
if (connection.db_type === "gbase") return "mysql";
// MySQL-protocol connections to Doris/StarRocks (db_type=mysql with a
// starrocks/doris driver_profile) must use the Doris/StarRocks SQL dialect so
// that multi-catalog 3-part names (`catalog.database.table`) are emitted.
// mysql and starrocks share the backtick-quoting + LIMIT dialect, so this
// only widens the catalog-aware SQL generation path without other side effects.
if (connection.db_type === "mysql") {
const profile = connection.driver_profile?.toLowerCase();
if (profile === "starrocks") return "starrocks";
if (profile === "doris" || profile === "selectdb") return "doris";
}
if (connection.db_type !== "jdbc") return connection.db_type;
return inferJdbcDialect(connection) ?? "jdbc";
}
@@ -13,6 +13,7 @@ export interface TableMetadata {
tableName: string;
tableType?: string;
catalog?: string;
database?: string;
columns: ColumnInfo[];
indexes: IndexInfo[];
primaryKeys: string[];
@@ -72,6 +73,7 @@ export function tableMetadataToDataTabMeta(metadata: TableMetadata, schema = met
tableName: metadata.tableName,
tableType: metadata.tableType,
catalog: metadata.catalog,
database: metadata.database,
columns: metadata.columns,
primaryKeys: metadata.primaryKeys,
};
@@ -104,6 +106,7 @@ export async function loadTableMetadata(request: TableMetadataRequest): Promise<
tableName: request.tableName,
tableType: request.tableType,
catalog: request.catalog,
database: request.database,
columns,
indexes,
primaryKeys,
+5 -3
View File
@@ -6,14 +6,15 @@ export interface NewQueryTarget {
connectionId: string;
database: string;
schema?: string;
catalog?: string;
shouldRefreshDefaultDatabase: boolean;
}
export type NewQueryContextSource = "tab" | "sidebar";
interface ResolveNewQueryTargetInput {
activeTab?: Pick<QueryTab, "connectionId" | "database" | "schema">;
selectedTreeNode?: Pick<TreeNode, "connectionId" | "database" | "schema"> | null;
activeTab?: Pick<QueryTab, "connectionId" | "database" | "schema" | "catalog">;
selectedTreeNode?: Pick<TreeNode, "connectionId" | "database" | "schema" | "catalog"> | null;
activeConnectionId?: string | null;
connections: Pick<ConnectionConfig, "id" | "database">[];
preferredSource?: NewQueryContextSource;
@@ -48,7 +49,7 @@ export function resolveNewQueryTarget(input: ResolveNewQueryTargetInput): NewQue
: null;
}
function targetFromContext(context: Pick<QueryTab | TreeNode, "connectionId" | "database" | "schema"> | undefined, connections: Pick<ConnectionConfig, "id" | "database">[]): NewQueryTarget | null {
function targetFromContext(context: Pick<QueryTab | TreeNode, "connectionId" | "database" | "schema" | "catalog"> | undefined, connections: Pick<ConnectionConfig, "id" | "database">[]): NewQueryTarget | null {
if (!context?.connectionId) return null;
const connection = connections.find((item) => item.id === context.connectionId);
if (!connection) return null;
@@ -57,6 +58,7 @@ function targetFromContext(context: Pick<QueryTab | TreeNode, "connectionId" | "
connectionId: context.connectionId,
database,
schema: "schema" in context ? (context as { schema?: string }).schema : undefined,
catalog: "catalog" in context ? (context as { catalog?: string }).catalog : undefined,
shouldRefreshDefaultDatabase: !context.database,
};
}
+9 -5
View File
@@ -18,6 +18,7 @@ export interface BuildTableSelectSqlOptions {
whereInput?: string;
includeRowId?: boolean;
catalog?: string;
database?: string;
}
export function quoteTableIdentifier(databaseType: DatabaseType | undefined, name: string): string {
@@ -45,16 +46,19 @@ function quoteCypherIdentifier(name: string): string {
return `\`${name.replace(/`/g, "``")}\``;
}
export function qualifiedTableName(options: Pick<BuildTableSelectSqlOptions, "databaseType" | "schema" | "tableName" | "catalog">): string {
const { databaseType, schema, tableName, catalog } = options;
export function qualifiedTableName(options: Pick<BuildTableSelectSqlOptions, "databaseType" | "schema" | "tableName" | "catalog" | "database">): string {
const { databaseType, schema, tableName, catalog, database } = options;
// Doris / StarRocks multi-catalog: address external-catalog tables with the
// 3-part `catalog.database.table` form, which the engines accept directly.
if (catalog && catalog !== "internal" && (databaseType === "doris" || databaseType === "starrocks")) {
const quotedCatalog = quoteTableIdentifier(databaseType, catalog);
const quotedTable = quoteTableIdentifier(databaseType, tableName);
const trimmedSchema = schema?.trim();
if (trimmedSchema) {
return `${quotedCatalog}.${quoteTableIdentifier(databaseType, trimmedSchema)}.${quotedTable}`;
// Doris/StarRocks have no separate schema concept; the database under the
// external catalog is the middle segment. Prefer schema when a caller
// passes it that way, otherwise fall back to database.
const middle = schema?.trim() || database?.trim();
if (middle) {
return `${quotedCatalog}.${quoteTableIdentifier(databaseType, middle)}.${quotedTable}`;
}
return `${quotedCatalog}.${quotedTable}`;
}