Repository navigation
Fix alias error in distributed calls, simplification for nanoseconds in Iceberg - #2749
Conversation
`JoinedTables` only reads the outer table function, so an old-analyzer global JOIN failed with "No alias for subquery or table function in JOIN". The inner alias stays for the query sent to the remote initiator. https: //github.com//issues/2748 Co-authored-by: Cursor <[email protected]>
…conds Scale-6 bounds in the normal range were dropped, so min/max pruning skipped every `timestamp` file. Values above `1e18` are still converted from nanoseconds, and `(1e16, 1e18]` still fails open. https: //github.com//issues/2747 Co-authored-by: Cursor <[email protected]>
Appendix D already sets the unit from the field type. `DateTime64(6)` stays microseconds and `DateTime64(9)` stays nanoseconds. https: //github.com//issues/2747 Co-authored-by: Cursor <[email protected]>
The decoder reads bounds at the type scale. A `timestamp` column whose bounds are nanoseconds is corrupt data, so those tests are not required. Co-authored-by: Cursor <[email protected]>
CI triage for
|
| Check | Failure | Verdict |
|---|---|---|
| Stateless (amd_asan_ubsan, distributed plan, parallel, 2/2) | 05387_s3_cluster_remote_initiator_keeps_stripped_join |
Pre-existing on antalya-26.6 |
| Stateless (amd_binary, cas s3 storage, parallel) | Server died: GroupingAggregatedTransform pushed bucket 4 twice |
Known upstream crash, not related to this PR |
| Stateless (amd_asan_ubsan, cas s3 storage, parallel, 1/2) | Server died: GroupingAggregatedTransform pushed bucket 3 twice |
Same as above |
| Stress test (amd_debug, cas s3 storage) | Test script failed, script exit code: 1 |
Infra: the stress harness timed out |
1. 05387_s3_cluster_remote_initiator_keeps_stripped_join (pre-existing)
The CI report's randomized-settings diagnosis:
Runs: 25, Failed: 25 (same randomized settings)
Runs: 34, Failed: 0 (without randomization)
Culprit settings: --prefer_localhost_replica 0
The old (old analyzer) half passes. The analyzer half (query 7) fails on the remote initiator:
Code: 499. DB::Exception: Received from localhost:9000. ... Failed to get object info: No response body.. HTTP response code: 403.
Please check your AWS credentials and permissions: while reading '05387_test_xafu307b.tsv' in bucket 'test' on disk 'StorageS3': While executing Remote. (S3_ERROR)
... StorageObjectStorageStableTaskDistributor::getMatchingFileFromIterator <- TaskDistributor <- RemoteQueryExecutor::processReadTaskRequest
Why it's not this PR: #2713 is an unrelated backport (Nullable ALTER) at 5284d10. The same test fails there in the same suite, with the same 403 and the same culprit setting (Runs: 26, Failed: 26 → Culprit settings: --prefer_localhost_replica 0). This PR doesn't touch the test.
What to do: this PR works on the remote-initiator path, so you may want to deal with it here, though it doesn't block the PR. The 403 comes from the read-task callback on the remote initiator, so with prefer_localhost_replica = 0 the S3 credentials apparently don't reach the key iterator there. I haven't confirmed that. Options:
- Real fix: find out why the credentials are lost on the analyzer path when the hop goes over TCP rather than local, probably a separate issue.
- Stop-gap: pin
prefer_localhost_replica = 1in the test'sSETTINGS, with a comment linking the issue, so the suite stops failing on every PR.
2. GroupingAggregatedTransform pushed bucket N twice (known upstream crash)
The server aborted on a logical error in both CAS-S3 stateless jobs:
Logical error: 'GroupingAggregatedTransform pushed bucket 4 twice'.
src/Processors/Transforms/MergingAggregatedMemoryEfficientTransform.cpp:63:15: DB::GroupingAggregatedTransform::pushData(...)
src/Processors/Transforms/MergingAggregatedMemoryEfficientTransform.cpp:123:9: DB::GroupingAggregatedTransform::tryPushTwoLevelData()
- This is the memory-efficient two-level aggregation merge. The PR changes
IStorageCluster::convertToRemote(an alias onremote()) and the Iceberg DateTime64 bound decoding, and neither path is involved. - It's an open upstream issue that also shows up on master and release branches: [CI crash] GroupingAggregatedTransform pushData failure ClickHouse/ClickHouse#115986 ("[CI crash] GroupingAggregatedTransform pushData failure"). See also the related Logical error: 'Bucket 58 is pushed twice' (STID: 2508-468c) ClickHouse/ClickHouse#116483.
- The crash happened late in the run (8439 tests had already passed in the amd_binary job).
- I didn't see this crash in the CAS-S3 jobs of Antalya 26.6 Backport of #102156 - Fix Nullable(X)->Y cross-type ALTER MODIFY COLUMN #2713 or Merge antalya-26.6-20261008 into antalya-26.6 #2644, so it's rare rather than constant. Hitting it in 2 jobs of one run is unlucky, but the stack has nothing to do with this diff.
What to do: safe to re-run.
3. Stress test (amd_debug, cas s3 storage) (infra/harness)
Every server-health result was OK (Server successfully started, No lost s3 keys, No SharedMergeTree lost forever), and fatal.log is empty. The only failure is the pre-stress sanity run of 00001_select_1 and 00234_… in --replicated-database mode. Both tests passed in about 18s, but the whole clickhouse-test call overran its 180s wrapper timeout:
[2 / 2] 00001_select_1: [ OK ] 1.76 sec. 2 tests passed ... 17.98 s elapsed
subprocess.TimeoutExpired: Command '/usr/bin/clickhouse-test --stress-tests --cas-s3-storage ... --replicated-database --database test_5 ...' timed out after 180 seconds
That's slow setup or teardown of the replicated database on CAS S3, not a server problem.
What to do: safe to re-run.
Sources: the CI report (result_pr.json) for a24fa31, plus those of #2713 (5284d10) and #2644 (97ac101) for comparison. No local build or test run; this is from CI evidence only.
…ry plan With `serialize_query_plan=1` and `prefer_localhost_replica=0`, `ClusterProxy::SelectStreamFactory` builds a local `QueryPlan` for each shard and sends it over the native protocol via `ReadFromTableFunctionStep`. The table function AST was formatted with secrets hidden (`show_secrets_=false`), so a function like `s3`/`s3Cluster` arrived on the executing shard with its access key or secret replaced by the `[HIDDEN]` literal, which the shard then used to sign requests, failing with `403 Forbidden`. This AST only travels inside the cluster and is never shown to the user, so format it with `formatWithSecretsOneLine` instead, matching the plain-SQL distributed query path (`IStorageCluster::readFromRemoteInitiator`, `ClusterProxy::rewriteSelectQuery`). Co-authored-by: Cursor <[email protected]>
|
Add potential fix for |
|
|
PR #2749 Audit Review
VerdictOne High, one Medium. No Low. The alias is copied onto Iceberg A serialized query plan now sends the table function with its credentials. The shard can sign an What the change doesThree independent edits. Remote initiator alias. Iceberg bounds. Plan text for a table function. When FindingsSilent wrong pruningHigh: nanosecond min/max on an Iceberg
Join is not global on the fallback pathMedium: old-analyzer
What was checked and found cleanThe alias reaches both places that read it. Spec-correct bounds match Appendix D. The plan string uses the same quoting as the SQL path.
Coverage
Deferred. The integration join test was not re-run here, so the 2-out-of-3 replica failure is from the code path. No test in the diff forces Operational readinessPersona. Operator querying Iceberg, and anyone running an old-analyzer global join through 1. A 2026 filter on
|
`convertToRemote` sent the local table name to one replica, so a replica without that table returned `UNKNOWN_TABLE`. `RIGHT`, `FULL`, and `PASTE` still stay on the initiator. Co-authored-by: Cursor <[email protected]>
|
Shit. |
Bounds at or below `1e18` stay microseconds, so ordinary `timestamp` pruning still runs. The previous threshold dropped those bounds and skipped the column. Co-authored-by: Cursor <[email protected]>
…1e18` Bounds below `1e16` stay microseconds and bounds at or above `1e18` are nanoseconds. A file in the middle band is pruned only when the predicate misses both readings. Co-authored-by: Cursor <[email protected]>
Optional fields are `Nullable(DateTime64)`, so the outer type check skipped both units between `1e16` and `1e18`. Co-authored-by: Cursor <[email protected]>
…nd `1e18` That band can be either unit, so the shortcut must read the file. Pruning and the shortcut share the same two thresholds. Co-authored-by: Cursor <[email protected]>
The reader already loads these bounds as little-endian `long`s. `test_minmax_pruning` now checks Spark-written `timestamp` values with `unix_micros`. Co-authored-by: Cursor <[email protected]>
|
Some compromise. Size effect - cons column optimization does not work anymore for |
|
@codex review |
Codex Review SummaryThis 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
Here are some automated review suggestions for this pull request.
Reviewed commit: 12930fc83b
ℹ️ 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".
| if (scale == 6) | ||
| { | ||
| if (!magnitudeExceeds(unscaled, nanoseconds_lower_threshold)) | ||
| return std::nullopt; | ||
|
|
||
| unscaled = nanosecondsToMicrosecondsForBound(unscaled, lower_bound); | ||
| if (!icebergTimestampMagnitudeBelow(unscaled, iceberg_timestamp_nanoseconds_lower_threshold)) | ||
| unscaled = nanosecondsToMicrosecondsForBound(unscaled, lower_bound); |
There was a problem hiding this comment.
Keep near-epoch nanosecond bounds from becoming constants
When an Iceberg timestamp manifest contains the nanosecond statistics this compatibility code is intended to handle, dates close to the epoch have |ticks| < 1e18, so this branch now returns the raw nanosecond count as a microsecond value. For a file whose timestamp is constant, DataFileMetaInfo accepts that point range and StorageObjectStorageSource substitutes it without reading the Parquet column; for example, 86400000000000 ns (1970-01-02) is returned as a timestamp in 1972. These ambiguous bounds need to fail open rather than becoming a constant.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
86400000000000 is less than 1e16, must be interpreted as microsoconds only.
Test is fixed to avoid misunderstanding.
| const bool allow_microseconds = icebergTimestampMagnitudeBelow(*lower_ticks, iceberg_timestamp_nanoseconds_lower_threshold) | ||
| && icebergTimestampMagnitudeBelow(*upper_ticks, iceberg_timestamp_nanoseconds_lower_threshold); | ||
| const bool allow_nanoseconds = !icebergTimestampMagnitudeBelow(*lower_ticks, iceberg_timestamp_microseconds_only_threshold) | ||
| && !icebergTimestampMagnitudeBelow(*upper_ticks, iceberg_timestamp_microseconds_only_threshold); |
There was a problem hiding this comment.
Preserve the nanosecond interpretation below 1e16
For timestamp-schema manifests carrying nanosecond statistics, valid near-epoch values can have both bounds below 1e16 (for example, 1970-01-02 is 8.64e13 ns). Here such a pair enables only the microsecond range, so the manifest pruner compares the predicate against a date years later and can discard a file containing matching rows. The removed near-epoch regression cases exercised exactly this scenario; pruning must fail open or retain the nanosecond interpretation for this band.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
It's an heuristic for already incorrectly written tables, where bounds in nanoseconds, when columns in microseconds.
For this tables pruning and constant column optimization must be turned off. ClickHouse can't detect and recognize this cases in 100%. If we though that any time less 1e16 can be nanoseconds, all normal tables with microseconds can't be pruned correctly.
`86400000000000` is `1972-09-27` as microseconds. The test locks that single range so it is not read as `1970-01-02` nanoseconds. Co-authored-by: Cursor <[email protected]>
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
PR #2749 Audit Review
VerdictThree Medium findings, one Low. No High. The Confirmed defectsOld-analyzer global joinMedium: a join alias that matches a temporary table joins that table instead of the broadcast rows.
if (!mutable_context->tryResolveStorageID(StorageID{"", name}, Context::ResolveExternal))
mutable_context->addExternalTable(name, std::move(*holder));
Medium: a table function on the right side fails with
Medium: global join mode rewrites every local
Iceberg timestamp boundsLow: min/max bounds that differ by exactly 1000 collapse into one constant timestamp.
Coverage summaryScope reviewed: the PR diff at Categories failed:
Categories passed:
Categories N/A:
Assumptions/limits: static only. The integration test in |
A table function on the right is read through `interpretSubquery`. `IN some_table` runs on the initiator, and `IN (SELECT 1)` stays on the replica. Co-authored-by: Cursor <[email protected]>
If either bound is below `1e16`, both stay microseconds. Otherwise a bound at or above `1e18` makes both nanoseconds. Co-authored-by: Cursor <[email protected]>
The interpreter rewrites the same tree that is sent, so it must not turn every subquery into `globalIn`. Co-authored-by: Cursor <[email protected]>
`deserializeDateTime64MinMaxRanges` already returns two ranges for the middle band. Co-authored-by: Cursor <[email protected]>
PR #2749 Audit Review
VerdictNo confirmed defects in reviewed scope. Confirmed defectsNo confirmed defects in reviewed scope. Coverage summaryScope reviewed: the PR diff at Assumptions/limits: static only. The new cases in |
PR #2749 CI Verification
VerdictOne failure is from this pull request. The other red jobs are not.
Iceberg, Parquet, Swarms, OAuth, and S3 export regression jobs passed. A second attempt of this workflow was already in progress when this report was written. The verdict below is attempt 1 only.
How the list was reducedFour GitHub jobs failed. The report lists five rows because the CAS job records both the logical error and
|
The integration container has no `clickhouse-client` on `PATH`. Co-authored-by: Cursor <[email protected]>
|
@alsugiliazova |
`numbers(2).number + 1` is `UInt64`, while the Iceberg column is `Nullable(Int32)`. Compare `tag` so the old analyzer accepts the key. Co-authored-by: Cursor <[email protected]>
… is chosen. A choice of node1 executes in-process and writes no non-initial `query_log` row. Co-authored-by: Cursor <[email protected]>
The replica receives `IN ((SELECT 1) AS _subqueryN)`, so the check looks for `(SELECT 1)`. Co-authored-by: Cursor <[email protected]>
`QueryFinish` can still be queued when the first `SYSTEM FLUSH LOGS` returns. Co-authored-by: Cursor <[email protected]>
|
Test issue again, fix in progress |
`is_initial_query = 0` only sees the replica `DESCRIBE`. The `SELECT` is a different `query_id` and still contains `(SELECT 1)`. Co-authored-by: Cursor <[email protected]>
|
Testa are passed |
|
@ianton-ru pls don't forget to add |
|
@zvonand port for 26.8 is on the way |
|
@ianton-ru you will do the port manually? |
|
@zvonand Yes, I will. |
|
Port is in #2749 |
Solved #2748
Solved #2747
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix alias error in distributed calls, simplification for nanoseconds in Iceberg
Documentation entry for user-facing changes
Solved #2748 - restore alias in distributed query (changes in
src/Storages/IStorageCluster.cpp)Solved #2747 - changes in #2239 for nanoseconds were overcomplicated, and broke work for microseconds. Partially reverted.
CI/CD Options
Exclude tests:
Regression jobs to run: