Skip to content

Add dictGetRoot function for hierarchical dictionaries - #109459

Merged
alexey-milovidov merged 8 commits into
masterfrom
dict-get-root-public
Jul 19, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
dict-get-root-public

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 6, 2026 •

Copy link
Copy Markdown
Member

Adds a new function dictGetRoot(dict_name, key) that returns the topmost ancestor (the root) of a key in a hierarchical dictionary.

Previously, to get the root of an element you had to take the last element of dictGetHierarchy, i.e. dictGetHierarchy(dict_name, key)[-1]. dictGetRoot returns it directly as a scalar.

  • If the key is itself a top-level node of the hierarchy, the key is returned.
  • If the key is absent from the dictionary, 0 is returned (matching dictGetHierarchy(dict_name, key)[-1], where an absent key produces an empty hierarchy).

It reuses the existing per-dictionary getHierarchy implementation, so it works for all layouts that support hierarchy (flat, hashed, hashed_array, cache, direct) without any per-dictionary code.

Changelog category (leave one):

  • New Feature

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

Added a new function dictGetRoot which returns the topmost ancestor (the root) of a key in a hierarchical dictionary. It is a convenient equivalent of dictGetHierarchy(dict_name, key)[-1].

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.7.1.1175 (included in 26.7 and later)

`dictGetRoot(dict_name, key)` returns the topmost ancestor (the root) of a
key in a hierarchical dictionary. It is a convenient equivalent of taking the
last element of `dictGetHierarchy`, i.e. `dictGetHierarchy(dict_name, key)[-1]`.

If the key is itself a top-level node of the hierarchy, the key is returned.
If the key is absent from the dictionary, `0` is returned, matching the
behavior of `dictGetHierarchy(dict_name, key)[-1]` (an absent key produces an
empty hierarchy).

The function reuses the existing per-dictionary `getHierarchy` implementation,
so it works for all layouts that support hierarchy (flat, hashed, hashed_array,
cache, direct) without any per-dictionary code.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mintlify

mintlify Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 6, 2026, 2:07 AM

@clickhouse-gh

clickhouse-gh Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3cc7da1]

Summary: ✅


AI Review

Summary

This PR adds dictGetRoot(dict_name, key) as a scalar helper for hierarchical dictionaries, updates the dictGet privilege metadata/docs to include the new hierarchy helpers, and adds stateless coverage for both regular and Nullable(UInt64) parent hierarchies across the supported layouts. I did not find a correctness, privilege, or evidence gap in the current patch.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jul 6, 2026
The equivalence query used `min(...) FROM system.numbers LIMIT 6`, but
`LIMIT` does not push down through the aggregation, so `min` read all of
`system.numbers` and hit `max_rows_to_read`, failing with `TOO_MANY_ROWS`
in the Fast test. Use `numbers(6)` to bound the read to the intended 6
rows. The output is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The regression test only proved the `dictGetHierarchy(dict, key)[-1]`
equivalence for the non-nullable `UInt64` hierarchy, where the root's
parent is the `0` sentinel. A `Nullable(UInt64) HIERARCHICAL` dictionary
stops the hierarchy at a `NULL` parent instead, so `0` can be a genuine
node rather than the null value.

Add a second block that builds a nullable-parent hierarchy across all five
layouts (flat, hashed, hashed_array, cache, direct) and checks the same
`dictGetRoot` equivalence. It also documents that key `0` (a real root) and
an absent key both return the default `0` and are indistinguishable, exactly
as for `dictGetHierarchy(dict, key)[-1]`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Bring the branch up to date with master. This pulls in #109176
(`Parse qualified COLUMNS matcher in INSERT column lists`), the
root-cause fix for the `Stress test (amd_debug)` AST-fuzzer failure
(`Inconsistent AST formatting`, issue #109158), so that red clears on
the next CI run.
The dictGetRoot function is authorized by the dictGet privilege: it reuses
FunctionDictHelper, which calls checkAccess(AccessType::dictGet, ...), and
functionIsDictGet matches the dictGet name prefix. Add dictGetRoot next to its
sibling dictGetHierarchy in the dictGet alias list so that GRANT dictGetRoot
works as an alias, SHOW PRIVILEGES advertises it, and the grant documentation
lists it. Refresh 01271_show_privileges.reference accordingly.

Addresses the AI review feedback on the PR.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Access/Common/AccessType.h Resolved
…tGet privilege

functionIsDictGet (src/Interpreters/misc.h) gates every dictGet* function,
including dictGetChildren and dictGetDescendants, behind AccessType::dictGet.
The alias list added for dictGetRoot omitted these two siblings, so
SHOW PRIVILEGES and grant.md still didn't reflect that GRANT dictGetChildren
and GRANT dictGetDescendants work as exact aliases of dictGet.
@clickhouse-gh

clickhouse-gh Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.10% 86.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 78.20% 78.20% +0.00%

Changed lines: Changed C/C++ lines covered: 67/72 (93.06%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Jul 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 19, 2026
Merged via the queue into master with commit 7361433 Jul 19, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the dict-get-root-public branch July 19, 2026 01:54
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 19, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…blic

Add dictGetRoot function for hierarchical dictionaries

This branch was successfully deployed

1 active deployment
staging - docs — 3cc7da11 Deployed Jul 18, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature 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.

3 participants