mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-20 00:17:44 +00:00
fix(cassandra): skip table alias completions for CQL
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user