Fix:修复逗号分隔多表语句的别名补全#3441
Conversation
t8y2
left a comment
There was a problem hiding this comment.
Request changes: the comma-separated FROM parser still stops on valid row-source syntax.
-
FROM table_a a(id), table_b bleaves the alias column list unconsumed, so the loop never reachestable_b; the same issue drops later tables in longer chains. -
Generic PostgreSQL table functions and
LATERALsources are parsed as ordinary table names because function-source detection only recognizes a fixed allowlist. For example,generate_series(...) gandLATERAL generate_series(...) gdo not exposegfor column completion.
Please make the parser consume a complete row source—including correlation column lists, generic function calls, and optional LATERAL—before looking for the next comma, and add regression tests for these cases.
|
已按评审意见完成修改,提交:
验证结果:
|
t8y2
left a comment
There was a problem hiding this comment.
request changes: 上次提到的基础 case 已经修复,但“完整消费当前行源后再处理逗号”仍有两个合法语法缺口。
-
PostgreSQL 表函数的
WITH ORDINALITY会被aliasAfter当成别名with。例如generate_series(...) WITH ORDINALITY AS g(value, ord), orders o无法得到g,也不会继续解析orders。请完整消费可选的WITH ORDINALITY后再解析别名和 correlation columns。 -
JOIN 后的逗号表源仍会丢失。例如
FROM users u JOIN orders o ON ..., audit_log a只记录users和orders,不会记录audit_log。逗号分隔的是完整 table references,其中一个 reference 可以是 joined table;这里需要在完整 joined-table 边界之后继续处理同层逗号。
请补充这两个场景的模型与补全回归测试。
|
已按本轮评审意见完成修改,提交:
验证结果:
|
t8y2
left a comment
There was a problem hiding this comment.
Thanks for the update. The previously reported WITH ORDINALITY and joined-table cases are fixed, but three compatibility issues remain.
-
apps/desktop/src/lib/sql/semantic/model.tstreats every parenthesized token list after a table alias as correlation columns. In SQL Server,FROM users u (NOLOCK)is valid table-hint syntax, but the semantic model recordsNOLOCKas the table's only column and skips loading the real metadata. Please distinguish aliased SQL Server table hints and add a regression test. -
A partial PostgreSQL column alias list is treated as the complete source schema. For
FROM users u(id), PostgreSQL only renames the first column; the remaining columns keep their original names. The current model prevents metadata loading, so all remaining columns disappear from completion. Please merge correlation names positionally with the underlying metadata and cover this through the completion path. -
LATERALis consumed in every dialect. SQL Server permits an unquoted table namedlateral, soFROM lateral lis currently parsed as a table namedlwith no alias. Please gateLATERALhandling by dialect and valid syntactic context.
|
已按本轮评审意见完成修改,提交:
验证结果:
@t8y2 本轮意见已处理完,烦请继续评审。 |
2521972 to
5105557
Compare
|
Thanks for the contribution! Merged in 1ab93a6, will be released in the next version. |
背景
SQL 语义模型此前对逗号分隔的多表语法只记录
FROM后的第一张表,并且没有完整消费表引用的可选后缀或 joined-table 边界,导致后续表别名无法参与字段补全。根因
parseRowSources最初只解析每个FROM/JOIN引导词后紧邻的一个行源。后续增加同层逗号遍历后,仍存在以下不完整边界:LATERAL没有统一进入函数行源解析WITH ORDINALITY会被当成普通别名JOIN ... ON ...后的同层逗号不再紧邻单个行源,无法由原循环继续解析改动
a(id)、g(value)可直接提供本地字段补全LATERALWITH ORDINALITYFROM子句范围内识别同层逗号,使完整 joined table 后的后续表也能进入语义模型LATERAL、WITH ORDINALITY和 joined-table 后逗号安全性
INSERT INTO、UPDATE、DELETE FROM的写入目标,避免把插入列清单误判成函数调用FROM users (NOLOCK)回归测试,避免表提示被误判为通用函数FROM子句WINDOW、QUALIFY、FETCH等后置子句边界,避免后续子句中的逗号产生伪表源验证
pnpm exec vitest run apps/desktop/src/lib/__tests__/sql/semantic/model.spec.ts apps/desktop/src/lib/__tests__/sql/semantic/completion.spec.ts:49/49 通过pnpm check:format、lint、typecheck、test 全部通过