Merged
chore(archive): 归档 develop_oss@c8a258d3f(DuckDB 跨 schema 解析 + dwcli 错误分类) #57
LiuliuliuAdd on 25 days ago
chore(archive): 归档 develop_oss@c8a258d3f(DuckDB 跨 schema 解析 + dwcli 错误分类) #57
Merged
LiuliuliuAdd on 25 days ago
Liuliuliu
LiuliuliuCollaborators
25 days ago

归档信息

  • 锚点:develop_oss@c8a258d3fc4f(与 dev-hub:develop_oss tip 一致,归档前已核对无落后)
  • 基线:workswarm0.2.6(patch 为基于该 tag 的全部内容差异,零排除)
  • 归档 commit:6859422991ce(parent = mr-hub:develop tip 5e583f350,MR diff 只显本次增量)

本次增量(develop_oss 11 个提交,实质 5 项)

  • fix(skill): dw_client 业务错误不再吞 detail,按工作空间错误码分类(88586ac7c)
  • fix(web): DuckDB 裸表名支持跨 schema 解析,表不存在不再报 internal_error(1aba09258)
  • fix(web): 裸表名跨 schema 同名时优先 main,与 DuckDB 默认 search_path 一致(2fbdd523e)
  • fix(analysis): probe/check-join SQL 按源方言引用标识符(735b22a30)
  • test(skill): 清理 plan 导入残留的裸名 render 缓存(6958f5b07)

归档统计

  • patch 全量差异:A=996 M=211 D=32(20,284,566 字节,零排除)
  • 展示层:skills 110 项 | sync 145 文件(清单 28 项)
  • 还原不变量已双层验证:归档内建自校验 + verify_equivalence.py 均通过(基线 + apply patch == anchor 全树,零差异)

MR 为归档生成物,不手改;评审意见改 develop_oss 后重新归档。

