Skip to content

Commit

Permalink
Remove unnecessary computation
Browse files Browse the repository at this point in the history
The `endExclusive` variable is derived from `dateTime`
which has `0` nano seconds.
  • Loading branch information
findinpath authored and findepi committed Dec 11, 2022
1 parent e3d2cb1 commit 8211f70
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.base.Enums;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.math.LongMath;
import io.airlift.slice.Slice;
import io.trino.Session;
import io.trino.metadata.ResolvedFunction;
Expand Down Expand Up @@ -63,7 +62,6 @@
import static io.trino.spi.type.DateType.DATE;
import static io.trino.spi.type.TimestampType.createTimestampType;
import static io.trino.spi.type.Timestamps.MICROSECONDS_PER_SECOND;
import static io.trino.spi.type.Timestamps.NANOSECONDS_PER_MICROSECOND;
import static io.trino.sql.ExpressionUtils.isEffectivelyLiteral;
import static io.trino.sql.ExpressionUtils.or;
import static io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType;
Expand All @@ -79,7 +77,6 @@
import static java.lang.Math.floorDiv;
import static java.lang.Math.floorMod;
import static java.lang.Math.toIntExact;
import static java.math.RoundingMode.UNNECESSARY;
import static java.util.Objects.requireNonNull;

/**
Expand Down Expand Up @@ -279,8 +276,8 @@ private Object calculateRangeEndInclusive(Object rangeStart, Type type, Supporte
case MONTH -> dateTime.plusMonths(1);
case YEAR -> dateTime.plusYears(1);
};
long endExclusiveMicros = endExclusive.toEpochSecond(ZoneOffset.UTC) * MICROSECONDS_PER_SECOND
+ LongMath.divide(endExclusive.getNano(), NANOSECONDS_PER_MICROSECOND, UNNECESSARY);
verify(endExclusive.getNano() == 0, "Unexpected nanos in %s, value not rounded to %s", endExclusive, rangeUnit);
long endExclusiveMicros = endExclusive.toEpochSecond(ZoneOffset.UTC) * MICROSECONDS_PER_SECOND;
return endExclusiveMicros - scaleFactor(timestampType.getPrecision(), 6);
}
LongTimestamp longTimestamp = (LongTimestamp) rangeStart;
Expand Down

0 comments on commit 8211f70

Please sign in to comment.