Skip to content

Commit

Permalink
feat: add additional time partitioning intervals (#737)
Browse files Browse the repository at this point in the history
* feat: add additional time partitioning intervals

* docstring updates based on comments
  • Loading branch information
stephaniewang526 authored Sep 17, 2020
1 parent 4e0d5a9 commit a57dbdf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ public abstract class TimePartitioning implements Serializable {
private static final long serialVersionUID = -8565064035346940951L;

/**
* The supported types are DAY, which will generate one partition per day, and HOUR, which will
* generate one partition per hour. (Providing an empty string used to cause an error, but in
* OnePlatform the field will be treated as unset.)
* [Optional] The supported types are DAY, HOUR, MONTH, and YEAR, which will generate one
* partition per day, hour, month, and year, respectively. When the interval is not specified, the
* default behavior is DAY.
*/
public enum Type {

/** Table is partitioned per day, based on data loading time. */
/** Table is partitioned per day. */
DAY,
/** Table is partitioned per hour, based on data loading time. */
HOUR
/** Table is partitioned per hour. */
HOUR,
/** Table is partitioned per month. */
MONTH,
/** Table is partitioned per year. */
YEAR
}

TimePartitioning() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class TimePartitioningTest {

private static final Type TYPE_DAY = Type.DAY;
private static final Type TYPE_HOUR = Type.HOUR;
private static final Type TYPE_MONTH = Type.MONTH;
private static final Type TYPE_YEAR = Type.YEAR;
private static final long EXPIRATION_MS = 42;
private static final boolean REQUIRE_PARTITION_FILTER = false;
private static final String FIELD = "field";
Expand All @@ -44,11 +46,25 @@ public class TimePartitioningTest {
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
.setField(FIELD)
.build();
private static final TimePartitioning TIME_PARTITIONING_MONTH =
TimePartitioning.newBuilder(TYPE_MONTH)
.setExpirationMs(EXPIRATION_MS)
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
.setField(FIELD)
.build();
private static final TimePartitioning TIME_PARTITIONING_YEAR =
TimePartitioning.newBuilder(TYPE_YEAR)
.setExpirationMs(EXPIRATION_MS)
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
.setField(FIELD)
.build();

@Test
public void testOf() {
assertEquals(TYPE_DAY, TIME_PARTITIONING_DAY.getType());
assertEquals(TYPE_HOUR, TIME_PARTITIONING_HOUR.getType());
assertEquals(TYPE_MONTH, TIME_PARTITIONING_MONTH.getType());
assertEquals(TYPE_YEAR, TIME_PARTITIONING_YEAR.getType());
assertEquals(EXPIRATION_MS, TIME_PARTITIONING_DAY.getExpirationMs().longValue());
assertEquals(REQUIRE_PARTITION_FILTER, TIME_PARTITIONING_DAY.getRequirePartitionFilter());
assertEquals(FIELD, TIME_PARTITIONING_DAY.getField());
Expand Down

0 comments on commit a57dbdf

Please sign in to comment.