Repository navigation
Persist ORC calendar metadata and support legacy DATE rebasing in C++ #24733
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
wjxiz1992
wants to merge
12
commits into
NVIDIA:main
Choose a base branch
from
wjxiz1992:codex/orc-calendar-23794
base: main
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.
+1,511
−100
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3468260
Persist proleptic Gregorian calendar in ORC footers
wjxiz1992 70eeb18
Support legacy ORC DATE calendar rebasing
wjxiz1992 db4aedb
Address ORC calendar review findings
wjxiz1992 c941fc6
Address ORC calendar review and share kernel error reporting
wjxiz1992 f33c38b
Merge main for ORC calendar compatibility
wjxiz1992 82fec42
Merge main and finish ORC calendar review cleanup
wjxiz1992 3e8599b
Split Java ORC calendar bindings into a follow-up PR
wjxiz1992 d430a1e
Keep ORC calendar changes focused and cover NumPy reads
wjxiz1992 c3d622a
Handle ORC date statistics outside Python datetime range
wjxiz1992 7703f64
Consolidate ORC calendar Java and JNI controls in this PR
wjxiz1992 f2595dc
Merge branch 'main' into codex/orc-calendar-23794
wjxiz1992 4105b7e
Fix chunked ORC calendar conversion and review feedback
wjxiz1992 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cudf/types.hpp> | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace cudf::io::orc::detail { | ||
|
|
||
| // Epoch days of 1582-10-15. Earlier hybrid dates use the Julian calendar. | ||
| constexpr int32_t calendar_cutover = -141'427; | ||
|
|
||
| CUDF_HOST_DEVICE constexpr int64_t floor_div(int64_t value, int64_t divisor) | ||
| { | ||
| return value / divisor - (value % divisor < 0); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Convert epoch days while preserving the civil year, month, and day. | ||
| * | ||
| * March-based 400-year Gregorian and 4-year Julian cycles keep intermediate values positive | ||
| * within each cycle, including for astronomical years zero and below. All arithmetic is 64 bit | ||
| * so that the complete int32 DATE domain can be checked before narrowing the result. | ||
| */ | ||
| template <bool to_hybrid> | ||
| CUDF_HOST_DEVICE constexpr int64_t rebase_days(int64_t days) | ||
| { | ||
| if (days >= calendar_cutover) { return days; } | ||
|
|
||
| constexpr int64_t gregorian_epoch_offset = 719'468; | ||
| constexpr int64_t julian_epoch_offset = 719'470; | ||
| constexpr int64_t gregorian_era_days = 146'097; | ||
| constexpr int64_t julian_era_days = 1'461; | ||
| constexpr int64_t gregorian_century_days = gregorian_era_days / 4; | ||
| constexpr int64_t five_month_days = 153; | ||
| constexpr auto source_era_days = to_hybrid ? gregorian_era_days : julian_era_days; | ||
| auto const z = days + (to_hybrid ? gregorian_epoch_offset : julian_epoch_offset); | ||
| auto const era = floor_div(z, source_era_days); | ||
| auto const doe = z - era * source_era_days; | ||
| // Discount leap days to recover the year within the source calendar's era. | ||
| auto const yoe = to_hybrid ? (doe - doe / (julian_era_days - 1) + doe / gregorian_century_days - | ||
| doe / (gregorian_era_days - 1)) / | ||
| 365 | ||
| : (doe == julian_era_days - 1 ? 3 : doe / 365); | ||
| auto const year = yoe + era * (to_hybrid ? 400 : 4); | ||
| auto const doy = doe - (365 * yoe + (to_hybrid ? yoe / 4 - yoe / 100 : 0)); | ||
| // March starts the year so the leap day is last. Five-month blocks contain 153 days; | ||
| // mp maps March through February to 0 through 11, with doy measured from March 1. | ||
| auto const mp = (5 * doy + 2) / five_month_days; | ||
| auto const day = doy - (five_month_days * mp + 2) / 5 + 1; | ||
|
|
||
| if constexpr (to_hybrid) { | ||
| return 365 * year + floor_div(year, 4) + (five_month_days * mp + 2) / 5 + day - 1 - | ||
| julian_epoch_offset; | ||
| } else { | ||
| return 365 * year + floor_div(year, 4) - floor_div(year, 100) + floor_div(year, 400) + | ||
| (five_month_days * mp + 2) / 5 + day - 1 - gregorian_epoch_offset; | ||
| } | ||
| } | ||
|
|
||
| template <bool to_hybrid> | ||
| CUDF_HOST_DEVICE constexpr bool is_representable_date(int64_t original, int64_t rebased) | ||
| { | ||
| // The hybrid cutover gap and Julian-only leap days have no lossless counterpart. | ||
| return rebased >= INT32_MIN and rebased <= INT32_MAX and | ||
| rebase_days<!to_hybrid>(rebased) == original; | ||
| } | ||
|
|
||
| } // namespace cudf::io::orc::detail | ||
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,32 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "io/utilities/kernel_error.hpp" | ||
|
|
||
| #include <cuda/atomic> | ||
|
|
||
| namespace cudf::io::orc::detail { | ||
|
|
||
| enum class decode_error : kernel_error::value_type { | ||
| INVALID_DATA_STREAM = 1 << 0, | ||
| UNREPRESENTABLE_DATE = 1 << 1, | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Record a decoding failure without a shared error count wrapping back to zero. | ||
| * | ||
| * The reader checks for any error after synchronizing the decoding stream. Columns and | ||
| * stripes share the same status, so their combined number of failures is not row-count bounded. | ||
| */ | ||
| inline __device__ void set_decode_error(kernel_error::pointer status, | ||
| decode_error kind = decode_error::INVALID_DATA_STREAM) | ||
| { | ||
| cuda::atomic_ref<kernel_error::value_type, cuda::thread_scope_device> error{*status}; | ||
| error.fetch_or(static_cast<kernel_error::value_type>(kind), cuda::std::memory_order_relaxed); | ||
| } | ||
|
|
||
| } // namespace cudf::io::orc::detail |
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.
The direction only shows up as a bool at the call sites (
rebase_days<true>in the writer,rebase_days<false>in the reader), so you have to come here to find out whattruemeans. Could we expose named wrappers likeproleptic_to_hybrid_days/hybrid_to_proleptic_days, and do the same foris_representable_date?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.
Added.