fix(oceanbase-oracle): complete tables across schemas

This commit is contained in:
Mo-Moore authored and GitHub committed 2026-09-24 16:16:18 +08:00
1 parent 53184faf87
commit a73bc4df69
10 files changed
+574 -22

No files matched your search

@@ -1,7 +1,12 @@
import type { DatabaseType } from "@/types/database";
/** Native Oracle and OceanBase Oracle share multi-schema completion semantics. */
export function isOracleCompletionDatabase(databaseType?: DatabaseType): boolean {
return databaseType === "oracle" || databaseType === "oceanbase-oracle";
}
export function usesOracleCurrentSchemaCompletion(databaseType?: DatabaseType, schema?: string | null): boolean {
return (databaseType === "oracle" || databaseType === "oceanbase-oracle") && !schema;
return isOracleCompletionDatabase(databaseType) && !schema;
}
export function usesOracleSessionCompletionColumns(options: { databaseType?: DatabaseType; selectedSchema?: string; referenceSchema?: string | null; clientSessionId?: string }): boolean {
+8 -7
View File
@@ -20,6 +20,7 @@ import { quoteTableIdentifier, quoteTableIdentifierIfNeeded } from "@/lib/table/
import { driverProfileCompletionObjects, driverProfileCompletionTableMetadata, driverProfileCompletionTables, driverProfileRoutineSignatures } from "@/lib/database/driverProfileExtensions";
import { DORIS_FUNCTION_DOCS, DORIS_FUNCTION_SIGNATURES } from "@/lib/sql/doris/functions";
import { rejectsAliasReferenceInHaving } from "@/lib/database/databaseFeatureSupport";
import { isOracleCompletionDatabase } from "@/lib/sql/oracleCompletionSession";
export { DEFAULT_SQL_SNIPPETS, resolveSqlSnippetBodyForDatabase } from "@/lib/sql/sqlSnippetTemplates";
@@ -3907,10 +3908,10 @@ function resolveTableSchemaQualification(
currentSchema: string | undefined,
schemasByTableName: Map<string, Set<string>>,
): { ambiguousTableName: boolean; schemaQualification: boolean; defaultApplyName: string } {
const oracleSchemaQualification = databaseType === "oracle" && table.schema && table.schema.toUpperCase() !== "PUBLIC" && (!currentSchema || normalizeIdentifierPart(table.schema) !== normalizeIdentifierPart(currentSchema));
const oracleSchemaQualification = isOracleCompletionDatabase(databaseType) && table.schema && table.schema.toUpperCase() !== "PUBLIC" && (!currentSchema || normalizeIdentifierPart(table.schema) !== normalizeIdentifierPart(currentSchema));
// A bare table name is ambiguous when metadata contains the same name in multiple schemas.
// Keep Oracle's current-schema behavior, but qualify the generic/PostgreSQL/SQL Server paths.
const ambiguousTableName = databaseType !== "oracle" && (schemasByTableName.get(normalizeIdentifierPart(table.name))?.size ?? 0) > 1;
const ambiguousTableName = !isOracleCompletionDatabase(databaseType) && (schemasByTableName.get(normalizeIdentifierPart(table.name))?.size ?? 0) > 1;
const schemaQualification = !!table.schema && (oracleSchemaQualification || ambiguousTableName);
const defaultApplyName = schemaQualification ? `${quoteCompletionApplyIdentifier(table.schema!, dialect)}.${quoteCompletionApplyIdentifier(table.name, dialect)}` : quoteCompletionApplyIdentifier(table.name, dialect);
return { ambiguousTableName, schemaQualification, defaultApplyName };
@@ -3948,7 +3949,7 @@ function buildTableItems(
detail,
apply: formatTableAliasApply(applyName, alias),
boost: computeBoost(table.name, prefix) + 1000 + (table.boost ?? 0),
dedupeKey: table.applyName || ambiguousTableName || (databaseType === "oracle" && table.schema) ? applyName : undefined,
dedupeKey: table.applyName || ambiguousTableName || (isOracleCompletionDatabase(databaseType) && table.schema) ? applyName : undefined,
};
})
.sort(compareCompletionItems)
@@ -4004,7 +4005,7 @@ function buildForeignKeyRelatedTableItems(
boost: computeBoost(table.name, context.prefix) + 3600,
// Mirror buildTableItems' dedupeKey so an FK candidate and the regular
// candidate for the same schema-qualified table collapse to one entry.
dedupeKey: ambiguousTableName || (databaseType === "oracle" && table.schema) ? applyName : undefined,
dedupeKey: ambiguousTableName || (isOracleCompletionDatabase(databaseType) && table.schema) ? applyName : undefined,
};
})
.sort(compareCompletionItems);
@@ -4044,7 +4045,7 @@ function buildObjectItems(context: SqlCompletionContext, objects: SqlCompletionO
if (completionQualifierIsReferencedTable(context)) return [];
const onlyProcedures = context.contextKind === "exec";
const onlyFunctions = context.suggestColumns && context.referencedTables.length > 0 && !context.qualifier;
const prioritizeOracleFunctions = databaseType === "oracle" && context.statementKind === "select";
const prioritizeOracleFunctions = isOracleCompletionDatabase(databaseType) && context.statementKind === "select";
return objects
.filter((object) => object.type !== "sequence" && (!onlyProcedures || object.type === "procedure") && (!onlyFunctions || (object.type === "function" && object.name.toLowerCase().startsWith(context.prefix.toLowerCase()))) && objectMatchesCompletionContext(object, context))
.map((object) => {
@@ -4060,7 +4061,7 @@ function buildObjectItems(context: SqlCompletionContext, objects: SqlCompletionO
const detail = [locationDetail, signature ? `(${signature})` : undefined, object.dataType ? `[${object.dataType}]` : undefined].filter(Boolean).join(" ");
const schemaBoost = onlyFunctions ? Math.min(object.boost ?? 0, 1000) : (object.boost ?? 0);
const typeBoost = routineTypeBoost(object.type, prioritizeOracleFunctions && !onlyFunctions);
const baseDedupeKey = object.applyName || (databaseType === "oracle" && object.schema) ? applyName : undefined;
const baseDedupeKey = object.applyName || (isOracleCompletionDatabase(databaseType) && object.schema) ? applyName : undefined;
return {
label: object.name,
type: "function" as const,
@@ -5470,7 +5471,7 @@ function activeSqlKeywords(databaseType?: DatabaseType): string[] {
}
function isOracleLikeDatabase(databaseType?: DatabaseType): boolean {
return databaseType === "oracle" || databaseType === "oceanbase-oracle";
return isOracleCompletionDatabase(databaseType);
}
// CQL has no table alias syntax, so Cassandra must never receive `table alias`