Skip to content

Commit

Permalink
Subsume non-identity partition timestamp predicate in Iceberg
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jun 20, 2022
1 parent 9afe194 commit 2cdf021
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
*/
package io.trino.plugin.iceberg;

import io.trino.spi.type.TimestampType;
import io.trino.spi.type.Type;
import io.trino.spi.type.Type.Range;

import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.DateType.DATE;
Expand Down Expand Up @@ -55,6 +57,14 @@ public static Optional<Object> getPreviousValue(Type type, Object value)
return getAdjacentValue(Integer.MIN_VALUE, Integer.MAX_VALUE, (long) value, Direction.PREV);
}

if (type instanceof TimestampType) {
// Iceberg supports only timestamp(6)
checkArgument(((TimestampType) type).getPrecision() == 6, "Unexpected type: %s", type);
// TODO update the code here when type implements getRange
verify(type.getRange().isEmpty(), "Type %s unexpectedly returned a range", type);
return getAdjacentValue(Long.MIN_VALUE, Long.MAX_VALUE, (long) value, Direction.PREV);
}

return Optional.empty();
}

Expand Down Expand Up @@ -83,6 +93,14 @@ public static Optional<Object> getNextValue(Type type, Object value)
return getAdjacentValue(Integer.MIN_VALUE, Integer.MAX_VALUE, (long) value, Direction.NEXT);
}

if (type instanceof TimestampType) {
// Iceberg supports only timestamp(6)
checkArgument(((TimestampType) type).getPrecision() == 6, "Unexpected type: %s", type);
// TODO update the code here when type implements getRange
verify(type.getRange().isEmpty(), "Type %s unexpectedly returned a range", type);
return getAdjacentValue(Long.MIN_VALUE, Long.MAX_VALUE, (long) value, Direction.NEXT);
}

return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,10 +1228,10 @@ public void testHourTransform()
.isFullyPushedDown();

assertThat(query("SELECT * FROM test_hour_transform WHERE d >= DATE '2015-05-15'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();

assertThat(query("SELECT * FROM test_hour_transform WHERE d >= TIMESTAMP '2015-05-15 12:00:00'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_hour_transform WHERE d >= TIMESTAMP '2015-05-15 12:00:00.000001'"))
.isNotFullyPushedDown(FilterNode.class);

Expand Down Expand Up @@ -1366,10 +1366,10 @@ public void testDayTransformTimestamp()
.isFullyPushedDown();

assertThat(query("SELECT * FROM test_day_transform_timestamp WHERE d >= DATE '2015-05-15'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();

assertThat(query("SELECT * FROM test_day_transform_timestamp WHERE d >= TIMESTAMP '2015-05-15 00:00:00'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_day_transform_timestamp WHERE d >= TIMESTAMP '2015-05-15 00:00:00.000001'"))
.isNotFullyPushedDown(FilterNode.class);

Expand Down Expand Up @@ -1584,12 +1584,12 @@ public void testMonthTransformTimestamp()
.isFullyPushedDown();

assertThat(query("SELECT * FROM test_month_transform_timestamp WHERE d >= DATE '2015-05-01'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_month_transform_timestamp WHERE d >= DATE '2015-05-02'"))
.isNotFullyPushedDown(FilterNode.class);

assertThat(query("SELECT * FROM test_month_transform_timestamp WHERE d >= TIMESTAMP '2015-05-01 00:00:00'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_month_transform_timestamp WHERE d >= TIMESTAMP '2015-05-01 00:00:00.000001'"))
.isNotFullyPushedDown(FilterNode.class);

Expand Down Expand Up @@ -1797,12 +1797,12 @@ public void testYearTransformTimestamp()
.isFullyPushedDown();

assertThat(query("SELECT * FROM test_year_transform_timestamp WHERE d >= DATE '2015-01-01'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_year_transform_timestamp WHERE d >= DATE '2015-01-02'"))
.isNotFullyPushedDown(FilterNode.class);

assertThat(query("SELECT * FROM test_year_transform_timestamp WHERE d >= TIMESTAMP '2015-01-01 00:00:00'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on timestamp
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_year_transform_timestamp WHERE d >= TIMESTAMP '2015-01-01 00:00:00.000001'"))
.isNotFullyPushedDown(FilterNode.class);

Expand Down Expand Up @@ -3701,6 +3701,8 @@ public static Object[][] testOptimizeTimePartitionedTableDataProvider()
{"date", "%s", 15},
{"date", "day(%s)", 15},
{"date", "month(%s)", 3},
{"timestamp(6)", "day(%s)", 15},
{"timestamp(6)", "month(%s)", 3},
};
}

Expand Down

0 comments on commit 2cdf021

Please sign in to comment.