Skip to content

Support of non-map columns for -Map combinator (also support for multi argument aggregate functions) - #123449

Merged
alexey-milovidov merged 64 commits into
masterfrom
continue-pr-56335-map-combinator-non-map-columns
Oct 8, 2026
Merged

alexey-milovidov merged 64 commits into
masterfrom
continue-pr-56335-map-combinator-non-map-columns

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Fix for #38857

Now, -Map combinator support syntax like that: argMaxMap(arg, val, key)

It's also somewhat faster, than using sumMap(map(key, value)

WITH number % 1000 AS key
SELECT sumMap(number, CAST(key, 'String'))
FROM numbers(10000000)
FORMAT `Null`

0 rows in set. Elapsed: 1.604 sec. Processed 9.48 million rows, 75.87 MB (5.91 million rows/s., 47.30 MB/s.)
Peak memory usage: 97.76 KiB.

WITH number % 1000 AS key
SELECT sumMap(map(CAST(key, 'String'), number))
FROM numbers(10000000)
FORMAT `Null`

0 rows in set. Elapsed: 2.464 sec. Processed 9.88 million rows, 79.01 MB (4.01 million rows/s., 32.06 MB/s.)
Peak memory usage: 99.50 KiB.




WITH number % 1000 AS key
SELECT sumMap(number, key)
FROM numbers(10000000)
FORMAT `Null`

0 rows in set. Elapsed: 0.589 sec. Processed 8.63 million rows, 69.07 MB (14.66 million rows/s., 117.30 MB/s.)
Peak memory usage: 89.51 KiB.

WITH number % 1000 AS key
SELECT sumMap(map(key, number))
FROM numbers(10000000)
FORMAT `Null`

0 rows in set. Elapsed: 1.265 sec. Processed 9.68 million rows, 77.44 MB (7.65 million rows/s., 61.21 MB/s.)
Peak memory usage: 92.13 KiB.





WITH number % 100 AS key
SELECT argMaxMap(number, number, key)
FROM numbers(10000000)
FORMAT `Null`

0 rows in set. Elapsed: 0.723 sec. Processed 9.88 million rows, 79.01 MB (13.65 million rows/s., 109.23 MB/s.)
Peak memory usage: 71.20 KiB.

WITH number % 100 AS key
SELECT argMaxMergeMap(map(key, initializeAggregation('argMaxState', number, number)))
FROM numbers(10000000)
FORMAT `Null`

0 rows in set. Elapsed: 2.594 sec. Processed 9.75 million rows, 77.97 MB (3.76 million rows/s., 30.06 MB/s.)
Peak memory usage: 9.56 MiB.

Plus aggMapState looks much more user friendly:

┌─toTypeName(argMaxMapState(number, number, key))─────┐
│ AggregateFunction(argMaxMap, UInt64, UInt64, UInt8) │
└─────────────────────────────────────────────────────┘

Than

AggregateFunction(argMaxMergeMap, Map(UInt64, AggregateFunction(argMax, UInt64, UInt64)))

This supersedes #56335 by @UnamedRus (original commits and authorship are preserved). The original branch could not be updated with the latest master because the merge touches .github/workflows, which the automation token is not allowed to push to a fork. On top of the original branch this adds a merge of master (reconciling the -Map combinator with the -State rollback rework) and Time64 key support requested in review.

Closes: #38857
Related: #56335

Changelog category (leave one):

  • New Feature

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

-Map combinator can be used with non-map columns (the key is passed as the last argument, e.g. sumMap(value, key)) and supports aggregate functions with multiple arguments, e.g. argMaxMap(arg, val, key).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code


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

Version info

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

UnamedRus and others added 30 commits January 14, 2024 06:37
@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Both have a fix. The failing run on 7856509a90c predates the merged parts, and your master merge in 8b817496d55 brings them in.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai. Merged master again (808b02f). The failures on 8b81749 are unrelated to this PR:

The PR's own tests (01852_map_combinator, 05317_map_combinator_time_key, 05325_map_combinator_legacy_nan_keys) pass locally on the merged tree.

alexey-milovidov and others added 2 commits October 6, 2026 19:49
…e outer version

`mergeSerializedDuplicate` deserialized the duplicate entry with `std::nullopt`, so for a
versioned nested function such as `uniqMap` the duplicate was read in the default version
format rather than the state's version. Pass the outer `version` through and add a regression
for `uniqMap` states of versions 0 and 1 with duplicate `NaN` keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: Logical error: 'file_infos.file_names.size() == file_infos.meta_by_inode.size()' in StorageFileLog::updateFileInfos (Stress test (amd_tsan)): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123449&sha=e5d0346afdc024101480f95a35a878b7c207cd2e&name_0=PR&name_1=Stress%20test%20(amd_tsan) and provide a fix in a separate PR. If the fix is already in progress, link it here. It is unrelated to this PR (-Map combinator): CIDB shows it on master since 2026-10-03 (Stress test (arm_asan_ubsan)) and in other PRs (#117153, #116101, #119672, #119463, #115907, #120518, #120632), which started right after FileLog changes such as #123590 were merged. #123673 (hard links in the watched directory) may be related, but I did not confirm that it fixes this.

I merged master again (3a3aefc).

@groeneai

groeneai commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

The fix is my #123673. This is the same defect as on #115907.

The aborting table is file_log__fuzz_8, the AST fuzzer's copy of file_log from 05318_file_log_one_bad_file. That test came with my #123595 (merged 2026-10-03 20:00 UTC), and the first hit is on master at 2026-10-03 22:24 UTC, before #123590 merged. The fuzzer creates the copy during the test's CREATE, before the test removes the target of the broken.jsonl symlink. The copy has no views, so it reads nothing until the fuzzed SELECT countIf(a = 601) FROM merge(toFixedString('.*', 2)). That batch has one event, bad.jsonl added. One added file can leave 3 names and 2 metas only if it got an inode the table already holds: here the deleted target's inode number, which the copy still keeps for broken.jsonl, so the DW_ITEM_ADDED branch overwrites that meta_by_inode entry.

#123673 drops a symlink's read name once the link no longer resolves to its inode, so the new file takes the inode alone. A deterministic repro of this state (a FileLog table without views, the symlink target deleted and recreated, a file with the old inode moved in, then a direct SELECT) aborts with this assertion on master debug. On #123673 merged with master (5d9d9495) it returns the rows and the server stays up. The current head 04058cac only adds a docs sentence. The PR is waiting for review.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai. So the StorageFileLog::updateFileInfos assertion is tracked by #123673, and it is unrelated to this PR. The current head (3a3aefc) is green and has no open review threads, so nothing more is needed here for now.

@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.

Sounds good.

@alexey-milovidov alexey-milovidov self-assigned this Oct 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit 2c3970d Oct 8, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the continue-pr-56335-map-combinator-non-map-columns branch October 8, 2026 00:38
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 8, 2026
davenger pushed a commit that referenced this pull request Nov 15, 2026
The `-Map` form with the key as the last argument comes from #123449, which is not in
26.8. 05485 builds its `-Map` state from a `Map` argument instead, and 05484 drops
its `contingencyMap` case, which has no equivalent without that form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
davenger pushed a commit that referenced this pull request Nov 15, 2026
The `-Map` form with the key as the last argument comes from #123449, which is not in
26.9. 05485 builds its `-Map` state from a `Map` argument instead, and 05484 drops
its `contingencyMap` case, which has no equivalent without that form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

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

Labels

comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). 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.

Map combinator with 2+ argument aggregate functions hard to use (argMaxMap)

4 participants