Skip to content

Commit 90f9980

Browse files
feat: add hourly partitioning support (#336)
Fixes b/154849483
1 parent 9cb5ba3 commit 90f9980

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TimePartitioning.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ public abstract class TimePartitioning implements Serializable {
3737
private static final long serialVersionUID = -8565064035346940951L;
3838

3939
/**
40-
* The type of time partitioning. Currently, the only type supported is {@code DAY}, which will
41-
* generate one partition per day based on data loading time.
40+
* The supported types are DAY, which will generate one partition per day, and HOUR, which will
41+
* generate one partition per hour. (Providing an empty string used to cause an error, but in
42+
* OnePlatform the field will be treated as unset.)
4243
*/
4344
public enum Type {
4445

4546
/** Table is partitioned per day, based on data loading time. */
46-
DAY
47+
DAY,
48+
/** Table is partitioned per hour, based on data loading time. */
49+
HOUR
4750
}
4851

4952
TimePartitioning() {
5053
// Users cannot extend this, but AutoValue can.
5154
}
5255

53-
/**
54-
* Returns the time partitioning type. Currently, the only type supported is {@link Type#DAY},
55-
* which will generate one partition per day based on data loading time.
56-
*/
56+
/** Returns the time partitioning type. */
5757
public abstract Type getType();
5858

5959
/**
@@ -96,19 +96,14 @@ public abstract static class Builder {
9696
public abstract TimePartitioning build();
9797
}
9898

99-
/**
100-
* Returns a {@code TimePartitioning} object given the time partitioning type. Currently, the only
101-
* type supported is {@link Type#DAY}, which will generate one partition per day based on data
102-
* loading time.
103-
*/
99+
/** Returns a {@code TimePartitioning} object given the time partitioning type. */
104100
public static Builder newBuilder(Type type) {
105101
return new AutoValue_TimePartitioning.Builder().setType(type);
106102
}
107103

108104
/**
109-
* Returns a {@code TimePartitioning} object given the time partitioning type. Currently, the only
110-
* type supported is {@link Type#DAY}, which will generate one partition per day based on data
111-
* loading time. The partitions will not expire.
105+
* Returns a {@code TimePartitioning} object given the time partitioning type. The partitions will
106+
* not expire.
112107
*/
113108
public static TimePartitioning of(Type type) {
114109
return newBuilder(type).build();
@@ -118,8 +113,7 @@ public static TimePartitioning of(Type type) {
118113
* Returns a {@code TimePartitioning} object given the time partitioning type and the partition's
119114
* expiration in milliseconds.
120115
*
121-
* @param type the time partitioning type. Currently, the only type supported is {@link Type#DAY},
122-
* which will generate one partition per day based on data loading time.
116+
* @param type the time partitioning type.
123117
* @param expirationMs the number of milliseconds for which to keep the storage for a partition
124118
*/
125119
public static TimePartitioning of(Type type, long expirationMs) {

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TimePartitioningTest.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,45 @@
2626

2727
public class TimePartitioningTest {
2828

29-
private static final Type TYPE = Type.DAY;
29+
private static final Type TYPE_DAY = Type.DAY;
30+
private static final Type TYPE_HOUR = Type.HOUR;
3031
private static final long EXPIRATION_MS = 42;
3132
private static final boolean REQUIRE_PARTITION_FILTER = false;
3233
private static final String FIELD = "field";
33-
private static final TimePartitioning TIME_PARTITIONING =
34-
TimePartitioning.newBuilder(TYPE)
34+
private static final TimePartitioning TIME_PARTITIONING_DAY =
35+
TimePartitioning.newBuilder(TYPE_DAY)
36+
.setExpirationMs(EXPIRATION_MS)
37+
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
38+
.setField(FIELD)
39+
.build();
40+
private static final TimePartitioning TIME_PARTITIONING_HOUR =
41+
TimePartitioning.newBuilder(TYPE_HOUR)
3542
.setExpirationMs(EXPIRATION_MS)
3643
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
3744
.setField(FIELD)
3845
.build();
3946

4047
@Test
4148
public void testOf() {
42-
assertEquals(TYPE, TIME_PARTITIONING.getType());
43-
assertEquals(EXPIRATION_MS, TIME_PARTITIONING.getExpirationMs().longValue());
44-
assertEquals(REQUIRE_PARTITION_FILTER, TIME_PARTITIONING.getRequirePartitionFilter());
45-
assertEquals(FIELD, TIME_PARTITIONING.getField());
46-
TimePartitioning partitioning = TimePartitioning.of(TYPE);
47-
assertEquals(TYPE, partitioning.getType());
49+
assertEquals(TYPE_DAY, TIME_PARTITIONING_DAY.getType());
50+
assertEquals(TYPE_HOUR, TIME_PARTITIONING_HOUR.getType());
51+
assertEquals(EXPIRATION_MS, TIME_PARTITIONING_DAY.getExpirationMs().longValue());
52+
assertEquals(REQUIRE_PARTITION_FILTER, TIME_PARTITIONING_DAY.getRequirePartitionFilter());
53+
assertEquals(FIELD, TIME_PARTITIONING_DAY.getField());
54+
TimePartitioning partitioning = TimePartitioning.of(TYPE_DAY);
55+
assertEquals(TYPE_DAY, partitioning.getType());
4856
assertNull(partitioning.getExpirationMs());
4957
}
5058

5159
@Test
5260
public void testBuilder() {
53-
TimePartitioning partitioning = TimePartitioning.newBuilder(TYPE).build();
54-
assertEquals(TYPE, partitioning.getType());
61+
TimePartitioning partitioning = TimePartitioning.newBuilder(TYPE_DAY).build();
62+
assertEquals(TYPE_DAY, partitioning.getType());
5563
assertNull(partitioning.getExpirationMs());
5664
assertNull(partitioning.getRequirePartitionFilter());
5765
assertNull(partitioning.getField());
58-
partitioning = TimePartitioning.newBuilder(TYPE).setExpirationMs(100L).build();
59-
assertEquals(TYPE, partitioning.getType());
66+
partitioning = TimePartitioning.newBuilder(TYPE_DAY).setExpirationMs(100L).build();
67+
assertEquals(TYPE_DAY, partitioning.getType());
6068
assertEquals(100, (long) partitioning.getExpirationMs());
6169
assertNull(partitioning.getRequirePartitionFilter());
6270
assertNull(partitioning.getField());
@@ -84,8 +92,9 @@ public void testTypeAndExpirationOf_Npe() {
8492

8593
@Test
8694
public void testToAndFromPb() {
87-
compareTimePartitioning(TIME_PARTITIONING, TimePartitioning.fromPb(TIME_PARTITIONING.toPb()));
88-
TimePartitioning partitioning = TimePartitioning.of(TYPE);
95+
compareTimePartitioning(
96+
TIME_PARTITIONING_DAY, TimePartitioning.fromPb(TIME_PARTITIONING_DAY.toPb()));
97+
TimePartitioning partitioning = TimePartitioning.of(TYPE_DAY);
8998
compareTimePartitioning(partitioning, TimePartitioning.fromPb(partitioning.toPb()));
9099
}
91100

0 commit comments

Comments
 (0)