fix(cassandra): skip table alias completions for CQL

This commit is contained in:
thanhthai3010
2026-09-15 14:42:46 +08:00
committed by GitHub
parent 20e026eea9
commit 715d834c32
2 changed files with 34 additions and 3 deletions
@@ -581,6 +581,30 @@ describe("sqlCompletion table aliases", () => {
expect(table?.apply).toBe("order_items oi");
});
it("never adds generated aliases to Cassandra table completions", () => {
const sql = "SELECT * FROM ord";
const items = buildSqlCompletionItems(sql, sql.length, {
tables: [{ name: "order_items", type: "table" }],
columnsByTable: new Map(),
databaseType: "cassandra",
autoAliasTables: true,
});
const table = items.find((item) => item.label === "order_items" && item.type === "table");
expect(table?.apply).toBe("order_items");
});
it("does not suggest table aliases for Cassandra", () => {
const sql = "SELECT * FROM order_items ";
const items = buildSqlCompletionItems(sql, sql.length, {
tables: [{ name: "order_items", type: "table" }],
columnsByTable: new Map(),
databaseType: "cassandra",
});
expect(items.some((item) => item.type === "snippet" && item.detail === "alias for order_items")).toBe(false);
});
it("keeps plain table completions when generated aliases are disabled", () => {
const sql = "SELECT * FROM ord";
const items = buildSqlCompletionItems(sql, sql.length, {
+10 -3
View File
@@ -1622,13 +1622,14 @@ class SqlCompletionProvider {
}
const emptyTableNameCompletion = !context.prefix && (context.suggestTables || context.exclusiveTableSuggestions);
if (!pendingJoinKeyword && !emptyTableNameCompletion && !context.tableAliasAfterCursor && context.referencedTables.length > 0 && !context.suggestColumns && !context.insertTable) {
if (!pendingJoinKeyword && !emptyTableNameCompletion && !context.tableAliasAfterCursor && context.referencedTables.length > 0 && !context.suggestColumns && !context.insertTable && supportsTableAliases(this.databaseType)) {
this.items.push(...buildAliasItems(context, this.databaseType, this.input.keywordCase));
}
if (!context.exclusiveColumnSuggestions && context.suggestTables) {
this.items.push(...buildForeignKeyRelatedTableItems(context, completionTables, this.input.foreignKeysByTable, this.dialect, !!this.input.autoAliasTables && context.autoAliasTableCompletions, this.databaseType, this.input.keywordCase, this.input.currentSchema));
this.items.push(...buildTableItems(context, completionTables, this.dialect, !!this.input.autoAliasTables && context.autoAliasTableCompletions, context.referencedTables, this.databaseType, this.input.currentSchema, this.input.keywordCase));
const autoAliasTables = !!this.input.autoAliasTables && context.autoAliasTableCompletions && supportsTableAliases(this.databaseType);
this.items.push(...buildForeignKeyRelatedTableItems(context, completionTables, this.input.foreignKeysByTable, this.dialect, autoAliasTables, this.databaseType, this.input.keywordCase, this.input.currentSchema));
this.items.push(...buildTableItems(context, completionTables, this.dialect, autoAliasTables, context.referencedTables, this.databaseType, this.input.currentSchema, this.input.keywordCase));
if (this.databaseType === "clickhouse") {
this.items.push(...buildClickHouseFunctionItems(context.prefix, context.openingParenAfterCursor, "table"));
}
@@ -5239,6 +5240,12 @@ function isOracleLikeDatabase(databaseType?: DatabaseType): boolean {
return databaseType === "oracle" || databaseType === "oceanbase-oracle";
}
// CQL has no table alias syntax, so Cassandra must never receive `table AS alias`
// or standalone alias suggestions.
function supportsTableAliases(databaseType?: DatabaseType): boolean {
return databaseType !== "cassandra";
}
function buildJoinModifierKeywordItems(prefix: string, keywordCase?: SqlKeywordCase): SqlCompletionItem[] {
if (!prefix) return [];
return JOIN_MODIFIER_KEYWORD_PHRASES.filter((keyword) => matchesPrefix(keyword, prefix)).map((keyword) => {