Repository navigation
Support DateTime64 in sequenceMatch, sequenceCount and sequenceMatchEvents - #118427
Conversation
…vents
SELECT sequenceMatch('(?1)(?t<1296000)(?2)')(ts, e = 1000, e = 2000) FROM t
Code: 43. DB::Exception: Illegal type DateTime64(6) of first argument of
aggregate function sequenceMatch, must be DateTime. (ILLEGAL_TYPE_OF_ARGUMENT)
A `DateTime64` timestamp had to be wrapped in `toDateTime`, throwing away the
sub-second part that decides the order of events within a second.
Instantiate the family with `DataTypeDateTime64::FieldType` for the column type and
`Int64` for the stored timestamp, reading the tick value out of the `ColumnDecimal`.
Timestamps are compared at the column's own precision, so events sharing a second
still order by their sub-second part.
The durations in the `(?t...)` conditions of the pattern stay in seconds for every
timestamp type: they are converted to the argument's ticks once, when the pattern is
parsed, so the same pattern keeps its meaning when a column changes from `DateTime`
to `DateTime64` or between two `DateTime64` scales. A duration whose tick value does
not fit `Int64` is rejected with `ARGUMENT_OUT_OF_BOUND` instead of wrapping.
`PatternAction::extra` becomes signed, because a `DateTime64` timestamp can be
negative and `base_it->first + extra` would otherwise be evaluated in unsigned
arithmetic and wrap around zero.
`windowFunnel` still rejects `DateTime64`; its data structures cast timestamps to
`UInt64` in several places and are left for a separate change.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [6db11b7] Summary: ✅
AI ReviewSummaryThis PR extends Final Verdict
LLVM Coverage ReportMeasured on commit 6db11b7.
Changed lines: Changed C/C++ lines covered: 70/71 (98.59%) · Uncovered code |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionSequenceMatch… |
1.80 MiB | 2.10 MiB | +310.81 KiB (+16.88%) |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
12 translation units recompiled, 42 s compile time in total, 12 of them have a recent master baseline.
`GROUP BY type`, where `type` is an alias of `toTypeName(ts)`, is only accepted by the analyzer. The old analyzer does not treat `toTypeName(ts)` in the `GROUP BY` as covering `ts`, and rejects the query with `Column ts is not under aggregate function and not in GROUP BY` (`NOT_AN_AGGREGATE`), so the test failed in `Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, parallel, 1/3)`. The type is only wanted as a label for the row, so take it from `any` instead and drop the `GROUP BY` altogether. Every query still returns exactly one row, and the reference is unchanged. Verified with `enable_analyzer` both 0 and 1. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118427&sha=86ce3f656c609f64c0654c838a67859237cd0be3&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20old%20analyzer%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F3%29 Related: #118427 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review feedback: making `PatternAction::extra` signed fixed the pre-epoch wraparound, but the comparison sites still evaluated `base + duration`, which can overflow for timestamps the `DateTime64` type accepts, and converting the duration of a `(?t...)` condition to the ticks of the timestamp type rejected durations that are perfectly meaningful at a high scale. Both go away by comparing the distance between the two timestamps instead: the duration stays in seconds, and `timeConditionSatisfied` widens the distance and the duration to `Int128` before comparing them. Nothing is rejected any more. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A cast clamps a `DateTime64` to the range the type can print, so the test did not actually reach the boundary it claims to test. `reinterpret` keeps the raw ticks. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review feedback asked for a case near the supported precision-9 upper boundary. `2262-04-11 23:47:16` is the last whole second the type holds, so the old `base + duration` formulation left the range of `Int64` for a one-second window: a control binary built from the previous commit answers `0 1` for this query, and it throws `ARGUMENT_OUT_OF_BOUND` for the large-window case above it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118427&sha=b03a2ce323b1c7f4befb8ff7094f2b2e46191a65&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. It is the |
|
Confirmed: this is the shared On Two of my PRs are open on it, and either one closes this pair:
Tracked in #118784. Master still builds those sets inside the callback ( |
…amps `timeConditionSatisfied` computed the distance between two events in `Int128`, which is not wide enough for the `UInt256` timestamps that `sequenceMatch` has always accepted: a gap of `2 ^ 200` lost all of its bits and a `(?t>1)` condition was evaluated as if the two events shared a timestamp. The distance is now computed in a type that holds every value of the timestamp type - `Int128` for the types that fit into 64 bits, including the signed ticks of `DateTime64`, and the unsigned timestamp type itself for `UInt128` and `UInt256`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Pushed
Related: #118486 (the earlier |
Only `DateTime64` timestamps get their durations rescaled to seconds. `Date` timestamps still compare `(?t...)` values in days and unsigned integer timestamps in their own units, so say that explicitly instead of claiming the value is always in seconds. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
sequenceMatch,sequenceCountandsequenceMatchEventsrejected aDateTime64timestamp:which forced a
toDateTime(...)cast and threw away the sub-second part that decides the order of events inside a second.DateTime64is what tables imported from PostgreSQL get for atimestampcolumn (#26216), so this is easy to hit without asking for it.The family is now instantiated with
DataTypeDateTime64::FieldTypefor the column type andInt64for the stored timestamp, reading the tick value out of theColumnDecimal. Two decisions worth calling out:Timestamps keep the column's precision. Events are ordered and compared in the column's own ticks, so two events in the same second still order by their sub-second part rather than being ambiguous.
sequenceMatchEventsreturnsArray(DateTime64(scale))with that precision intact.(?t...)durations stay in seconds.(?t<1296000)means 15 days whether the column isDateTime,DateTime64(3)orDateTime64(9), so a pattern keeps its meaning when a column's precision changes - which is the migration this issue was reported from. No duration is rejected: even a window that does not fit the ticks of the type is still evaluated.The temporal conditions are compared on the distance between the two timestamps rather than on
base + duration, with the distance and the scaled duration widened toInt128(timeConditionSatisfied). ADateTime64timestamp is signed and can sit at either end ofInt64, so formingbase + duration- or pre-scaling the duration into ticks - overflows for values the type itself accepts; comparing the distance does not.windowFunnelstill rejectsDateTime64- its data structures cast timestamps toUInt64in several places, so it needs its own change and is not in scope here.Closes: #31911
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
sequenceMatch,sequenceCountandsequenceMatchEventsnow accept aDateTime64timestamp instead of failing withIllegal type DateTime64(6) of first argument. Events are ordered at the column's full precision, so two events within the same second are no longer ambiguous. The durations in the(?t...)conditions of the pattern are in seconds for every timestamp type, so an existing pattern keeps its meaning when a column changes fromDateTimetoDateTime64.Workflow [PR]
Sync PR [sync-upstream/pr/118427]
Version info
26.10.1.622-master(included in26.10and later)