Skip to content

🐛 fix(grid): show column comments for joined (multi-source) query results - #6358

Merged
t8y2 merged 4 commits into
t8y2:mainfrom
0verme:fix/query-result-column-comments
Aug 16, 2026
Merged

🐛 fix(grid): show column comments for joined (multi-source) query results#6358
t8y2 merged 4 commits into
t8y2:mainfrom
0verme:fix/query-result-column-comments

Conversation

@0verme

@0verme 0verme commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #2129 (first half: result-set column comments for joined queries).

Problem

Executing a JOIN / multi-source query hid every column comment in the result grid. Single-table queries worked because the data grid builds its comment map from tableMeta.columns; multi-source results are not editable so tableMeta was undefined, and the source tables' metadata — already loaded during editability analysis — was discarded.

Changes

  • QueryTab (types/database.ts) gains resultColumnComments (merged comments from every JOIN source) and queryDisplaySourceColumns (display-only result→source mapping).
  • queryStore.ts buildQueryMetadataPatch now populates both fields for multi-source branches via mergeEditableSourceColumnComments / mergeEditableSourceDisplayColumns; applyQueryMetadataPatch, tab clone and result-cache snapshot carry them.
  • DataGrid.vue merges resultColumnComments into columnCommentMap and resolves header/tooltip comments through queryDisplaySourceColumns first for precise matching.
  • ContentArea.vue passes the new props.

Tests

  • queryStore.multiSourceColumnComments.spec.ts: JOIN result merges comments from both sources + display mapping; single-source regression stays free of the new fields.
  • multiSourceColumnMapping.spec.ts: sqlAnalysis per-source column mapping (incl. duplicate result names).
  • DataGridColumnComments.spec.ts: extended source assertions.

Validation

  • vue-tsc typecheck ✅, oxlint ✅, oxfmt --check
  • 45 related test files / 983 tests pass; the 4 failing specs (Redis completion, grid popover/condition/readonly) were confirmed failing before these changes (pre-existing).

Follow-up

The second half of #2129 — hovering a column/table name in the SQL editor to show its comment — will be a separate PR.

Review follow-up

This update addresses the requested changes from the latest review:

  • Resolve result-column comments by result ordinal instead of a global physical-column-name map.
  • Preserve the source identity for each result column with sourceKey + sourceColumn, so same-named columns from joined sources do not collide.
  • Reuse the existing metadata-aware source-column binder for aliases and source resolution; ambiguous or calculated columns intentionally receive no comment rather than a potentially incorrect one.
  • Preserve quoted identifier semantics instead of globally lowercasing identifiers.
  • Restore the new column metadata correctly across tab result-cache serialization / reload paths.

Regression coverage includes:

  • same-named columns across joined tables
  • alias resolution and ambiguous columns
  • quoted mixed-case identifiers
  • duplicate result names
  • result-cache round trips
  • single-table fallback behavior

@github-actions github-actions Bot added area/desktop Desktop application or Tauri shell bug Something isn't working ui-change Changes user-visible interface, text, or visual assets labels Aug 15, 2026
…ults

Joined results were marked non-editable (no single tableMeta), so the data grid's comment map built only from tableMeta.columns stayed empty and every column comment disappeared. The source tables' metadata was already loaded during editability analysis — it was just discarded.

- QueryTab gains resultColumnComments (merged comments from every JOIN source) and queryDisplaySourceColumns (display-only result->source mapping), populated in buildQueryMetadataPatch for multi-source branches.
- DataGrid merges resultColumnComments into columnCommentMap and resolves comments through queryDisplaySourceColumns first.
- ContentArea passes the new props; tab clone and result-cache snapshot carry the fields.
- Tests: multi-source JOIN comment merge + display mapping (queryStore), per-source column mapping (sqlAnalysis), DataGrid source assertions.

