-
Notifications
You must be signed in to change notification settings - Fork 95
feat(isthmus): migrate to PrecisionTime / PrecisionTimestamp #721
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import java.nio.ByteBuffer; | ||
| import java.time.Instant; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
| import java.time.ZoneOffset; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
@@ -89,6 +90,23 @@ public static Expression.PrecisionTimeLiteral precisionTime( | |
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a precision time literal from a LocalTime value. | ||
| * | ||
| * <p>This method converts a Java {@link LocalTime} to a Substrait precision time literal with | ||
| * nanosecond precision (precision = 9). The time value is represented as nanoseconds since | ||
| * midnight (00:00:00). | ||
| * | ||
| * @param nullable whether the literal can be null | ||
| * @param value the LocalTime value to convert | ||
| * @return a PrecisionTimeLiteral with nanosecond precision representing the given time | ||
| * @see #precisionTime(boolean, long, int) for creating precision time with custom precision | ||
| */ | ||
| public static Expression.PrecisionTimeLiteral precisionTime(boolean nullable, LocalTime value) { | ||
| long epochNano = value.toNanoOfDay(); | ||
| return precisionTime(nullable, epochNano, 9); | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated Timestamp is deprecated in favor of PrecisionTimestamp | ||
| */ | ||
|
|
@@ -155,6 +173,27 @@ public static Expression.PrecisionTimestampLiteral precisionTimestamp( | |
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a precision timestamp literal from a LocalDateTime value. | ||
| * | ||
| * <p>This method converts a Java {@link LocalDateTime} to a Substrait precision timestamp literal | ||
| * with nanosecond precision (precision = 9). The timestamp value is represented as nanoseconds | ||
| * since the Unix epoch (1970-01-01 00:00:00 UTC), assuming the LocalDateTime is in UTC timezone. | ||
| * | ||
| * @param nullable whether the literal can be null | ||
| * @param value the LocalDateTime value to convert (interpreted as UTC) | ||
| * @return a PrecisionTimestampLiteral with nanosecond precision representing the given timestamp | ||
| * @see #precisionTimestamp(boolean, long, int) for creating precision timestamp with custom | ||
| * precision | ||
| */ | ||
| public static Expression.PrecisionTimestampLiteral precisionTimestamp( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look to be used anywhere in the codebase. If it is worth adding, it should probably have a test driving it. |
||
| boolean nullable, LocalDateTime value) { | ||
| long epochNano = | ||
| TimeUnit.SECONDS.toNanos(value.toEpochSecond(ZoneOffset.UTC)) | ||
| + value.toLocalTime().getNano(); | ||
| return precisionTimestamp(nullable, epochNano, 9); | ||
| } | ||
|
|
||
| public static Expression.PrecisionTimestampTZLiteral precisionTimestampTZ( | ||
| boolean nullable, long value, int precision) { | ||
| return Expression.PrecisionTimestampTZLiteral.builder() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ class CalciteCallTest extends CalciteObjs { | |
| @Test | ||
| void extract() { | ||
| test( | ||
| "extract:req_ts", | ||
| "extract:req_pts", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need to test
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Round tripping function calls with the deprecated Timestamp, TimestampTZ, Time was already broken in some cases before this change. We don't have tests that certify backwards compatibility of parsing Substrait plans using deprecated types / functions. |
||
| rex.makeCall( | ||
| t(SqlTypeName.INTEGER), | ||
| SqlStdOperatorTable.EXTRACT, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
This doesn't look to be used anywhere in the codebase. If it is worth adding, it should probably have a test driving it.