Skip to content

Commit 3e51ea0

Browse files
Praful Makanistephaniewang526
andauthored
feat: expose requirepartitionfilter field in table (#158)
* feat: expose requirepartitionfilter field in table * feat: modified java doc * feat: ignore differences * remove clirr-ignored-differences file this will no longer be needed * add TableInfo outer-class back * remove abstract implementation of setRequirePartitionFilter add empty default implementation instead in the public class * remove extraneous words * remove whitespaces * feat: update javadoc * feat: lint Co-authored-by: Stephanie Wang <[email protected]>
1 parent acc5d6c commit 3e51ea0

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public Builder setLabels(Map<String, String> labels) {
150150
return this;
151151
}
152152

153+
@Override
154+
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
155+
infoBuilder.setRequirePartitionFilter(requirePartitionFilter);
156+
return this;
157+
}
158+
153159
@Override
154160
public Table build() {
155161
return new Table(bigquery, infoBuilder);

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public Table apply(TableInfo tableInfo) {
7171
private final TableDefinition definition;
7272
private final EncryptionConfiguration encryptionConfiguration;
7373
private final Labels labels;
74+
private final Boolean requirePartitionFilter;
7475

7576
/** A builder for {@code TableInfo} objects. */
7677
public abstract static class Builder {
@@ -130,6 +131,10 @@ public abstract static class Builder {
130131
public abstract TableInfo build();
131132

132133
public abstract Builder setEncryptionConfiguration(EncryptionConfiguration configuration);
134+
135+
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
136+
return this;
137+
}
133138
}
134139

135140
static class BuilderImpl extends Builder {
@@ -149,6 +154,7 @@ static class BuilderImpl extends Builder {
149154
private TableDefinition definition;
150155
private EncryptionConfiguration encryptionConfiguration;
151156
private Labels labels = Labels.ZERO;
157+
private Boolean requirePartitionFilter;
152158

153159
BuilderImpl() {}
154160

@@ -168,6 +174,7 @@ static class BuilderImpl extends Builder {
168174
this.definition = tableInfo.definition;
169175
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
170176
this.labels = tableInfo.labels;
177+
this.requirePartitionFilter = tableInfo.requirePartitionFilter;
171178
}
172179

173180
BuilderImpl(Table tablePb) {
@@ -191,6 +198,7 @@ static class BuilderImpl extends Builder {
191198
new EncryptionConfiguration.Builder(tablePb.getEncryptionConfiguration()).build();
192199
}
193200
this.labels = Labels.fromPb(tablePb.getLabels());
201+
this.requirePartitionFilter = tablePb.getRequirePartitionFilter();
194202
}
195203

196204
@Override
@@ -283,6 +291,12 @@ public Builder setLabels(Map<String, String> labels) {
283291
return this;
284292
}
285293

294+
@Override
295+
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
296+
this.requirePartitionFilter = requirePartitionFilter;
297+
return this;
298+
}
299+
286300
@Override
287301
public TableInfo build() {
288302
return new TableInfo(this);
@@ -305,6 +319,7 @@ public TableInfo build() {
305319
this.definition = builder.definition;
306320
this.encryptionConfiguration = builder.encryptionConfiguration;
307321
labels = builder.labels;
322+
this.requirePartitionFilter = builder.requirePartitionFilter;
308323
}
309324

310325
/** Returns the hash of the table resource. */
@@ -399,6 +414,14 @@ public Map<String, String> getLabels() {
399414
return labels.userMap();
400415
}
401416

417+
/**
418+
* Returns true if a partition filter (that can be used for partition elimination) is required for
419+
* queries over this table.
420+
*/
421+
public Boolean getRequirePartitionFilter() {
422+
return requirePartitionFilter;
423+
}
424+
402425
/** Returns a builder for the table object. */
403426
public Builder toBuilder() {
404427
return new BuilderImpl(this);
@@ -422,6 +445,7 @@ public String toString() {
422445
.add("definition", definition)
423446
.add("encryptionConfiguration", encryptionConfiguration)
424447
.add("labels", labels)
448+
.add("requirePartitionFilter", requirePartitionFilter)
425449
.toString();
426450
}
427451

@@ -482,6 +506,7 @@ Table toPb() {
482506
tablePb.setEncryptionConfiguration(encryptionConfiguration.toPb());
483507
}
484508
tablePb.setLabels(labels.toPb());
509+
tablePb.setRequirePartitionFilter(requirePartitionFilter);
485510
return tablePb;
486511
}
487512

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class TableInfoTest {
3636
private static final Long CREATION_TIME = 10L;
3737
private static final Long EXPIRATION_TIME = 100L;
3838
private static final Long LAST_MODIFIED_TIME = 20L;
39+
private static final Boolean REQUIRE_PARTITION_FILTER = true;
40+
private static final EncryptionConfiguration ENCRYPTION_CONFIGURATION =
41+
EncryptionConfiguration.newBuilder().setKmsKeyName("KMS_KEY_1").build();
3942

4043
private static final Field FIELD_SCHEMA1 =
4144
Field.newBuilder("StringField", LegacySQLTypeName.STRING)
@@ -91,6 +94,7 @@ public class TableInfoTest {
9194
TableInfo.newBuilder(TABLE_ID, TABLE_DEFINITION)
9295
.setCreationTime(CREATION_TIME)
9396
.setDescription(DESCRIPTION)
97+
.setEncryptionConfiguration(ENCRYPTION_CONFIGURATION)
9498
.setEtag(ETAG)
9599
.setExpirationTime(EXPIRATION_TIME)
96100
.setFriendlyName(FRIENDLY_NAME)
@@ -101,6 +105,7 @@ public class TableInfoTest {
101105
.setNumRows(BigInteger.valueOf(NUM_ROWS))
102106
.setSelfLink(SELF_LINK)
103107
.setLabels(Collections.singletonMap("a", "b"))
108+
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
104109
.build();
105110
private static final TableInfo VIEW_INFO =
106111
TableInfo.newBuilder(TABLE_ID, VIEW_DEFINITION)
@@ -151,6 +156,7 @@ public void testBuilder() {
151156
assertEquals(TABLE_ID, TABLE_INFO.getTableId());
152157
assertEquals(CREATION_TIME, TABLE_INFO.getCreationTime());
153158
assertEquals(DESCRIPTION, TABLE_INFO.getDescription());
159+
assertEquals(ENCRYPTION_CONFIGURATION, TABLE_INFO.getEncryptionConfiguration());
154160
assertEquals(ETAG, TABLE_INFO.getEtag());
155161
assertEquals(EXPIRATION_TIME, TABLE_INFO.getExpirationTime());
156162
assertEquals(FRIENDLY_NAME, TABLE_INFO.getFriendlyName());
@@ -161,6 +167,7 @@ public void testBuilder() {
161167
assertEquals(NUM_BYTES, TABLE_INFO.getNumBytes());
162168
assertEquals(NUM_LONG_TERM_BYTES, TABLE_INFO.getNumLongTermBytes());
163169
assertEquals(BigInteger.valueOf(NUM_ROWS), TABLE_INFO.getNumRows());
170+
assertEquals(REQUIRE_PARTITION_FILTER, TABLE_INFO.getRequirePartitionFilter());
164171

165172
assertEquals(TABLE_ID, VIEW_INFO.getTableId());
166173
assertEquals(VIEW_DEFINITION, VIEW_INFO.getDefinition());
@@ -192,33 +199,39 @@ public void testOf() {
192199
assertEquals(TABLE_ID, tableInfo.getTableId());
193200
assertNull(tableInfo.getCreationTime());
194201
assertNull(tableInfo.getDescription());
202+
assertNull(tableInfo.getEncryptionConfiguration());
195203
assertNull(tableInfo.getEtag());
196204
assertNull(tableInfo.getExpirationTime());
197205
assertNull(tableInfo.getFriendlyName());
198206
assertNull(tableInfo.getGeneratedId());
199207
assertNull(tableInfo.getLastModifiedTime());
208+
assertNull(tableInfo.getRequirePartitionFilter());
200209
assertEquals(TABLE_DEFINITION, tableInfo.getDefinition());
201210
assertNull(tableInfo.getSelfLink());
202211
tableInfo = TableInfo.of(TABLE_ID, VIEW_DEFINITION);
203212
assertEquals(TABLE_ID, tableInfo.getTableId());
204213
assertNull(tableInfo.getCreationTime());
205214
assertNull(tableInfo.getDescription());
215+
assertNull(tableInfo.getEncryptionConfiguration());
206216
assertNull(tableInfo.getEtag());
207217
assertNull(tableInfo.getExpirationTime());
208218
assertNull(tableInfo.getFriendlyName());
209219
assertNull(tableInfo.getGeneratedId());
210220
assertNull(tableInfo.getLastModifiedTime());
221+
assertNull(tableInfo.getRequirePartitionFilter());
211222
assertEquals(VIEW_DEFINITION, tableInfo.getDefinition());
212223
assertNull(tableInfo.getSelfLink());
213224
tableInfo = TableInfo.of(TABLE_ID, EXTERNAL_TABLE_DEFINITION);
214225
assertEquals(TABLE_ID, tableInfo.getTableId());
215226
assertNull(tableInfo.getCreationTime());
216227
assertNull(tableInfo.getDescription());
228+
assertNull(tableInfo.getEncryptionConfiguration());
217229
assertNull(tableInfo.getEtag());
218230
assertNull(tableInfo.getExpirationTime());
219231
assertNull(tableInfo.getFriendlyName());
220232
assertNull(tableInfo.getGeneratedId());
221233
assertNull(tableInfo.getLastModifiedTime());
234+
assertNull(tableInfo.getRequirePartitionFilter());
222235
assertEquals(EXTERNAL_TABLE_DEFINITION, tableInfo.getDefinition());
223236
assertNull(tableInfo.getSelfLink());
224237
}
@@ -250,6 +263,7 @@ private void compareTableInfo(TableInfo expected, TableInfo value) {
250263
assertEquals(expected.getDefinition(), value.getDefinition());
251264
assertEquals(expected.getCreationTime(), value.getCreationTime());
252265
assertEquals(expected.getDescription(), value.getDescription());
266+
assertEquals(expected.getEncryptionConfiguration(), value.getEncryptionConfiguration());
253267
assertEquals(expected.getEtag(), value.getEtag());
254268
assertEquals(expected.getExpirationTime(), value.getExpirationTime());
255269
assertEquals(expected.getFriendlyName(), value.getFriendlyName());
@@ -260,6 +274,8 @@ private void compareTableInfo(TableInfo expected, TableInfo value) {
260274
assertEquals(expected.getNumRows(), value.getNumRows());
261275
assertEquals(expected.getSelfLink(), value.getSelfLink());
262276
assertEquals(expected.getLabels(), value.getLabels());
277+
assertEquals(expected.getRequirePartitionFilter(), value.getRequirePartitionFilter());
278+
assertEquals(expected.toString(), value.toString());
263279
assertEquals(expected.hashCode(), value.hashCode());
264280
}
265281
}

0 commit comments

Comments
 (0)