Repository navigation
feat(sqlserver): complete table-valued functions in FROM/JOIN context - #13394
Conversation
TVFs are relation sources used directly in FROM/JOIN, so the function objects from the completion metadata now join the table candidate set on sqlserver; procedures and other engines are unaffected (t8y2#13131).
|
CI 状态说明:本轮 |
zipg
left a comment
There was a problem hiding this comment.
[P2] 当前实现把所有 object.type === "function" 都加入 FROM/JOIN,并未区分表值函数与标量函数。现有 SQL Server 元数据把 FN/FS(标量)和 IF/TF/FT(表值)都映射为 FUNCTION,所以 GetCustomerName 这类标量函数也会被当成关系来源推荐;SELECT * FROM dbo.GetCustomerName(...) 随后执行失败。PR 注释和说明中的“Scalar functions stay in the routine context only”与代码行为不一致。
支持 TVF 的需求合理,但应在元数据/补全契约中保留返回表类型的区别,再仅将真正的 IF/TF/FT 放入 FROM/JOIN;未知类别应保守处理。请补充同一 schema 同时存在标量函数和 TVF 的用例,断言 TVF 出现、标量函数和过程不出现,同时保留 SELECT 表达式里的标量函数补全,并验证带参数函数的插入结果。类型依据:Microsoft sys.objects 文档。
这需要补齐上下游类型信息并重新验证,暂不代改或合并。涉及补全候选界面,修改后建议补充 FROM/JOIN 候选和 SELECT 表达式候选的截图,展示 TVF/标量函数的区分。
…letion The completion assistant reports the return kind through dataType: IF/TF/FT functions come back as "table" while scalar FN/FS functions carry their return type name. Filter on that kind so scalar functions and unknown categories stay in the routine context only (t8y2#13394 review), and insert the parameterized call for TVFs with a known signature.
|
已按 review 意见重做(69d50d42a): 只把真正的表值函数放进 FROM/JOIN。 补全助手链路里本来就有返回类型信息:SQL Server 侧 object.type === "function" && object.dataType?.trim().toLowerCase() === "table"
用例( 全量 关于截图:这个改动只影响补全候选列表,界面上的差异就是 FROM/JOIN 候选里不再出现标量函数。本机没有 SQL Server 实例可截图;如果你需要,我可以在有实例的环境里补 FROM/JOIN 与 SELECT 表达式两个候选列表的截图。 |
|
Addressed on The completion assistant already carries the return kind in
|
zipg
left a comment
There was a problem hiding this comment.
已复核更新,dataType === "table" 已解决之前混入标量函数的问题,但当前 HEAD 还有两处会生成错误 SQL 的缺口,需要作者继续调整。
- [P2] 零参数/无签名 TVF 仍插入裸名称。
if (!signature) return item让TotalSales的 apply 为TotalSales,而 FROM 中应为TotalSales()。即使函数没有参数也必须是调用形式。请覆盖空签名和缺失签名的插入结果。 - [P2] 显式 schema 未限制候选。新分支把所有
input.objects的 TVF 直接传给 buildTableItems,未按 context 的 schema 筛选。在SELECT * FROM dbo.下,同时提供 dbo.DboRows 和 archive.ArchiveOnly,仍会推荐 ArchiveOnly;插入后成为错误的 dbo.ArchiveOnly。也请覆盖不同 schema 同名 TVF、各自不同参数签名的情况,避免仅按 name 建立的 signaturesByLabel 串用签名。
我在 exact HEAD 上补了临时评审用例实测:原有 5 项通过,新增两项分别得到 TotalSales(期望 TotalSales())及候选 [DboRows, ArchiveOnly](期望排除 ArchiveOnly),两项均失败。未修改作者分支;这些契约需要一起修正再验证。
修改后建议补充 FROM/JOIN 带 schema 的候选和 SELECT 表达式候选截图,展示 TVF/标量函数及 schema 范围。
zipg
left a comment
There was a problem hiding this comment.
已 push 7a450ef6 到 feat/13131-sqlserver-tvf-completion,处理上一轮的第 1 点:
apply现在无条件走buildRoutineApply,无签名/零参数的 TVF 也会插成TotalSales(),不会再被插成FROM TotalSales这种裸名字。- 新增用例
inserts a call for zero-argument and signature-less table-valued functions固定这个行为。
第 2 点(SELECT * FROM dbo. 时未按 context schema 过滤候选)我没有改动:buildTableItems 自己已经吃 context 和 currentSchema,要确认到底是 buildTableItems 的过滤没覆盖这个入口,还是这条新分支绕过了它。麻烦你在补用例时把 dbo.DboRows + archive.ArchiveOnly 的场景加进去;如果 buildTableItems 本身已经过滤,那只是缺测试,不用再改实现。
本地 apps/desktop/src/lib/__tests__/sql 全量 2862 项通过。
…calls Per the review on t8y2#13394: the raw object list leaked TVFs from other schemas into a schema-qualified FROM ( offered archive.ArchiveOnly), because buildTableItems qualifies labels but does not filter its input — the regular tables arrive pre-scoped by their provider, and the TVF branch bypassed that. The candidates are now narrowed to the typed qualifier's schema, falling back to the current schema, which also keeps the by-name signature lookup from crossing schemas when the same function name exists twice. And a table-valued function is a relation source only in call form: the insert now always goes through buildRoutineApply, so zero-argument and signature-less TVFs insert instead of the bare name.
…calls Per the review on t8y2#13394: the raw object list leaked TVFs from other schemas into a schema-qualified FROM ("FROM dbo." offered archive.ArchiveOnly), because buildTableItems qualifies labels but does not filter its input - the regular tables arrive pre-scoped by their provider, and the TVF branch bypassed that. The candidates are now narrowed to the typed qualifier's schema, falling back to the current schema, which also keeps the by-name signature lookup from crossing schemas when the same function name exists twice. And a table-valued function is a relation source only in call form: the insert now always goes through buildRoutineApply, so zero-argument and signature-less TVFs insert "TotalSales()" instead of the bare name.
0b00cc4 to
e144b39
Compare
|
两点都已在分支上处理(注意:review 里提到的
用例(
关于截图:完成候选拦截在 headless 契约测试里断言(候选集合与插入文本),本环境无法出 UI 截图;如需要我可以再看仓库有没有 headless gallery 之类的现成通道。 |
t8y2
left a comment
There was a problem hiding this comment.
Both review rounds are resolved at e144b39: the FROM/JOIN branch now filters TVF candidates by qualifier schema (falling back to currentSchema) and builds signatures from the scoped set, with cross-schema coverage added. Zero-argument call-form insertion is retained. Verified locally on the exact head: the new spec passes 8/8 and the SQL completion suite shows no regressions.
|
Thanks for the contribution! Merged in b2c6bf7, will be released in the next version. |
Summary
Closes #13131.
The completion metadata for SQL Server already returns table-valued functions (
FN/IF/TF/FS/FTmapped toFUNCTIONinsqlserver_list_objects_sql), but the completion engine only surfaced them in routine contexts. A TVF is a relation source —SELECT * FROM dbo.Split(@csv)— so afterFROM/JOINthe candidate set (tables + views) never included it and there was nothing to complete.Change — on sqlserver, the table-suggestion branch now also converts
function-typed completion objects into table candidates (type: "function", signature as detail). Scalar functions keep working everywhere they did (routine context,SELECTlist); procedures stay out of the FROM set; every other engine is untouched.Behavior
SELECT * FROM dbo.SELECT * FROMSELECT GetCustomerName(Test plan
sqlCompletion.sqlserverTvf.spec.ts: TVFs offered after FROM/qualified FROM; procedures excluded; no leakage into other engines — 3/3vue-tsctypecheck clean;oxfmtclean