9 files changed
+167
-2
No files matched your search
@@ -100,4 +100,19 @@ describe("completionTreeIndex", () => {
|
||||
expect(completionTablesFromTree(tree, "doris", "sales")).toEqual([{ name: "orders", schema: undefined, type: "table" }]);
|
||||
expect(completionTablesFromTree(tree, "doris", "sales", undefined, "hive_catalog")).toEqual([{ name: "orders", catalog: "hive_catalog", schema: undefined, type: "table" }]);
|
||||
});
|
||||
|
||||
it("preserves TDengine stable metadata from the sidebar tree", () => {
|
||||
const tree: TreeNode[] = [
|
||||
{
|
||||
id: "tdengine-stable",
|
||||
label: "test_tb",
|
||||
type: "table",
|
||||
tableType: "STABLE",
|
||||
connectionId: "tdengine",
|
||||
database: "issue_5685",
|
||||
},
|
||||
];
|
||||
|
||||
expect(completionTablesFromTree(tree, "tdengine", "issue_5685")).toEqual([{ name: "test_tb", schema: undefined, type: "table", tableType: "STABLE" }]);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { TreeNode } from "@/types/database";
|
||||
import type { SqlCompletionTable } from "@/lib/sql/sqlCompletion";
|
||||
import { isTdengineStableTableType } from "@/lib/table/tableEditing";
|
||||
|
||||
const TABLE_NODE_TYPES = new Set(["table", "view", "materialized_view"]);
|
||||
|
||||
@@ -31,6 +32,7 @@ export function completionTablesFromTree(nodes: readonly TreeNode[], connectionI
|
||||
catalog: node.catalog,
|
||||
schema: node.schema,
|
||||
type: node.type === "materialized_view" ? "materialized_view" : node.type === "view" ? "view" : "table",
|
||||
...(isTdengineStableTableType(node.tableType) ? { tableType: node.tableType } : {}),
|
||||
});
|
||||
});
|
||||
return dedupeCompletionTables(tables);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { SqlCompletionColumn, SqlCompletionTable } from "@/lib/sql/sqlCompletion";
|
||||
import { getSqlCompletionContext, isOracleSystemValueName } from "@/lib/sql/sqlCompletion";
|
||||
import { executableStatementRanges, isOraclePlSqlStatement, type SqlTextRange } from "@/lib/sql/sqlStatementRanges";
|
||||
import { DBX_TDENGINE_TBNAME_COLUMN, isTdengineStableTableType } from "@/lib/table/tableEditing";
|
||||
import type { DatabaseType, SqlColumnReference, SqlReferenceAnalysis, SqlReferenceScope, SqlTableReference, SqlTextSpan } from "@/types/database";
|
||||
|
||||
export interface SqlSemanticDiagnostic {
|
||||
@@ -45,6 +46,7 @@ export function buildSqlSemanticDiagnostics(analysis: SqlReferenceAnalysis, sche
|
||||
const tables = analysis.tables.filter((table) => table.name.trim());
|
||||
const knownTables = new Map<string, SqlTableReference>();
|
||||
const scopesById = scopesByIdMap(analysis.scopes);
|
||||
let tdengineStableTables: Set<string> | undefined;
|
||||
|
||||
for (const table of tables) {
|
||||
knownTables.set(normalizeName(table.name), table);
|
||||
@@ -73,6 +75,10 @@ export function buildSqlSemanticDiagnostics(analysis: SqlReferenceAnalysis, sche
|
||||
|
||||
const columnNames = new Set(columns.map((item) => normalizeName(item.name)));
|
||||
if (columnNames.has(normalizeName(column.name))) continue;
|
||||
if (schema.databaseType === "tdengine" && normalizeName(column.name) === DBX_TDENGINE_TBNAME_COLUMN) {
|
||||
tdengineStableTables ??= tdengineStableTableKeys(schema.tables);
|
||||
if (tdengineStableTables.has(tableReferenceKey(table))) continue;
|
||||
}
|
||||
|
||||
const displayName = column.qualifier ? `${column.qualifier}.${column.name}` : column.name;
|
||||
diagnostics.push({
|
||||
@@ -85,6 +91,20 @@ export function buildSqlSemanticDiagnostics(analysis: SqlReferenceAnalysis, sche
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
function tdengineStableTableKeys(tables: readonly SqlCompletionTable[]): Set<string> {
|
||||
const keys = new Set<string>();
|
||||
for (const table of tables) {
|
||||
if (!isTdengineStableTableType(table.tableType)) continue;
|
||||
keys.add(completionTableReferenceKey(table));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
function completionTableReferenceKey(table: Pick<SqlCompletionTable, "name" | "database" | "schema">): string {
|
||||
if (table.schema) return normalizeName(`${table.database ? `${table.database}.` : ""}${table.schema}.${table.name}`);
|
||||
return normalizeName(table.name);
|
||||
}
|
||||
|
||||
function isUnquotedOracleSystemValueReference(column: SqlColumnReference, schema: SqlSemanticDiagnosticSchema): boolean {
|
||||
if (column.qualifier || !isOracleSystemValueName(column.name, schema.databaseType)) return false;
|
||||
if (!schema.sql) return false;
|
||||
|
||||
@@ -1160,6 +1160,7 @@ export interface SqlCompletionTable {
|
||||
database?: string;
|
||||
schema?: string;
|
||||
type?: SqlObjectNavigationType;
|
||||
tableType?: string;
|
||||
detail?: string;
|
||||
applyName?: string;
|
||||
boost?: number;
|
||||
|
||||
@@ -9,7 +9,7 @@ function isViewTableType(tableType?: string): boolean {
|
||||
return tableType?.toUpperCase().includes("VIEW") === true;
|
||||
}
|
||||
|
||||
function isTdengineStableTableType(tableType?: string): boolean {
|
||||
export function isTdengineStableTableType(tableType?: string): boolean {
|
||||
const normalized = tableType?.trim().toUpperCase();
|
||||
return normalized === "STABLE" || normalized === "SUPER TABLE" || normalized === "SUPERTABLE";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user