Skip to content

Commit

Permalink
Subsume non-identity partition date predicate in Iceberg
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jun 20, 2022
1 parent d4a743c commit 9afe194
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import java.util.Optional;

import static com.google.common.base.Verify.verify;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.DateType.DATE;
import static io.trino.spi.type.IntegerType.INTEGER;
import static io.trino.spi.type.SmallintType.SMALLINT;
import static io.trino.spi.type.TinyintType.TINYINT;
Expand Down Expand Up @@ -47,6 +49,12 @@ public static Optional<Object> getPreviousValue(Type type, Object value)
return getAdjacentValue((long) typeRange.getMin(), (long) typeRange.getMax(), (long) value, Direction.PREV);
}

if (type == DATE) {
// TODO update the code here when type implements getRange
verify(type.getRange().isEmpty(), "Type %s unexpectedly returned a range", type);
return getAdjacentValue(Integer.MIN_VALUE, Integer.MAX_VALUE, (long) value, Direction.PREV);
}

return Optional.empty();
}

Expand All @@ -69,6 +77,12 @@ public static Optional<Object> getNextValue(Type type, Object value)
return getAdjacentValue((long) typeRange.getMin(), (long) typeRange.getMax(), (long) value, Direction.NEXT);
}

if (type == DATE) {
// TODO update the code here when type implements getRange
verify(type.getRange().isEmpty(), "Type %s unexpectedly returned a range", type);
return getAdjacentValue(Integer.MIN_VALUE, Integer.MAX_VALUE, (long) value, Direction.NEXT);
}

return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,13 +1290,13 @@ public void testDayTransformDate()
.isFullyPushedDown();

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

// d comparison with TIMESTAMP can be unwrapped
assertThat(query("SELECT * FROM test_day_transform_date WHERE d >= TIMESTAMP '2015-01-13 00:00:00'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on date
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_day_transform_date WHERE d >= TIMESTAMP '2015-01-13 00:00:00.000001'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on date
.isFullyPushedDown();

dropTable("test_day_transform_date");
}
Expand Down Expand Up @@ -1508,13 +1508,13 @@ public void testMonthTransformDate()
.isFullyPushedDown();

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

// d comparison with TIMESTAMP can be unwrapped
assertThat(query("SELECT * FROM test_month_transform_date WHERE d >= TIMESTAMP '2015-06-01 00:00:00'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on date
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_month_transform_date WHERE d >= TIMESTAMP '2015-05-01 00:00:00.000001'"))
.isNotFullyPushedDown(FilterNode.class);

Expand Down Expand Up @@ -1723,13 +1723,13 @@ public void testYearTransformDate()
.isFullyPushedDown();

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

// d comparison with TIMESTAMP can be unwrapped
assertThat(query("SELECT * FROM test_year_transform_date WHERE d >= TIMESTAMP '2015-01-01 00:00:00'"))
.isNotFullyPushedDown(FilterNode.class); // TODO subsume partition boundary filters on date
.isFullyPushedDown();
assertThat(query("SELECT * FROM test_year_transform_date WHERE d >= TIMESTAMP '2015-01-01 00:00:00.000001'"))
.isNotFullyPushedDown(FilterNode.class);

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

Expand Down

0 comments on commit 9afe194

Please sign in to comment.