Repository navigation
Fix DateTime64 Protobuf range and preserve subsecond precision - #111920
RamiDarwiche wants to merge 6 commits into
Conversation
|
Workflow [PR], commit [235f63d] Summary: ✅
AI ReviewSummaryThe PR maps Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Correct the default conversion of negative fractional timestamps and add the focused regression above. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 0/0 (nothing coverable) · Uncovered code |
|
@RamiDarwiche are you going to continue on this? |
|
@PedroTadim Yes! Just a quick question, would it be better to separate the Time/Time64 implementations into their own PR? I believe they'd need their own serializers as well. I'm finishing up the commit so that the DateTime64 extremes match the range in the documentation, the decimal serializer path doesn't handle subseconds. |
Sure, for Time/Time64 you can create another PR, and I can review it |
|
@PedroTadim This latest commit introduces a new Protobuf serializer specifically for DateTime64 that enables sub-second precision and allows DateTime64 to reach the upper bound referenced in the documentation. The value ClickHouse/src/IO/parseDateTimeBestEffort.cpp Lines 914 to 928 in a9f0a82 Would you want the fix for this to be addressed as another commit in this PR? |
You can address in this PR and update the description. |
DateTime64 Protobuf range and preserve subsecond precision
|
@RamiDarwiche the tidy build failed |
|
@PedroTadim Currently, the standard ClickHouse/src/IO/ReadHelpers.h Lines 964 to 968 in 3428f5c Best-effort parsing throws an error for the same date: ClickHouse/src/IO/parseDateTimeBestEffort.cpp Lines 937 to 945 in 3428f5c For |
I would say it should match, This may become a backwards incompatible change, but it's fine because it's a very edge case. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes504 object files changed (+91.38 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units3348 translation units recompiled, 18485 s compile time in total, 3347 of them have a recent master baseline. Translation units without a recent master baseline:
|
|
@PedroTadim Can I get your thoughts on this approach to |
So far it seems good to me. |
|
@PedroTadim Is there anything remaining that you'd want addressed in this PR? I'm also not sure how to resolve the Bugfix validation check failure. Thanks! |
|
@RamiDarwiche can you merge with master and fix the conflicts for a final run? @yariks5s can also give a final look |
e1f3d13 to
25d9d46
Compare
|
@RamiDarwiche this PR is too big, we should split in 2:
|
|
@PedroTadim I definitely agree, I'll separate the changes and leave this PR focused on Protobufs. |
|
@RamiDarwiche merge with master one more time. I want to get this merged this week at most. 🕵️ |
| { | ||
| switch (field_typeid) | ||
| { | ||
| case FieldTypeId::TYPE_INT32: { |
There was a problem hiding this comment.
@RamiDarwiche could you use a c++ template to remove the duplicate code?
| } | ||
|
|
||
| case FieldTypeId::TYPE_FLOAT: { | ||
| /// Float/double schemas always store fractional Unix seconds. |
There was a problem hiding this comment.
another template could be possible for the floating-point types
|
@RamiDarwiche please squash the commits |
5474bd7 to
add9c8e
Compare
| if (!output_scaled_ticks) | ||
| { | ||
| /// Integer protobuf fields store whole Unix seconds unless scaled ticks were explicitly selected. | ||
| return DecimalUtils::getWholePart(value, scale); |
There was a problem hiding this comment.
The default integer-seconds path still misencodes negative fractional DateTime64 values here. DecimalUtils::getWholePart truncates toward zero, so with scale = 3 the timestamp 1969-12-31 23:59:59.500 (value.value == -500) writes 0 instead of -1; ticksFromNumericField then reads that back as 1970-01-01 00:00:00.000 instead of 1969-12-31 23:59:59.000.
That means the new "Unix seconds by default" contract is still wrong for every pre-epoch value with a fractional part. Can we floor toward negative infinity before emitting the integer seconds (or reuse a helper that already does that split for DateTime64 elsewhere) and add a focused regression on the default -1 path?
|
@yariks5s can you help to give a final look? |
…ization_overflow Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Dear @PedroTadim, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…story 26.10 was released without them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #111860
DateTime64was incorrectly being mapped to auint64during Protobuf auto schema resolution, causing an overflow error when values prior to the Unix epoch (negative values) were serialized. This effectively restricted the lower bound ofDateTime64values writable through auto-generated Protobuf schemas to1970-01-01 00:00:00rather than0000-01-01 00:00:00, as suggested by the type's documentation.Originally,
DateTime64usedProtobufSerializerDecimal, which was unaware of tick precision. The decimal serializer would callgetWholePartand discard subseconds. This PR introducesProtobufSerializerDateTime64to retain subsecond time values during Protobuf serialization/deserialization.input_format_protobuf_datetime64_scale/output_format_protobuf_datetime64_scalesettings were added to opt into scaled ticks when set to theDateTime64column precision (mismatches are rejected). Left at-1(the default), integer fields stay Unix seconds, so a file written at one precision still decodes to the same instant at another.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes
DateTime64Protobuf auto-schema (maps toint64instead ofuint64) so pre-epoch values no longer raiseDECIMAL_OVERFLOW. SerializesDateTime64integer fields as Unix seconds by default so a precision change does not reinterpret the payload (setinput_format_protobuf_datetime64_scale/output_format_protobuf_datetime64_scaleto the column precision to keep subseconds as scaled ticks; mismatches are rejected).Workflow [PR]
Sync PR [sync-upstream/pr/111920]