Validation: vue-tsc typecheck, oxlint, oxfmt check, 45 related test files / 983 tests pass; 4 pre-existing failures (Redis completion, grid popover/condition/readonly specs) confirmed failing before these changes.
@0verme
0verme force-pushed the fix/query-result-column-comments branch from f58b228 to b51ceb7 Compare August 15, 2026 16:08

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: the result-column comment mapping loses source identity and therefore returns incorrect metadata.

  1. Comments from all source tables are merged into one map keyed only by physical column name with first-source-wins behavior. Two tables with id columns can display the first table's comment for both result columns.
  2. The result mapping stores a source column name but not its source key, and it uses unbound SQL analysis. A uniquely resolvable unqualified alias such as name AS username cannot map back to the physical column even though the existing metadata binder can resolve it.
  3. The new fields are written to the result cache snapshot but are not restored when the cached result is reloaded.
  4. Lowercase aliases in the global map also collapse valid quoted mixed-case identifiers.

Please store comments per result ordinal with source identity, reuse database-aware binding/canonicalization, return no comment for ambiguity, restore the fields from cache, and cover same-name sources, aliases, quoted case, duplicate result names, and cache restore.

Reworks the multi-source column-comment fix per review on t8y2#6358.

- resultColumnComments is now indexed by result ordinal (Array<string|undefined>) instead of a first-source-wins name map: two tables with an id column keep per-source comments on both result columns.
- queryDisplaySourceColumns now carries source identity per ordinal ({sourceKey, sourceColumn}) via the same database-aware binder (resolveMetadataColumnName) used by editability analysis: uniquely resolvable unqualified aliases (name AS username) map back to the physical column, quoted mixed-case identifiers match exactly, and ambiguous or computed columns yield undefined instead of a wrong comment.
- The two fields round-trip through the result cache snapshot and are restored on reload (restoreCachedResultPayload, projectResultRun, persistResultRun, captureDisplayedResultRun, clearResultRunPayload) and reset on every execution state transition.
- DataGrid consumes comments per result ordinal and keeps the tableMeta-derived lookup fallback for single-source grids.

Validation: vue-tsc, oxlint; queryStore.multiSourceColumnComments (6), multiSourceColumnMapping (9), tabResultCache (incl. cache restore), DataGridColumnComments pass; sql+tabs suites 991 tests, queryStore suites 197/198 (1 pre-existing tableMetaRestore timeout confirmed on HEAD baseline); 3 pre-existing grid spec load failures confirmed on HEAD baseline.
@0verme

0verme commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in ed2c71e10.

  1. Result column comments are now resolved by result ordinal and retain sourceKey + sourceColumn, avoiding collisions for same-named columns across joined sources.
  2. Source-column resolution now reuses the existing metadata-aware binder instead of the previous unbounded SQL analysis, including alias resolution and ambiguity handling.
  3. The new metadata is restored correctly from result cache snapshots / runs.
  4. Identifier matching no longer globally lowercases quoted identifiers, preserving database-specific quoted identifier semantics.

I also added regression coverage for duplicate source column names, aliases / ambiguity, quoted mixed-case identifiers, duplicate result names, and cache round trips.

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

维护者补丁 622eef73e 已推送。

根因:复制查询 Tab 时对数组 resultColumnComments 使用对象展开,运行时会得到普通对象,破坏按列序号读取注释的数组语义。

修复:改为数组展开,并增加复制 Tab 时保持数组类型、内容及独立引用的回归测试。

验证:字段注释、来源映射、结果缓存和 Tab 复制相关 5 个测试文件共 42 项通过;pnpm typecheck、格式检查及 git diff --check 通过。未新增依赖。

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the maintainer-patched exact head 622eef73e; column-comment regressions, typecheck, and frontend CI pass.

@t8y2
t8y2 merged commit 64e5e88 into t8y2:main Aug 16, 2026
14 checks passed
@t8y2

t8y2 commented Aug 16, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 64e5e88, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/desktop Desktop application or Tauri shell bug Something isn't working ui-change Changes user-visible interface, text, or visual assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

支持在SQL编辑器中悬停显示字段/表注释,并修复查询结果中字段注释不显示的问题

2 participants