[Gandiva] Complete timestamp precision support for all datetime functions#129
Closed
telemenar wants to merge 6 commits intodremio:dremio_27.0_20from
Closed
[Gandiva] Complete timestamp precision support for all datetime functions#129telemenar wants to merge 6 commits intodremio:dremio_27.0_20from
telemenar wants to merge 6 commits intodremio:dremio_27.0_20from
Conversation
…ractYear POC
Phase 1: Core Infrastructure
- Add MICROS_*, NANOS_*, SECS_* constants to time_constants.h
- Create templated EpochTimePointT<Duration> class for precision-aware time operations
- Add gdv_timestamp_{sec,ms,us,ns} type aliases in types.h
- Update FunctionSignature::Hash() to include TimeUnit for temporal types
- Add timestamp_{sec,ms,us,ns}() helpers and TIMESTAMP_PRECISION_TYPES macro
Phase 2: Proof of Concept - extractYear
- Implement extractYear_timestamp_{sec,ms,us,ns} functions
- Register precision-specific extractYear in function registry
- Add unit tests for EpochTimePointT template
- Add unit tests for precision-specific extractYear
- Add FunctionSignature hash tests for timestamp precisions
- Add integration test for extractYear with all precisions
Phase 4: Remaining Extract Functions - Add EXTRACT_TIMESTAMP_PRECISION_FNS macro for generating precision-aware extract functions - Implement extractMonth, extractDay, extractHour, extractMinute, extractSecond for all timestamp precisions (sec, ms, us, ns) - Implement extractDoy, extractDow, extractQuarter for all precisions - Implement extractWeek for all precisions (converts to millis for week calculation) - Implement extractEpoch for all precisions (returns seconds) - Implement extractMillennium, extractCentury, extractDecade for all precisions - Add DECLARE_EXTRACT_TIMESTAMP_PRECISION macro for function declarations - Register all precision-specific extract functions in function registry - Add comprehensive unit tests for all extract functions with all precisions
Phase 5: Date Truncation Functions - Add precision-aware date_trunc macros (DATE_TRUNC_FIXED_UNIT_PRECISION, DATE_TRUNC_WEEK_PRECISION, DATE_TRUNC_MONTH_UNITS_PRECISION, DATE_TRUNC_YEAR_UNITS_PRECISION) - Implement date_trunc_Second/Minute/Hour/Day for all timestamp precisions - Implement date_trunc_Week/Month/Quarter/Year for all precisions - Implement date_trunc_Decade/Century/Millennium for all precisions - Add new sub-millisecond truncation functions: - date_trunc_Millisecond for timestamp[us] and timestamp[ns] - date_trunc_Microsecond for timestamp[ns] - Add DECLARE_DATE_TRUNC_TIMESTAMP_PRECISION macro for declarations - Register all precision-specific date_trunc functions in function registry - Add comprehensive unit tests for date truncation with all precisions
Phase 6: Timestamp Arithmetic Functions - Add precision-aware macros for timestamp add operations: - ADD_INT32_TO_TIMESTAMP_PRECISION_FIXED for fixed unit additions - ADD_INT64_TO_TIMESTAMP_PRECISION_FIXED for fixed unit additions - ADD_INT32_TO_TIMESTAMP_PRECISION_MONTH for month-based additions - ADD_INT64_TO_TIMESTAMP_PRECISION_MONTH for month-based additions - Implement timestampaddSecond/Minute/Hour/Day/Week for all precisions (sec, ms, us, ns) - Implement timestampaddMonth/Quarter/Year for all precisions - Support both argument orders: (int, timestamp) and (timestamp, int) - Add DECLARE_TIMESTAMPADD_PRECISION macros for function declarations - Add TIMESTAMP_ADD_PRECISION_FNS macro for registry registration - Register all precision-specific timestampadd functions - Add comprehensive unit tests for timestamp arithmetic with all precisions
Phase 7 & 8: Cast, Conversion, and Remaining Functions
- Implement timestamp-to-timestamp precision cast functions:
- castTIMESTAMP_{ms,us,ns}_timestamp_sec
- castTIMESTAMP_{sec,us,ns}_timestamp_ms
- castTIMESTAMP_{sec,ms,ns}_timestamp_us
- castTIMESTAMP_{sec,ms,us}_timestamp_ns
- Implement castDATE for all timestamp precisions
- Implement castTIME for all timestamp precisions
- Implement datediff for all timestamp precisions
- Register all cast and conversion functions in function registry
- Add comprehensive unit tests for:
- Timestamp precision conversion (upscale and downscale)
- Timestamp to date64 cast
- Timestamp to time32 cast
- datediff with various precisions
Phase 8: Remaining Functions - Implement months_between for all timestamp precisions - Implement last_day for all timestamp precisions - Register months_between and last_day functions in function registry - Both functions convert to milliseconds internally for calendar calculations since these are calendar operations that don't require sub-ms precision Note: Timezone functions (to_utc_timestamp, from_utc_timestamp) are complex and would require more extensive changes to gdv_function_stubs.cc. These can be addressed in a follow-up PR if needed.
519aad5 to
86f537f
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR completes the implementation of timestamp precision support for all Gandiva datetime functions, building on the infrastructure established in #128.
Changes
Phase 4: Extract Functions
extractMonth,extractDay,extractHour,extractMinute,extractSecondfor all precisionsextractDoy,extractDow,extractQuarter,extractWeekfor all precisionsextractEpoch,extractMillennium,extractCentury,extractDecadefor all precisionsPhase 5: Date Truncation Functions
date_trunc_Second/Minute/Hour/Day/Week/Month/Quarter/Yearfor all precisionsdate_trunc_Decade/Century/Millenniumfor all precisionsdate_trunc_Millisecond(for us/ns) anddate_trunc_Microsecond(for ns)Phase 6: Timestamp Arithmetic Functions
timestampaddSecond/Minute/Hour/Day/Weekfor all precisionstimestampaddMonth/Quarter/Yearfor all precisions(int, timestamp)and(timestamp, int)Phase 7: Cast and Conversion Functions
castDATEfor all timestamp precisionscastTIMEfor all timestamp precisionsdatedifffor all timestamp precisionsPhase 8: Remaining Functions
months_betweenfor all timestamp precisionslast_dayfor all timestamp precisionsFunctions Implemented
Testing
Dependencies
Co-authored by Augment Code
Pull Request opened by Augment Code with guidance from the PR author