1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
2020
21+ import com .google .api .core .BetaApi ;
22+ import com .google .auto .value .AutoValue ;
2123import com .google .common .base .MoreObjects ;
2224
25+ import javax .annotation .Nullable ;
2326import java .io .Serializable ;
2427import java .util .Objects ;
2528
3033 *
3134 * @see <a href="https://cloud.google.com/bigquery/docs/partitioned-tables">Partitioned Tables</a>
3235 */
33- public final class TimePartitioning implements Serializable {
36+ @ AutoValue
37+ public abstract class TimePartitioning implements Serializable {
3438
3539 private static final long serialVersionUID = -8565064035346940951L ;
3640
37- private final Type type ;
38- private final Long expirationMs ;
39-
4041 /**
4142 * The type of time partitioning. Currently, the only type supported is {@code DAY}, which will
4243 * generate one partition per day based on data loading time.
@@ -49,47 +50,66 @@ public enum Type {
4950 DAY
5051 }
5152
52- private TimePartitioning (Type type , Long expirationMs ) {
53- this .type = checkNotNull (type );
54- this .expirationMs = expirationMs ;
53+ TimePartitioning () {
54+ // Users cannot extend this, but AutoValue can.
5555 }
5656
57-
5857 /**
5958 * Returns the time partitioning type. Currently, the only type supported is {@link Type#DAY},
6059 * which will generate one partition per day based on data loading time.
6160 */
62- public Type getType () {
63- return type ;
64- }
61+ public abstract Type getType ();
6562
6663
6764 /**
6865 * Returns the number of milliseconds for which to keep the storage for a partition. When expired,
6966 * the storage for the partition is reclaimed.
7067 */
71- public Long getExpirationMs () {
72- return expirationMs ;
73- }
68+ @ Nullable
69+ public abstract Long getExpirationMs ();
7470
75- @ Override
76- public String toString () {
77- return MoreObjects .toStringHelper (this )
78- .add ("type" , type )
79- .add ("expirationMs" , expirationMs )
80- .toString ();
81- }
8271
83- @ Override
84- public int hashCode () {
85- return Objects .hash (type , expirationMs );
72+ /**
73+ * If not set, the table is partitioned by pseudo column '_PARTITIONTIME'; if set, the table is
74+ * partitioned by this field.
75+ */
76+ @ BetaApi
77+ @ Nullable
78+ public abstract String getField ();
79+
80+
81+ /**
82+ * If set to true, queries over this table require a partition filter (that can be used for
83+ * partition elimination) to be specified.
84+ */
85+ @ BetaApi
86+ @ Nullable
87+ public abstract Boolean getRequirePartitionFilter ();
88+
89+ public abstract Builder toBuilder ();
90+
91+ @ AutoValue .Builder
92+ public abstract static class Builder {
93+ abstract Builder setType (Type type );
94+
95+ public abstract Builder setExpirationMs (Long expirationMs );
96+
97+ @ BetaApi
98+ public abstract Builder setRequirePartitionFilter (Boolean requirePartitionFilter );
99+
100+ @ BetaApi
101+ public abstract Builder setField (String field );
102+
103+ public abstract TimePartitioning build ();
86104 }
87105
88- @ Override
89- public boolean equals (Object obj ) {
90- return obj == this
91- || obj instanceof TimePartitioning
92- && Objects .equals (toPb (), ((TimePartitioning ) obj ).toPb ());
106+ /**
107+ * Returns a {@code TimePartitioning} object given the time partitioning type. Currently, the only
108+ * type supported is {@link Type#DAY}, which will generate one partition per day based on data
109+ * loading time.
110+ */
111+ public static Builder newBuilder (Type type ) {
112+ return new AutoValue_TimePartitioning .Builder ().setType (type );
93113 }
94114
95115 /**
@@ -98,7 +118,7 @@ public boolean equals(Object obj) {
98118 * loading time.
99119 */
100120 public static TimePartitioning of (Type type ) {
101- return new TimePartitioning (type , null );
121+ return newBuilder (type ). build ( );
102122 }
103123
104124 /**
@@ -110,20 +130,25 @@ public static TimePartitioning of(Type type) {
110130 * @param expirationMs the number of milliseconds for which to keep the storage for a partition
111131 */
112132 public static TimePartitioning of (Type type , long expirationMs ) {
113- return new TimePartitioning (type , expirationMs );
133+ return newBuilder (type ). setExpirationMs ( expirationMs ). build ( );
114134 }
115135
116136 com .google .api .services .bigquery .model .TimePartitioning toPb () {
117137 com .google .api .services .bigquery .model .TimePartitioning partitioningPb =
118138 new com .google .api .services .bigquery .model .TimePartitioning ();
119- partitioningPb .setType (type .name ());
120- partitioningPb .setExpirationMs (expirationMs );
139+ partitioningPb .setType (getType ().name ());
140+ partitioningPb .setExpirationMs (getExpirationMs ());
141+ partitioningPb .setRequirePartitionFilter (getRequirePartitionFilter ());
142+ partitioningPb .setField (getField ());
121143 return partitioningPb ;
122144 }
123145
124146 static TimePartitioning fromPb (
125147 com .google .api .services .bigquery .model .TimePartitioning partitioningPb ) {
126- return new TimePartitioning (
127- Type .valueOf (partitioningPb .getType ()), partitioningPb .getExpirationMs ());
148+ return newBuilder (Type .valueOf (partitioningPb .getType ()))
149+ .setExpirationMs (partitioningPb .getExpirationMs ())
150+ .setField (partitioningPb .getField ())
151+ .setRequirePartitionFilter (partitioningPb .getRequirePartitionFilter ())
152+ .build ();
128153 }
129154}
0 commit comments