Skip to content

Add a test for an unqualified dictGet in a SQL UDF used by an ALIAS column - #123563

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:test-udf-dictget-alias-lightweight-delete-123489
Oct 3, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:test-udf-dictget-alias-lightweight-delete-123489

Conversation

@groeneai

@groeneai groeneai commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #123489
Related: #114923

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not required.

Description

Requested by PedroTadim on the linked issue. Test only, no src/ change.

What breaks. On 26.9.8.3, a table with v ALIAS f(id) where f = x -> dictGet(d, 'v', x) reads v
fine from its own database, but a SELECT from another current database fails with
Dictionary (d) not found, and DELETE FROM t WHERE id = 1 fails with Code 341 wrapping the same
error (its mutation runs in a background context whose current database is the server default).

Root cause. On 26.9, CREATE TABLE qualified names before expanding SQL UDFs and never after, so the
column was persisted as dictGet(d, 'v', id). Master persists dictGet(<db>.d, 'v', id) since #114923,
which qualifies the table expressions of the columns list after the UDF expansion. That PR's tests
cover dictGet only in a view and joinGet in a DEFAULT; nothing covered this shape.

Validation.

  • Official 26.9.8.3: the test fails with the issue's two errors; the same script with the UDF body
    qualified (dictGet(<db>.d, ...), the only change) passes, so the persisted spelling alone decides it.
  • Master with only the visitTableExpressions(*create.columns_list) call from Make a table read by a scalar subquery in a CONSTRAINT a loading dependency #114923 removed: fails
    with the same two errors; restored: passes.
  • 50/50 green under settings randomization, 8 copies in parallel (the UDF name is scoped by
    ${CLICKHOUSE_DATABASE}, which is why this is a .sh test).

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/123563]

Version info

  • Merged into: 26.10.1.1359-master (included in 26.10 and later)

…olumn

On 26.9.8.3 `CREATE TABLE` qualified table and dictionary names before
expanding SQL UDFs and never after, so `v ALIAS f(id)` with
`f = x -> dictGet(d, 'v', x)` was persisted as `dictGet(d, 'v', id)`.
Every later reader resolved `d` against its own current database: a
`SELECT` from another database failed with `Dictionary (d) not found`,
and the mutation of a lightweight `DELETE` (analyzed in a background
context) failed with Code 341 wrapping the same error.

Master already persists `dictGet(<db>.d, 'v', id)` since ClickHouse#114923, which
runs `AddDefaultDatabaseVisitor::visitTableExpressions` on the columns
list after the UDF expansion. Its tests cover `dictGet` only in a view
and `joinGet` in a `DEFAULT`, so this adds the issue's shape: an
identifier-form `dictGet` from a UDF in an `ALIAS` column, read from
another current database and by a lightweight `DELETE`.

The test is a shell test because a SQL UDF is server-wide and
`CREATE FUNCTION` takes no query parameter, so the name must be scoped
by `${CLICKHOUSE_DATABASE}` to be safe under concurrent runs.

Closes ClickHouse#123489

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 2, 2026
@groeneai

groeneai commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) and an independent cold review of the same tree (0 blocker, 0 major findings). Nothing to adjudicate.

Session id: cron:clickhouse-review-slot-9:20261002-144503

@groeneai

groeneai commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On official 26.9.8.3 the test fails on every run: the cross-database SELECT gives Code: 36 Dictionary (d) not found and the lightweight DELETE gives Code: 341 wrapping it. Not settings-dependent: the trigger is the persisted bare dictionary name.
b Root cause explained? On 26.9, CREATE TABLE qualified names before expanding SQL UDFs and never after, so the ALIAS was stored as dictGet(d, 'v', id); readers with another current database, including the DELETE's background mutation, looked the dictionary up in the wrong database. #114923 added a post-expansion visitTableExpressions pass on the columns list, so master stores dictGet(<db>.d, 'v', id).
c Fix matches root cause? Test-only PR; the fix is #114923, already on master. The test asserts the user-visible contract (cross-database read and lightweight DELETE), not the stored spelling.
d Test intent preserved / new tests added? New regression test for the shape no existing test covered: identifier-form dictGet from a SQL UDF in an ALIAS column, read by a mutation.
e Both directions demonstrated? Fails on 26.9.8.3 and on master with only the #114923 columns-list pass removed; passes on master and after restoring the pass. On 26.9.8.3, qualifying the UDF body (the only change) makes it pass.
f Fix is general across code paths? N/A (no code change). Sibling carriers checked: DEFAULT/MATERIALIZED and string-form dictGet go through the same pass (covered by 05223/05043); ALTER ... ADD COLUMN was never affected; heavy mutations read the same stored metadata.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (no code change).
h Backward compatible? (maintainer-approved exception only) N/A: test only, no setting or format change.
i Invariants and contracts preserved? N/A (no code change). The test is parallel-safe (UDF name scoped by ${CLICKHOUSE_DATABASE}, 50/50 green with 8 concurrent copies under settings randomization) and drops its UDF in a separate client call.

Session id: cron:clickhouse-impl-slot-5:20261002-142300

@clickhouse-gh

clickhouse-gh Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4e12ec6]

Summary: ✅


AI Review

Summary

This PR adds a stateless shell regression test for issue #123489, covering a dictGet introduced by SQL UDF expansion inside an ALIAS column and checking both cross-database reads and a lightweight DELETE mutation. I do not see a correctness or coverage gap in the test relative to the bug it targets, and the PR metadata is appropriate for a test-only change.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 2, 2026
@PedroTadim PedroTadim self-assigned this Oct 2, 2026
@PedroTadim
PedroTadim enabled auto-merge October 2, 2026 15:11
@AndreaCatalucci

AndreaCatalucci commented Oct 2, 2026 •

Copy link
Copy Markdown

Thank you for taking this up so quickly!

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 2, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit 2c6edc8 Oct 3, 2026
149 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 3, 2026
valerypetrov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Nov 13, 2026
With the revert, the only caller of `addWithAliases` passes
`only_recursive_with_hides_table = true`, so `collectWithExpressionAliases`
is never called and `with_expression_aliases` is never written:
`isExpressionAlias(name)` equals `expression_aliases.contains(name)` on every
remaining path. Remove the parameter, the member and both helpers (added by
ClickHouse#114908 for the removed pass); the full traversal behaves as before. The
second sentence of the comment on the string overload of
`qualifyDictionaryNameWithDatabase` named the removed metadata-load caller.

05233_udf_expansion_with_alias_scope (ClickHouse#114908) and
05317_udf_dictget_alias_column_lightweight_delete (ClickHouse#123563, issue ClickHouse#123489)
test the qualification of the names a SQL UDF brings into a CREATE, which
the revert removes; both fail on the revert commit and are deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-udf User-defined functions (SQL UDFs, executable UDFs) and UDF framework. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-udf User-defined functions (SQL UDFs, executable UDFs) and UDF framework. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unqualified dictGet inside SQL UDF used by ALIAS column succeeds on SELECT but fails on DELETE

4 participants