likedislike
Pull Request has been successfully merged by openJiuwen-bot.
(Thank you for Liuliuliu's contribution.)
atomgit-bot
atomgit-bot
25 days ago Comments:

变更摘要

本 PR 为归档生成物,把 develop_oss@c8a258d3f 的内容合并回 develop,增量集中在两处:一是 DuckDB 多 schema 场景下裸表名的解析与错误语义,二是 dwcli 技能侧的错误分类与信息透传。核心思路是让「裸表名解析」在连接器、业务数据访问对象(DAO)、HTTP 路由三层保持一致:优先落到默认 main,跨 schema 唯一同名时自动解析为全限定名,多义时返回带候选的「未找到」错误;同时让技能侧脚本能拿到规范表名并按源方言语义生成探针 SQL。

主要改动

  • 裸表名跨 schema 解析与默认 schema 优先:codec_impl.py 中 _checked_table 改为按目录条目匹配(新增 _catalog_matches、_default_schema_matches),带 schema 的目录接受裸表名并返回全限定名,多义时抛出含候选列表的 LookupError;duckdb_native.py 的 resolve_dataset 先按 main 解析,main 不存在时在全部 schema 中找唯一同名表,多义时抛 ConnectorError 并列出候选;get_table_detail、preview_table 改用解析后的规范名。
  • 新增 default_schema 配置项:ref_codec.py 的 codec 基类增加 default_schema 字段,db_connector.py 中 DuckDB 的 codec 置为 "main",使「同名优先 main」与裸名 SQL 的默认 search_path 行为对齐。
  • 表不存在由 500 改为 404:databases/controller.py 增加对 LookupError 的捕获,返回 404 + {"error": "not_found"},避免路由把「找不到表」归为 internal_error,让技能侧可以据此分类而非落到 UNKNOWN。
  • 探针 SQL 按源方言引用标识符:analysis/explore.py 引入 dialect_registry.quote_ident,probe_request 与 _sample_inclusion(新增 dialect 参数)依据列的 source_type 选择引号风格,不再硬编码反引号,避免 duckdb/postgres 方言在护栏 sqlglot 解析阶段报语法错误。
  • 技能侧错误透传与新错误类型:dw_client.py 中仅工作空间类错误码包装为 WorkspaceContextError,其余错误统一经 _err_msg 带出 detail;schema() 新增返回 resolved_table,dw_error_classify.py 新增 AMBIGUOUS_TABLE 分类(retry=True)及建议文案,get_schema.py、sample_dim_values.py 改用 resolved_table 拼接后续 SQL,nl2sql/SKILL.md 同步补充该错误类型说明。

(此外 test_plan_reuse.py 清理了 plan.py 导入残留的裸名 render 模块缓存,避免遮蔽 dw-report 的 render 包;归档 patch dataswarm.patch 随之重新生成。)

likedislike
Incorrect?
atomgit-bot
atomgit-bot
25 days ago Comments:

代码审查

审查结论

变更清单逐一核查

文件 结论
dataswarm/patch/dataswarm.patch 2 项问题(见下):databases/controller.py 的 except LookupError 过宽;default_schema 只覆盖 DuckDB。其余增量(explore.py 按源方言引用标识符、codec_impl 裸名按目录解析、duckdb_native 裸名回退、dw_client/dw_error_classify 的归档副本、新增单测)逐条核对过:quote_ident(dialect, name) 形参与 dialect_registry 一致,csv/excel/parquet 等源经 _ALIASES 归一为 duckdb,ColumnMeta.source_type 确实存在,_catalog_matches 的单段/两段匹配索引无误,_sample_inclusion 的方言参数所有调用点均已同步。
dataswarm/skills/_dw_common/scripts/dw_client.py 无问题。code = error_code or error + 只对 4 个工作空间码包 WorkspaceContextError 的收窄,与 _err_msg 的 detail 透传自洽;已核对唯一按类型名分流的下游 plan_to_tasks.py:105(其注释本就要求“workspace 错误向上抛,其余走 legacy 兜底”),收窄后语义反而与消费方契约一致;resolved_table 的 payload["name"] 与服务端 get_table_detail 返回的 "name" 一致,缺省回退到入参表名。
dataswarm/skills/_dw_common/scripts/dw_error_classify.py 无问题。AMBIGUOUS_TABLE 排在 TABLE_NOT_FOUND 之前(避免被 not found 分支抢走),retry=True 与 SKILL.md 中“retry 表示改 SQL 后值得再试”的语义相符,SUGGESTIONS 已补齐对应项。
dataswarm/skills/nl2sql/scripts/get_schema.py 无问题。resolved_table or table 回退安全;返回的全限定名 "schema"."table" 再次传入 get_schema/sample_dim_values 时会被服务端目录精确命中,不会二次解析失败。
dataswarm/skills/nl2sql/scripts/sample_dim_values.py 无问题。table = resolved_table or table 后仅用于 quote_table();已核对 _db_client.quote_table 对“已加引号的 schema.table”会逐段去引号再加引号,产出 "schema"."table" 正确,不会出现双重引号;文件源(source_type=csv)走单标识符分支,视图名里的点不会被误当分隔符。

问题统计

  • P0:0
  • P1:0
  • P2:1(except LookupError 连带吞掉 KeyError,服务端缺陷被伪装成 404 not_found)
  • P3:1(SQL Server 属 qualified catalog 但无 default_schema,裸名跨 schema 同名会误报歧义)

总体风险判断

变更整体质量较高:错误分类与裸表名解析的链路(服务端目录 → LookupError → 404 → dw_client detail 透传 → dw_error_classify)是打通的,且每处修复都配了针对性单测。剩余风险集中在错误状态码的过度归类——404 分支的捕获面比预期宽一档,会把潜在服务端缺陷误导成“表不存在”,建议合入前把 KeyError 分离出去;default_schema 的方言覆盖不全是新功能的已知留白(fail-loud 且有明确 hint,可恢复),可在后续增量补齐。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
Incorrect?
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Added label: sig/sig-dataswarm
atomgit-bot
atomgit-bot
25 days ago Comments:

AtomGit AI 助手使用指南

在 PR 评论中使用命令即可触发。支持在普通评论和代码行评论中使用。

功能 命令 说明
代码审查 /ai review 检查代码质量、潜在问题、安全风险
PR 摘要 /ai summary 生成 PR 变更内容的结构化摘要
代码解释 /ai explain 解释代码变更的逻辑和意图
自由提问 @atomgit-bot <问题> 询问关于本 PR 的任何问题
帮助 /ai help 显示此帮助信息

免责声明

AI 助手可能存在误判,请结合自身判断。可以对评论点 👍 或 👎 帮助我们改进。

likedislike
Incorrect?
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

欢迎来到 openJiuwen 社区

Hey @qq_22408539 , 感谢你对社区的贡献.

机器人使用手册

有关指令的使用,可以点击 此处 查看详情。开发人员可以在每个PR或Issue下方评论特定指令来触发机器人任务。

联系指引

有疑问可以联系 SIG: sig-dataswarm ,
维护者是: @xinyu-jiuwen, @youchhhh ,
审核者是: @SincoTeng, @qq_22408539, @wjy_project, @yuhangye .

likedislike
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Added label: openJiuwen-cla/yes
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

CLA 签署成功

qq_22408539, 感谢您的代码贡献。 所有的代码贡献者都已完成了 CLA 签署。 👍

likedislike
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

The pipeline(pipeline number:57) is running. Please wait a moment...

likedislike
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Added label: ci-running
atomgit-bot
atomgit-bot25 days agoStart code review1
dataswarm/patch/dataswarm.patch
@@ -40171,0 +40259,4 @@
40259++ # 表不在数据源目录里(含跨 schema 裸名歧义):是「找不到」,不是服务端故障。
40260++ # 500 internal_error 会让技能侧只能报 UNKNOWN(hint 指向查数据库日志)。
40261++ handler._write_json(404, {"error": "not_found", "detail": str(exc)})
40262++ return
atomgit-bot
atomgit-bot25 days agoComments:

🟡 Medium Priority

变更行:databases/controller.py 的 handle_get 新增 except LookupError as exc: ... 404 not_found(归档 patch 行 40258-40262),位置在已有 except (IndexError, ValueError)(400)与 except Exception(500)之间。

问题链:该 try 覆盖 handle_get 的全部路由分支——/search(svc.search_tables)、/schema-gap(svc.schema_gap_analysis)、/{db}/tables(svc.list_tables)、/…/preview(svc.preview_table)、/{db}/tables/{table}(svc.get_table_detail)。CPython 里 LookupError 的继承树是 IndexError/KeyError → LookupError → Exception;IndexError 已被前一条 400 分支截走,因此本行实际新捕获的类只有 KeyError(外加 DAO 有意抛出的 LookupError)。

失败模式:KeyError 是服务端自身缺陷(例如 DAO/connector 里 self._spec["type"]、result["rows"] 之类字典取键、或后续重构改了返回 shape)。这类缺陷现在会从“500 internal_error + 栈定位”变成“404 not_found + detail='rows'”:

  • 技能侧 dw_client._dwcli 见到 404 抛 RuntimeError,dw_error_classify 对 detail 里 'rows'/not found 文本会归到 TABLE_NOT_FOUND,Agent 被引导去核对表名/拼写并反复重试;
  • 服务端真实 bug 在日志与状态码上被伪装成“表不存在”,排障链路(PR 正文里抱怨的“只看到 internal_error”)反而变成“只看到 not_found”。

修复方向:在使用点显式区分 KeyError(保持 500)与目录查找失败,或让 DAO 抛出专用异常类型(如 TableNotFoundError(LookupError))后只捕获该类型。

建议:在 except LookupError 之前补一条 except KeyError(保持 500 internal_error),或让目录查找失败抛专用异常子类后只捕获它,避免把服务端 KeyError 伪装成 404 not_found。

Suggestions
40262
+ except KeyError as exc:
40263
+ # KeyError 是 LookupError 的子类,属服务端缺陷:保留 500 便于定位。
40264
+ handler._write_json(500, {"error": "internal_error", "detail": str(exc)})
40265
+ return
40266
+ except LookupError as exc:
40267
+ # 表不在数据源目录里(含跨 schema 裸名歧义):是「找不到」,不是服务端故障。
40268
+ # 500 internal_error 会让技能侧只能报 UNKNOWN(hint 指向查数据库日志)。
40269
+ handler._write_json(404, {"error": "not_found", "detail": str(exc)})
40270
+ return
Apply suggestion
likedislike
Incorrect?
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Removed label: ci-running
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:
任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ✅SUCCESS 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 ✅SUCCESS 点此跳转
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 ✅SUCCESS N/A
likedislike
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Added label: ci-successful
SincoTeng
SincoTengCollaborators
25 days ago Comments:

/lgmt

likedislike
SincoTeng
SincoTengCollaborators
25 days ago Comments:

/approve

likedislike
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Added label: approved
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

Review Code Feedback

  • The label approved was added to this pull request. It means that SincoTeng reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
SincoTeng
SincoTengCollaborators
25 days ago Comments:

/lgtm

likedislike
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Added label: lgtm-SincoTeng
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

Review Code Feedback

  • The label lgtm-SincoTeng was added to this pull request. It means that SincoTeng reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
yuhangye
yuhangyeCollaborators
25 days ago Comments:

/lgtm

likedislike
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Added label: lgtm-yuhangye
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

Review Code Feedback

  • The label lgtm-yuhangye was added to this pull request. It means that yuhangye reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

PR Merge Failed

  • reason: {"message":"The MR can not be merged, because of CodeReview discussion not resolved"}
likedislike
openJiuwen-bot
openJiuwen-botCollaborators
25 days ago Comments:

PR Merge Failed

  • reason: {"message":"The MR can not be merged, because of CodeReview discussion not resolved"}
likedislike
LiuliuliuLiuliuliuCollaborators
25 days ago Resolved final issue
openJiuwen-botopenJiuwen-botCollaborators
25 days ago Merged pull request, merge node SHA: 9bf3a1f5bd2e1dfa678f63b87e792b3850dc1513