epgif commented on code in PR #9008:
URL: https://github.com/apache/iceberg/pull/9008#discussion_r1469960212
##########
api/src/main/java/org/apache/iceberg/expressions/ExpressionUtil.java:
##########
@@ -564,14 +569,26 @@ private static String sanitizeDate(int days, int today) {
return "(date)";
}
- private static String sanitizeTimestamp(long micros, long now) {
- String isPast = now > micros ? "ago" : "from-now";
- long diff = Math.abs(now - micros);
- if (diff < FIVE_MINUTES_IN_MICROS) {
+ private static String sanitizeTimestamp(ChronoUnit unit, long timeUnits,
long nowMillis) {
+ long timeMillis;
+ switch (unit) {
+ case MICROS:
+ timeMillis = DateTimeUtil.microsToMillis(timeUnits);
+ break;
+ case NANOS:
+ timeMillis = DateTimeUtil.nanosToMillis(timeUnits);
Review Comment:
I don't see how. See line 521 of `sanitize` for example.
##########
api/src/main/java/org/apache/iceberg/expressions/Literals.java:
##########
@@ -501,18 +531,22 @@ public <T> Literal<T> to(Type type) {
return (Literal<T>) new TimeLiteral(timeMicros);
case TIMESTAMP:
- if (((Types.TimestampType) type).shouldAdjustToUTC()) {
- long timestampMicros =
- ChronoUnit.MICROS.between(
- EPOCH, OffsetDateTime.parse(value(),
DateTimeFormatter.ISO_DATE_TIME));
- return (Literal<T>) new TimestampLiteral(timestampMicros);
+ TimestampType tsType = (TimestampType) type;
+ if (tsType.shouldAdjustToUTC()) {
+ long timestampUnits =
+ tsType
+ .unit()
+ .between(EPOCH, OffsetDateTime.parse(value(),
DateTimeFormatter.ISO_DATE_TIME));
Review Comment:
Maybe. Do you want that done here, or in a follow-up pull request?
##########
api/src/main/java/org/apache/iceberg/expressions/Literals.java:
##########
@@ -426,16 +428,40 @@ protected Type.TypeID typeId() {
}
static class TimestampLiteral extends ComparableLiteral<Long> {
- TimestampLiteral(Long value) {
+ private final ChronoUnit unit;
+
+ TimestampLiteral(ChronoUnit unit, Long value) {
super(value);
+ this.unit = unit;
}
@Override
@SuppressWarnings("unchecked")
public <T> Literal<T> to(Type type) {
switch (type.typeId()) {
case TIMESTAMP:
- return (Literal<T>) this;
+ ChronoUnit toUnit = ((TimestampType) type).unit();
+ switch (unit) {
+ case MICROS:
+ switch (toUnit) {
+ case MICROS:
+ return (Literal<T>) this;
+ case NANOS:
+ return (Literal<T>)
+ new TimestampLiteral(unit,
DateTimeUtil.microsToNanos(value()));
+ }
+ break;
+ case NANOS:
+ switch (toUnit) {
+ case MICROS:
+ return (Literal<T>)
+ new TimestampLiteral(unit,
DateTimeUtil.nanosToMicros(value()));
+ case NANOS:
+ return (Literal<T>) this;
+ }
+ break;
+ }
+ break;
Review Comment:
I'll add that.
##########
api/src/main/java/org/apache/iceberg/types/Types.java:
##########
@@ -46,8 +47,10 @@ private Types() {}
.put(DoubleType.get().toString(), DoubleType.get())
.put(DateType.get().toString(), DateType.get())
.put(TimeType.get().toString(), TimeType.get())
- .put(TimestampType.withZone().toString(), TimestampType.withZone())
- .put(TimestampType.withoutZone().toString(),
TimestampType.withoutZone())
+ .put(TimestampType.microsWithZone().toString(),
TimestampType.microsWithZone())
+ .put(TimestampType.microsWithoutZone().toString(),
TimestampType.microsWithoutZone())
Review Comment:
Are you just suggesting we leave lines 49 and 50 alone, i.e. using the
methods we want to deprecate? Functionally there's no difference, but I'd
prefer not to use the deprecated forms.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]