Skip to content

Commit

Permalink
Improve Iceberg pruning for date_trunc 'hour' over timestamptz
Browse files Browse the repository at this point in the history
See 154223c for more context.
  • Loading branch information
findepi committed Sep 19, 2022
1 parent a3d2c2f commit 8d70892
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Expand Up @@ -34,6 +34,7 @@
import io.trino.spi.type.Type;

import java.time.Instant;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -251,6 +252,10 @@ private static Optional<Domain> unwrapDateTruncInComparison(String unit, Functio
ZonedDateTime periodStart;
ZonedDateTime nextPeriodStart;
switch (unit.toLowerCase(ENGLISH)) {
case "hour" -> {
periodStart = ZonedDateTime.of(dateTime.toLocalDate(), LocalTime.of(dateTime.getHour(), 0), UTC);
nextPeriodStart = periodStart.plusHours(1);
}
case "day" -> {
periodStart = dateTime.toLocalDate().atStartOfDay().atZone(UTC);
nextPeriodStart = periodStart.plusDays(1);
Expand Down
Expand Up @@ -1514,7 +1514,7 @@ else if (format == AVRO) {

// date_trunc
assertThat(query("SELECT * FROM test_hour_transform_timestamptz WHERE date_trunc('hour', d) = TIMESTAMP '2015-05-15 12:00:00.000000 UTC'"))
.isNotFullyPushedDown(FilterNode.class); // TODO convert into range
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_hour_transform_timestamptz WHERE date_trunc('day', d) = TIMESTAMP '2015-05-15 00:00:00.000000 UTC'"))
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_hour_transform_timestamptz WHERE date_trunc('month', d) = TIMESTAMP '2015-05-01 00:00:00.000000 UTC'"))
Expand Down

0 comments on commit 8d70892

Please sign in to comment.