Repository navigation
Support aggregate function states in Parquet and Iceberg - #2680
Conversation
|
Backporter: cherry-pick conflicts resolved by AI Conflicted files:
Commits:
|
|
Can you add a test like the below? The reason is I also need to implement some annotated types and AI is saying that 3rd party tools can overwrite your annotation
|
@arthurpassos Added this in clickhouse-regression and ran it against this PR's build. You were right, the annotation doesn't survive. Here's what I tried:
Reading works fine. Spark and PyIceberg both see the states as binary, and if you CAST back to the AggregateFunction type in ClickHouse you get the right results. But anything that writes to the table drops the field key, since it isn't in the spec. If the type needs to survive other writers, I think it has to go somewhere they keep, like table properties. Here is the main file you would want to look at for for ths: https://github.com/Altinity/clickhouse-regression/blob/main/iceberg/tests/iceberg_engine/aggregate_states/annotation_survival.py |
Defects in #2680Head MediumAn attached Iceberg table checks Attach an Iceberg table with a LowIceberg accepts a On a LowIceberg resolves
|
The field-level `clickhouse.type` key was dropped by REST catalogs and by commits from other engines, so aggregate-state columns silently read back as `String` or their storage type. Annotations are now table properties `clickhouse.type.<field-id>.<schema-id>`; a field's type in a schema is the entry with the greatest schema id not above it, so older schemas keep theirs. - Pass annotations explicitly to `IcebergSchemaProcessor::addIcebergTableSchema` and store them per schema; re-parse a schema transactionally when they change. - Validate an annotation exactly against the field's Iceberg type. - Ignore `clickhouse.type.*` properties that are not annotation keys. - Register metadata schemas before maintenance operations walk manifests. - Send property changes with REST `updateSchema`, forward properties on create. - Move the docs sections into the engine and format `Documentation` sources. Related: #2680 (comment)
`IcebergSchemaProcessor::getFieldType` is compiled without Avro but calls `getIcebergType` and `icebergTypesEqualIgnoringIds`, which were declared and defined only under `USE_AVRO`. Neither depends on Avro, so move them out of the guard. CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2680&sha=bf6ff058da7117bbd3c4ff1bc9bbb499b2236d38&name_0=PR&name_1=Fast%20test PR: #2680
CI triage for
|
| Check | Failing tests | Verdict |
|---|---|---|
| Integration (amd_asan_ubsan, db disk, old analyzer, 5/8) | all 21 of test_storage_iceberg_with_spark/test_export_partition_iceberg.py |
Already failing on the base branch |
| Integration (… 6/8) | 17× test_database_backup/test.py |
Already failing on the base branch |
| Integration (… 7/8) | 2× test_backward_compatibility/test_custom_s3_disk_remote_url_allow_hosts.py |
Already failing on the base branch |
| Stateless (amd_debug, parallel) | 05387_cas_publish_counts_replicated |
Flaky (CAS test, passed 16/16 reruns) |
| Regression release oauth | /oauth/access control, /oauth/groups/* |
Already failing on the base branch |
| Regression release swarms | cluster discovery/…wrong cluster name, node failure/cpu overload* |
Already failing on the base branch |
| Regression release s3_azure_1 | /s3/azure/part 1/disk/remote host filter, …/disk/syntax |
Already failing on the base branch |
How I checked: I compared against the praktika result_pr.json reports of four unrelated open PRs on antalya-26.8: #2703, #2715, #2729, #2735. All four have the same 21 test_export_partition_iceberg failures, plus the test_database_backup and test_custom_s3_disk_remote_url_allow_hosts failures in the same shards. On their GitHub checks, oauth and swarms regression fail on #2703, #2715, #2729 and #2735, and s3_azure_1 fails on #2735.
The checks that cover this feature passed: Regression iceberg_1 / iceberg_2, integration shards 1–4 and 8/8, and the rest of stateless amd_debug parallel (13638 passed). That includes the new 04673_parquet_aggregate_function_state and 05428_iceberg_… tests; the report lists only non-OK tests, and these aren't in it.
1. test_export_partition_iceberg.py (21/21): already failing on the base branch
Every test fails while setting up the table, on the CREATE TABLE … ENGINE=IcebergS3(s3, …) statement. It never gets to any export or aggregate-state code:
Code: 497. DB::Exception: default: Not enough privileges. To execute this query, it's necessary to have the grant SHOW NAMED COLLECTIONS SECRETS ON s3.
10. src/Storages/NamedCollectionsHelpers.cpp:228:18: DB::checkNamedCollectionOverride(...)
12. src/Storages/ObjectStorage/StorageObjectStorageConfiguration.cpp:114:38: DB::StorageObjectStorageConfiguration::initialize(...)
This is the named-collection override access check against the test's default user. The same 21 tests fail with the same shard layout on #2703, #2715, #2729 and #2735. To fix it on the base branch, the test user needs SHOW NAMED COLLECTIONS SECRETS on s3, or the test config needs to allow overriding the collection without it. That belongs in a separate fix on antalya-26.8, not in this PR.
2. test_database_backup/test.py (17): already failing on the base branch
The first failure is a server abort. All the others are Connection refused because the instance is dead:
<Fatal> : Logical error: 'Chosen multipart upload for an empty file. This must not happen'.
It is a CAS backup to backup_disk_s3_plain_rustfs (test_database_backup_database[cas_policy-Disk('backup_disk_s3_plain_rustfs', …)]). The same tests fail on all four comparison PRs. None of that code is in this PR.
3. test_custom_s3_disk_remote_url_allow_hosts.py (2): already failing on the base branch
Exception: Timed out while waiting for instance `node' with ip address 172.16.5.6 to start.
The same 2 tests fail on #2703, #2715, #2729 and #2735.
4. 05387_cas_publish_counts_replicated: flaky
-replicated_merge 1 0 3
+replicated_merge 0 0 3
The runner's own diagnosis: "Runs: 16, Failed: 0, Passed: 16 … The failure is not reproducible." The test checks CAS publish counters for replicated merges, which this PR doesn't touch. Safe to re-run.
5. Regression oauth / swarms / s3_azure_1: already failing on the base branch
The failing scenarios are OAuth groups/access control, swarm cluster discovery and CPU overload, and the Azure disk remote host filter / syntax. They have nothing to do with Parquet or Iceberg type mapping, and the same suites are red on #2735 (all three) and #2703, #2715, #2729 (oauth and swarms).
Other notes
- Several jobs show as
DROPPEDin the praktika report andskippingon GitHub, so they didn't run for this commit: stateless amd_debug sequential, distributed plan, CAS storage suites, Stress (amd_debug/asan), AST fuzzer, BuzzHouse, SQLLogic/SQLStorm, Install packages and Compatibility check. The report gives no reason. If you want that coverage before merging, a re-run is worth trying. - Suggested next step: nothing to change in this PR. The
test_export_partition_icebergaccess error is red on everyantalya-26.8PR, so it deserves its own fix on the base branch.
Sources: PRs/2680/d2ee51d…/result_pr.json, plus the same reports for #2703, #2715, #2729 and #2735, and the gh run view --log-failed output of the regression jobs.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
ClickHouse/src/Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.cpp
Lines 951 to 958 in d2ee51d
When a schema evolution both changes a SimpleAggregateFunction annotation and creates a new schema ID—for example, changing sum to max while repositioning the column—the Iceberg primitive type remains identical and this branch passes the old DAG input through unchanged. Because IDataType::equals ignores the custom SimpleAggregateFunction name, old data files retain the old function/type while the new schema expects the new annotation, producing an incorrect transformed header or wrong aggregate semantics. Compare the resolved annotated types here and add a cast/retyping node whenever their custom names differ.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Segfault reading an
|
This comment was marked as outdated.
This comment was marked as outdated.
Bounds are stored in the Iceberg encoding of the field, but were decoded with the annotated ClickHouse type: - `AggregateFunction`: `ColumnAggregateFunction::insertData` treated the bound bytes written by Spark as a state pointer, so reading the table crashed in `UniquesHashSet::write`. - `SimpleAggregateFunction` over `DateTime64(3)` or `Time`: microsecond bounds were read at the annotated scale or width, so `SELECT` returned `9999-12-31 23:59:59.000` through the min/max read optimization and min/max pruning skipped files with matching rows. `ManifestFilesPruner` and `DataFileMetaInfo` now ignore bounds of fields for which `IcebergSchemaProcessor::hasClickHouseTypeAnnotation` is true. Related: #2680 (comment)
`IcebergSchemaProcessor::addIcebergTableSchema` now requires the `ClickHouseTypeAnnotations` argument. Use the existing helper `addIcebergTableSchemasFromMetadata`, which passes annotations taken from the metadata. https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2680&sha=latest&name_0=PR&name_1=Build%20(amd_debug) Related: #2680
This comment was marked as outdated.
This comment was marked as outdated.
|
@codex review |
This comment was marked as outdated.
This comment was marked as outdated.
|
@codex review |
abdd14c to
7917eed
Compare
This comment has been minimized.
This comment has been minimized.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c371eecacf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`MergeTreePartitionExportScheduler::tryCommit` resolved the destination table with the storage context before applying the settings persisted by the initiating query, so a `DataLakeCatalog` Iceberg destination could fail with `SUPPORT_IS_DISABLED` on commit when `allow_aggregate_function_states_in_open_formats` was enabled only at the query level. #2680 (comment)
…ollback When `current-schema-id` points to a schema below the highest one, `addCurrentSchema` copied its effective annotations into the new `max_id + 1` schema. An inherited annotation that became stale after another engine evolved the field was then recorded explicitly, and the next read rejected the schema with `ICEBERG_SPECIFICATION_VIOLATION`. Such annotations are now dropped. Related: #2680 (comment)
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The test reads the annotated table through `icebergLocal`, which takes the setting from the query. Since the setting is decided per table and is disabled by default, the `clickhouse.type` annotation was ignored and `x` was read as `DateTime64(6)`. https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2680&sha=fc5771e291f5d01f28d8ccc5325c781afa9ee335&name_0=PR&name_1=Stateless+tests+%28amd_asan_ubsan%2C+distributed+plan%2C+parallel%2C+selected+tests%29&name_2=Tests #2680
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a721d1835b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Without `allow_aggregate_function_states_in_open_formats`, `addCurrentSchema` keeps the annotations of the previous schema as they are instead of parsing them, so a malformed or unknown annotation no longer blocks `ADD`, `DROP`, `RENAME` or `MODIFY COLUMN`. #2680 (comment)
Store `AggregateFunction` states as binary in Parquet files and Iceberg tables, and record the ClickHouse types of `AggregateFunction` and `SimpleAggregateFunction` columns in the `clickhouse.column_types` Parquet file metadata or the `clickhouse.type.<field-id>.<schema-id>` Iceberg table properties. The recorded types are applied only with the new setting `allow_aggregate_function_states_in_open_formats`. Without it, columns have their plain types (a state column is `String`), and writing a state throws `SUPPORT_IS_DISABLED`. A table takes the setting from its own `SETTINGS`, or the server's value without one; the query's value applies only to table functions and `DataLakeCatalog` tables. Closes: #2206
a2e3a5b to
811893a
Compare
CI triage for #2680 (
|
| Check | Classification | PR-caused? |
|---|---|---|
| Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/8) | slow runner: session timeout plus one load-sensitive test | ❌ no (high confidence) |
| Grype Scan (keeper, server-alpine) | pre-existing CVEs in the base images | ❌ no |
| DCO | commit has no Signed-off-by |
PR is the aggregate gate and only reflects the failures above. Every build, unit, stateless and other integration shard that ran is green. All the new Parquet/Iceberg aggregate-state stateless tests and unit tests passed.
1. Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/8): ERROR
FAILED test_filesystem_cache/test.py::test_concurrent_eviction[lru]
E Code: 209. DB::NetException: Timeout exceeded while reading from socket (peer: 127.0.0.1:9000, ..., 10000 ms) (SOCKET_TIMEOUT)
!!!!!!! xdist.dsession.Interrupted: session-timeout: 9000.0 sec exceeded !!!!!!!
- What happened: the shard ran all 1389 tests (the last one passed at
[100%]at 13:12:16). pytest started at 10:40:10, so the run took about 2h32m and went over the 9000 s session limit. The timeout fired after the work was already done; no test hung. - The only real test failure is
test_concurrent_eviction[lru]. It runsclickhouse benchmark --concurrency 100against a plain MergeTree table on the filesystem cache, and one query hit the client's 10 s receive timeout. The[slru]variant right after it passed. This code path doesn't touch Parquet, Iceberg or AggregateFunction serialization. - Why I think it's not this PR:
- The same shard on Parquet hedged reads #2979 (same base, same 26.8.39 version) ran 1387 tests in about 1h50m and passed. In that run
test_concurrent_eviction[lru]took 7 s; here it failed after 20 s. - The test set is the same apart from the 2 new
test_aggregate_function_states.pytests, which took about 50 s in total and passed. - The whole shard was slower, not one test: the 50% mark came after 58 min here vs 41 min on Parquet hedged reads #2979. Other shards of this PR vary in both directions against Parquet hedged reads #2979: 4/8 took 5059 s vs 6298 s, and 6/8 took 7481 s vs 6361 s. That points to a slow runner, not a PR-wide regression.
- Every Iceberg test in the shard passed (771
test_storage_iceberg_with_sparkcases), along withtest_export_partition_to_iceberg/test_schema_match.py,test_export_merge_tree_part_to_icebergandtest_database_iceberg.
- The same shard on Parquet hedged reads #2979 (same base, same 26.8.39 version) ran 1387 tests in about 1h50m and passed. In that run
- Next step: re-run the failed job. If 5/8 hits the session limit again, check whether this PR makes the Iceberg integration tests measurably slower under ASan. I couldn't measure per-test durations directly in this job.
2. Grype Scan (clickhouse-keeper, clickhouse-server …-alpine): fail
Grype Scan Completed with 5 high/critical vulnerabilities
- Pre-existing: unrelated antalya-26.8 PRs Parquet hedged reads #2979 and Parquet v3: add read back-pressure for the compressed prefetch stage #2977 get exactly the same result: keeper and server-alpine both fail with 5 high/critical, and the non-alpine server passes with 0. These come from the base images and packages, not from anything this PR changes.
- Next step: none on this PR. It needs a base-image bump on
antalya-26.8.
3. DCO: fail
- This PR's only commit,
811893a3bb(authorAndrey Zvonov <…users.noreply.github.com>), has noSigned-off-by:trailer. DCO status varies across other branch PRs (Parquet hedged reads #2979 passes, Parquet v3: add read back-pressure for the compressed prefetch stage #2977 fails), so it depends on the PR, not the branch. - Fix: run
git commit --amend -s --no-editand force-push the branch. I don't force-push, so the author needs to do it. Alternatively, a maintainer can override DCO if backport PRs are exempt.
Summary: nothing to fix in the code. Re-run Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/8), sign off the commit (or get a DCO override), and treat Grype as the known base-image issue on antalya-26.8.
|
I reran my tests against the latest changes in the PR and made some adjustments.. I have two questions. Table function INSERT goes through without the settingWithout SET allow_insert_into_iceberg = 1;
CREATE TABLE t (k Int32, u AggregateFunction(uniq, UInt64), s SimpleAggregateFunction(sum, Int64))
ENGINE = IcebergLocal('/tmp/aggprobe/t/') SETTINGS allow_aggregate_function_states_in_open_formats = 1;
INSERT INTO FUNCTION icebergLocal('/tmp/aggprobe/t/') (k, u, s)
SELECT toInt32(number % 2), uniqState(toUInt64(number % 23)), sumSimpleState(toInt64(number))
FROM numbers(200) GROUP BY 1; -- no setting, succeeds
SELECT k, uniqMerge(u), sum(s) FROM t GROUP BY k ORDER BY k; -- merges correctlyIs that intended? It looks like states are only refused when the column is typed Refused Parquet write leaves an empty fileThis write is refused with INSERT INTO FUNCTION file('/tmp/aggprobe/f.parquet', Parquet)
SELECT toInt32(number % 2) AS k, uniqState(toUInt64(number % 23)) AS u
FROM numbers(10) GROUP BY k;Reading the file afterwards fails with |
|
There is also this from the couple of iterations of audit review. Defects in #2680Head 1. A bad inherited annotation makes the table unreadableSeverity: Medium A Schema 0 has SELECT x FROM tResult: the query throws while parsing the schema. Expected: 2. ALTER with the setting off freezes a stale annotationSeverity: Medium With the setting off, CREATE TABLE t (k Int32, x SimpleAggregateFunction(max, Int32))
ENGINE = IcebergLocal('/path/t/');
ALTER TABLE t ADD COLUMN y Nullable(Int32);
ALTER TABLE t ADD COLUMN z Nullable(Int32);Promote ALTER TABLE t ADD COLUMN w Nullable(Int32);
SELECT x FROM icebergLocal('/path/t/')
SETTINGS allow_aggregate_function_states_in_open_formats = 1Result: Expected: 3. Making an annotated Tuple optional breaks old filesSeverity: Medium The evolution transform checks the old annotation against the new CREATE TABLE t (t Tuple(x AggregateFunction(uniq, UInt64)))
ENGINE = IcebergLocal('/path/t/')
SETTINGS allow_aggregate_function_states_in_open_formats = 1;
INSERT INTO t SELECT tuple(uniqState(toUInt64(1)));In the next metadata version, set SELECT t FROM tResult: Expected: the inserted row is returned. 4. A cluster read turns the setting off for the whole querySeverity: Medium If the Iceberg table's setting is off and the query turns it on, the cluster rewrite writes
SELECT uniqMerge(u)
FROM iceberg_off AS t, file('states.parquet') AS f
SETTINGS
allow_aggregate_function_states_in_open_formats = 1,
object_storage_cluster = 'test_cluster_two_shards_localhost'Result: on the shards Expected: |
|
As for the first comment:
|
|
as for the second commit: none of these are blockers. they can go in a follow-up PR |
|
Good, I don't see any issues with the CI/CD either - marking as |
Store
AggregateFunctionstates as binary in Parquet files and Iceberg tables, and record the ClickHouse types ofAggregateFunctionandSimpleAggregateFunctioncolumns in theclickhouse.column_typesParquet file metadata or theclickhouse.type.<field-id>.<schema-id>Iceberg table properties. The recorded types are applied only with the new settingallow_aggregate_function_states_in_open_formats. Without it, columns have their plain types (a state column isString), and writing a state throwsSUPPORT_IS_DISABLED. A table takes the setting from its ownSETTINGS, or the server's value without one; the query's value applies only to table functions andDataLakeCatalogtables.Closes: #2206
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Parquet files and Iceberg tables can now store
AggregateFunctionstates andSimpleAggregateFunctioncolumns, and ClickHouse reads them back with their original types. This requires the new settingallow_aggregate_function_states_in_open_formats, disabled by default, which a table takes from its ownSETTINGSor the server's settings, not from the query.CI/CD Options
Exclude tests:
Regression jobs to run: