16
16
17
17
package com .google .cloud .bigquery ;
18
18
19
- import static com .google .common .base .Preconditions . checkNotNull ;
19
+ import static com .google .common .base .MoreObjects . firstNonNull ;
20
20
21
+ import com .google .api .client .util .Data ;
21
22
import com .google .api .core .BetaApi ;
22
23
import com .google .auto .value .AutoValue ;
23
- import com .google .common .base .MoreObjects ;
24
-
25
- import javax .annotation .Nullable ;
26
24
import java .io .Serializable ;
27
- import java . util . Objects ;
25
+ import javax . annotation . Nullable ;
28
26
29
27
/**
30
28
* Objects of this class allow to configure table partitioning based on time. By dividing a large
@@ -63,7 +61,7 @@ public enum Type {
63
61
64
62
/**
65
63
* Returns the number of milliseconds for which to keep the storage for a partition. When expired,
66
- * the storage for the partition is reclaimed.
64
+ * the storage for the partition is reclaimed. If null, the partion does not expire.
67
65
*/
68
66
@ Nullable
69
67
public abstract Long getExpirationMs ();
@@ -115,7 +113,7 @@ public static Builder newBuilder(Type type) {
115
113
/**
116
114
* Returns a {@code TimePartitioning} object given the time partitioning type. Currently, the only
117
115
* type supported is {@link Type#DAY}, which will generate one partition per day based on data
118
- * loading time.
116
+ * loading time. The partitions will not expire.
119
117
*/
120
118
public static TimePartitioning of (Type type ) {
121
119
return newBuilder (type ).build ();
@@ -137,18 +135,22 @@ com.google.api.services.bigquery.model.TimePartitioning toPb() {
137
135
com .google .api .services .bigquery .model .TimePartitioning partitioningPb =
138
136
new com .google .api .services .bigquery .model .TimePartitioning ();
139
137
partitioningPb .setType (getType ().name ());
140
- partitioningPb .setExpirationMs (getExpirationMs ());
138
+ partitioningPb .setExpirationMs (firstNonNull ( getExpirationMs (), Data . NULL_LONG ));
141
139
partitioningPb .setRequirePartitionFilter (getRequirePartitionFilter ());
142
140
partitioningPb .setField (getField ());
143
141
return partitioningPb ;
144
142
}
145
143
146
144
static TimePartitioning fromPb (
147
145
com .google .api .services .bigquery .model .TimePartitioning partitioningPb ) {
146
+ Long expirationMs = partitioningPb .getExpirationMs ();
147
+ if (Data .isNull (expirationMs )) {
148
+ expirationMs = null ;
149
+ }
148
150
return newBuilder (Type .valueOf (partitioningPb .getType ()))
149
- .setExpirationMs (partitioningPb . getExpirationMs () )
150
- .setField (partitioningPb .getField ())
151
- .setRequirePartitionFilter (partitioningPb .getRequirePartitionFilter ())
152
- .build ();
151
+ .setExpirationMs (expirationMs )
152
+ .setField (partitioningPb .getField ())
153
+ .setRequirePartitionFilter (partitioningPb .getRequirePartitionFilter ())
154
+ .build ();
153
155
}
154
156
}
0 commit comments