Repository navigation
[C++] Honor TS_2DIFF floating-point precision properties in writers #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jixuan1989
wants to merge
5
commits into
apache:develop
Choose a base branch
from
jixuan1989:cpp/fix-ts2diff-writer-precision
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+741
−35
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f4bc79
Honor floating-point TS_2DIFF precision properties in C++ writers
jixuan1989 f933c9e
Escape reserved TS_2DIFF precisions for zero-only pages
jixuan1989 861aa8c
Match Java rounding at floating-point boundaries
jixuan1989 1e8d230
Borrow device IDs during record schema checks
jixuan1989 75592b8
Fix precision boundary test decoder lifetime under ASan
jixuan1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * License); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #ifndef ENCODING_ENCODING_PROPS_H | ||
| #define ENCODING_ENCODING_PROPS_H | ||
|
|
||
| #include <cstdint> | ||
| #include <map> | ||
| #include <string> | ||
|
|
||
| namespace storage { | ||
| namespace detail { | ||
|
|
||
| // Integer.parseInt uses Character.digit(char, 10): BMP decimal digits are | ||
| // accepted, but supplementary digits (UTF-16 surrogate pairs) are not. | ||
| inline int precision_digit(const std::string& text, size_t& offset) { | ||
| const auto first = static_cast<unsigned char>(text[offset++]); | ||
| if (first < 0x80) { | ||
| return first >= '0' && first <= '9' ? first - '0' : -1; | ||
| } | ||
| int trailing; | ||
| uint32_t code; | ||
| if (first >= 0xC2 && first <= 0xDF) { | ||
| trailing = 1; | ||
| code = first & 0x1F; | ||
| } else if (first >= 0xE0 && first <= 0xEF) { | ||
| trailing = 2; | ||
| code = first & 0x0F; | ||
| } else { | ||
| return -1; | ||
| } | ||
| if (offset + trailing > text.size()) return -1; | ||
| for (int i = 0; i < trailing; ++i) { | ||
| const auto next = static_cast<unsigned char>(text[offset++]); | ||
| if ((next & 0xC0) != 0x80) return -1; | ||
| code = (code << 6) | (next & 0x3F); | ||
| } | ||
| if ((trailing == 2 && code < 0x800) || (code >= 0xD800 && code <= 0xDFFF)) | ||
| return -1; | ||
| static const uint16_t zeroes[] = { | ||
| 0x0660, 0x06F0, 0x07C0, 0x0966, 0x09E6, 0x0A66, 0x0AE6, 0x0B66, 0x0BE6, | ||
| 0x0C66, 0x0CE6, 0x0D66, 0x0DE6, 0x0E50, 0x0ED0, 0x0F20, 0x1040, 0x1090, | ||
| 0x17E0, 0x1810, 0x1946, 0x19D0, 0x1A80, 0x1A90, 0x1B50, 0x1BB0, 0x1C40, | ||
| 0x1C50, 0xA620, 0xA8D0, 0xA900, 0xA9D0, 0xA9F0, 0xAA50, 0xABF0, 0xFF10}; | ||
| for (uint16_t zero : zeroes) { | ||
| if (code >= zero && code <= zero + 9U) return code - zero; | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| inline int max_point_number(const std::map<std::string, std::string>& props) { | ||
| const auto property = props.find("max_point_number"); | ||
| if (property == props.end()) return 2; | ||
| const auto& text = property->second; | ||
| size_t offset = 0; | ||
| bool negative = false; | ||
| if (!text.empty() && (text[0] == '-' || text[0] == '+')) { | ||
| negative = text[0] == '-'; | ||
| ++offset; | ||
| } | ||
| // A fresh Java Ts2Diff builder retains zero after NumberFormatException. | ||
| if (offset == text.size()) return 0; | ||
| const uint32_t limit = negative ? 2147483648U : 2147483647U; | ||
| uint32_t value = 0; | ||
| while (offset < text.size()) { | ||
| const int digit = precision_digit(text, offset); | ||
| if (digit < 0 || value > (limit - digit) / 10) return 0; | ||
| value = value * 10 + digit; | ||
| } | ||
| // Negative precision falls back to Java's default floatPrecision (2). | ||
| return negative && value != 0 ? 2 : static_cast<int>(value); | ||
| } | ||
|
|
||
| } // namespace detail | ||
| } // namespace storage | ||
|
|
||
| #endif // ENCODING_ENCODING_PROPS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed by reproduction. On the published PR head, the added regressions fail in 32 zero-only writer variants plus one encoder boundary test. Both FLOAT and DOUBLE are affected, at precisions 2147483646 and 2147483647. The leading precision is interpreted as a bitmap marker, and C++ rejects the following zero count.
I have tested a local fix that forces the existing scaled-value bitmap wrapper for these two precisions, retaining an all-scaled bitmap and writing the actual precision after it. Both existing decoders understand that position as a precision value. The local fix passed 87 focused tests, 992 Windows tests and 1013 Linux tests. All 64 added C++ boundary pages were readable by Java; 8 additional C++ zero-only files passed both own and Java reads.
One compatibility detail: the current Java encoder itself emits unreadable zero-only pages for these two precisions (16 raw pages and 8 full files reproduced). Copying those bytes would reproduce the bug; the explicit existing wrapper is required. These invalid Java outputs are recorded as failures, not counted as interoperability passes.
The fix has not been pushed yet: our performance gate detected a small reproducible FLOAT record slowdown (125 paired runs, median ratio 1.0172, 95% CI [1.0062, 1.0244]). I am investigating that before publishing the revision and will update this thread with the validated commit and evidence.
AI disclosure: This response, reproduction and reported local validation were prepared/performed by OpenAI Codex.
AI 使用说明: 本回复、复现及报告的本地验证由 OpenAI Codex 编写或执行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validated update for
1e8d230805d5823f1e0cd7a82af4e815510080e0: the fix is now pushed to this PR.The two reserved precision values now force the existing scaled-value bitmap wrapper in both floating-point flush paths, even when every value is scaled zero. The actual precision follows the count/bitmap and is read as a value by both existing decoders. Empty pages still emit nothing. The new zero-only regressions failed 33 tests before this correction and pass afterward.
The final revision also makes Java rounding exact at half-neighbors and large integers: the old
floor(x + 0.5)can round twice. An IEEE-significand implementation matches Java on 1,088,975 deterministic random/edge inputs for both saturated int32 and int64 results (the legacy int64 floor approximation differs on 251). Actual NaN inputs keep the existing raw-bit handling; zero multiplied by an infinite scale rounds to zero. The record schema-check helpers borrow the caller-owned DeviceID instead of copying its shared_ptr on every record; they retain no reference and public APIs/object layouts are unchanged.Final local validation:
The earlier performance signal was investigated rather than omitted. Final paired latency ratios (same benchmark source/configuration, 125 retained pairs for FLOAT record including the fixed-size confirmation; 25 pairs for each other workload):
float_nonaligned_record_default: 1.0000, 95% CI [0.9941, 1.0049].double_nonaligned_tablet_default: 0.9812, 95% CI [0.9662, 0.9901].float_aligned_tablet_precision_2: 0.9822, 95% CI [0.9756, 0.9868].double_aligned_record_precision_2: 0.9999, 95% CI [0.9910, 1.0044].No statistically distinguishable slowdown was observed in this final matrix; the report retains earlier slower versions and all measurements. This is evidence for these workloads, not a claim about every possible workload.
Validation report · Logs, sources, coverage and measurements
AI disclosure: This response, implementation, tests and reported local validation were prepared/performed by OpenAI Codex.
AI 使用说明: 本回复、实现、测试及报告的本地验证由 OpenAI Codex 编写或执行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanitizer follow-up in
75592b89d1523a96090e8bca1dcb4cd2180162e5: both Ubuntu ASan jobs found a lifetime error in my new zero-page test.DecoderFactory::freedoes not call the decoder destructor, so its bitmap vectors leaked 424 bytes in 32 allocations. The test now uses scoped concrete decoders. No production code changes. The original test reproduces the same leak locally; the revised 7 encoding tests and full Linux Debug ASan suite (1014 passed, 1 skipped, all six codecs enabled) pass with leak detection on. Windows Release: 993 passed. Production source and prior measured artifacts are SHA-256 identical, preserving the previously reported compatibility, coverage and performance evidence. Supplementary report · Logs and reproduction.AI disclosure: This correction, response and reported validation were prepared/performed by OpenAI Codex.
AI 使用说明: 本修正、回复及报告的验证由 OpenAI Codex 编写或执行。