Skip to content

Commit

Permalink
feat: expose requirepartitionfilter field in table (#158)
Browse files Browse the repository at this point in the history
* 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 <stephaniewang526@users.noreply.github.com>
  • Loading branch information
Praful Makani and stephaniewang526 committed Feb 27, 2020
1 parent acc5d6c commit 3e51ea0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Expand Up @@ -150,6 +150,12 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

@Override
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
infoBuilder.setRequirePartitionFilter(requirePartitionFilter);
return this;
}

@Override
public Table build() {
return new Table(bigquery, infoBuilder);
Expand Down
Expand Up @@ -71,6 +71,7 @@ public Table apply(TableInfo tableInfo) {
private final TableDefinition definition;
private final EncryptionConfiguration encryptionConfiguration;
private final Labels labels;
private final Boolean requirePartitionFilter;

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

public abstract Builder setEncryptionConfiguration(EncryptionConfiguration configuration);

public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
return this;
}
}

static class BuilderImpl extends Builder {
Expand All @@ -149,6 +154,7 @@ static class BuilderImpl extends Builder {
private TableDefinition definition;
private EncryptionConfiguration encryptionConfiguration;
private Labels labels = Labels.ZERO;
private Boolean requirePartitionFilter;

BuilderImpl() {}

Expand All @@ -168,6 +174,7 @@ static class BuilderImpl extends Builder {
this.definition = tableInfo.definition;
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
this.labels = tableInfo.labels;
this.requirePartitionFilter = tableInfo.requirePartitionFilter;
}

BuilderImpl(Table tablePb) {
Expand All @@ -191,6 +198,7 @@ static class BuilderImpl extends Builder {
new EncryptionConfiguration.Builder(tablePb.getEncryptionConfiguration()).build();
}
this.labels = Labels.fromPb(tablePb.getLabels());
this.requirePartitionFilter = tablePb.getRequirePartitionFilter();
}

@Override
Expand Down Expand Up @@ -283,6 +291,12 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

@Override
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
this.requirePartitionFilter = requirePartitionFilter;
return this;
}

@Override
public TableInfo build() {
return new TableInfo(this);
Expand All @@ -305,6 +319,7 @@ public TableInfo build() {
this.definition = builder.definition;
this.encryptionConfiguration = builder.encryptionConfiguration;
labels = builder.labels;
this.requirePartitionFilter = builder.requirePartitionFilter;
}

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

/**
* Returns true if a partition filter (that can be used for partition elimination) is required for
* queries over this table.
*/
public Boolean getRequirePartitionFilter() {
return requirePartitionFilter;
}

/** Returns a builder for the table object. */
public Builder toBuilder() {
return new BuilderImpl(this);
Expand All @@ -422,6 +445,7 @@ public String toString() {
.add("definition", definition)
.add("encryptionConfiguration", encryptionConfiguration)
.add("labels", labels)
.add("requirePartitionFilter", requirePartitionFilter)
.toString();
}

Expand Down Expand Up @@ -482,6 +506,7 @@ Table toPb() {
tablePb.setEncryptionConfiguration(encryptionConfiguration.toPb());
}
tablePb.setLabels(labels.toPb());
tablePb.setRequirePartitionFilter(requirePartitionFilter);
return tablePb;
}

Expand Down
Expand Up @@ -36,6 +36,9 @@ public class TableInfoTest {
private static final Long CREATION_TIME = 10L;
private static final Long EXPIRATION_TIME = 100L;
private static final Long LAST_MODIFIED_TIME = 20L;
private static final Boolean REQUIRE_PARTITION_FILTER = true;
private static final EncryptionConfiguration ENCRYPTION_CONFIGURATION =
EncryptionConfiguration.newBuilder().setKmsKeyName("KMS_KEY_1").build();

private static final Field FIELD_SCHEMA1 =
Field.newBuilder("StringField", LegacySQLTypeName.STRING)
Expand Down Expand Up @@ -91,6 +94,7 @@ public class TableInfoTest {
TableInfo.newBuilder(TABLE_ID, TABLE_DEFINITION)
.setCreationTime(CREATION_TIME)
.setDescription(DESCRIPTION)
.setEncryptionConfiguration(ENCRYPTION_CONFIGURATION)
.setEtag(ETAG)
.setExpirationTime(EXPIRATION_TIME)
.setFriendlyName(FRIENDLY_NAME)
Expand All @@ -101,6 +105,7 @@ public class TableInfoTest {
.setNumRows(BigInteger.valueOf(NUM_ROWS))
.setSelfLink(SELF_LINK)
.setLabels(Collections.singletonMap("a", "b"))
.setRequirePartitionFilter(REQUIRE_PARTITION_FILTER)
.build();
private static final TableInfo VIEW_INFO =
TableInfo.newBuilder(TABLE_ID, VIEW_DEFINITION)
Expand Down Expand Up @@ -151,6 +156,7 @@ public void testBuilder() {
assertEquals(TABLE_ID, TABLE_INFO.getTableId());
assertEquals(CREATION_TIME, TABLE_INFO.getCreationTime());
assertEquals(DESCRIPTION, TABLE_INFO.getDescription());
assertEquals(ENCRYPTION_CONFIGURATION, TABLE_INFO.getEncryptionConfiguration());
assertEquals(ETAG, TABLE_INFO.getEtag());
assertEquals(EXPIRATION_TIME, TABLE_INFO.getExpirationTime());
assertEquals(FRIENDLY_NAME, TABLE_INFO.getFriendlyName());
Expand All @@ -161,6 +167,7 @@ public void testBuilder() {
assertEquals(NUM_BYTES, TABLE_INFO.getNumBytes());
assertEquals(NUM_LONG_TERM_BYTES, TABLE_INFO.getNumLongTermBytes());
assertEquals(BigInteger.valueOf(NUM_ROWS), TABLE_INFO.getNumRows());
assertEquals(REQUIRE_PARTITION_FILTER, TABLE_INFO.getRequirePartitionFilter());

assertEquals(TABLE_ID, VIEW_INFO.getTableId());
assertEquals(VIEW_DEFINITION, VIEW_INFO.getDefinition());
Expand Down Expand Up @@ -192,33 +199,39 @@ public void testOf() {
assertEquals(TABLE_ID, tableInfo.getTableId());
assertNull(tableInfo.getCreationTime());
assertNull(tableInfo.getDescription());
assertNull(tableInfo.getEncryptionConfiguration());
assertNull(tableInfo.getEtag());
assertNull(tableInfo.getExpirationTime());
assertNull(tableInfo.getFriendlyName());
assertNull(tableInfo.getGeneratedId());
assertNull(tableInfo.getLastModifiedTime());
assertNull(tableInfo.getRequirePartitionFilter());
assertEquals(TABLE_DEFINITION, tableInfo.getDefinition());
assertNull(tableInfo.getSelfLink());
tableInfo = TableInfo.of(TABLE_ID, VIEW_DEFINITION);
assertEquals(TABLE_ID, tableInfo.getTableId());
assertNull(tableInfo.getCreationTime());
assertNull(tableInfo.getDescription());
assertNull(tableInfo.getEncryptionConfiguration());
assertNull(tableInfo.getEtag());
assertNull(tableInfo.getExpirationTime());
assertNull(tableInfo.getFriendlyName());
assertNull(tableInfo.getGeneratedId());
assertNull(tableInfo.getLastModifiedTime());
assertNull(tableInfo.getRequirePartitionFilter());
assertEquals(VIEW_DEFINITION, tableInfo.getDefinition());
assertNull(tableInfo.getSelfLink());
tableInfo = TableInfo.of(TABLE_ID, EXTERNAL_TABLE_DEFINITION);
assertEquals(TABLE_ID, tableInfo.getTableId());
assertNull(tableInfo.getCreationTime());
assertNull(tableInfo.getDescription());
assertNull(tableInfo.getEncryptionConfiguration());
assertNull(tableInfo.getEtag());
assertNull(tableInfo.getExpirationTime());
assertNull(tableInfo.getFriendlyName());
assertNull(tableInfo.getGeneratedId());
assertNull(tableInfo.getLastModifiedTime());
assertNull(tableInfo.getRequirePartitionFilter());
assertEquals(EXTERNAL_TABLE_DEFINITION, tableInfo.getDefinition());
assertNull(tableInfo.getSelfLink());
}
Expand Down Expand Up @@ -250,6 +263,7 @@ private void compareTableInfo(TableInfo expected, TableInfo value) {
assertEquals(expected.getDefinition(), value.getDefinition());
assertEquals(expected.getCreationTime(), value.getCreationTime());
assertEquals(expected.getDescription(), value.getDescription());
assertEquals(expected.getEncryptionConfiguration(), value.getEncryptionConfiguration());
assertEquals(expected.getEtag(), value.getEtag());
assertEquals(expected.getExpirationTime(), value.getExpirationTime());
assertEquals(expected.getFriendlyName(), value.getFriendlyName());
Expand All @@ -260,6 +274,8 @@ private void compareTableInfo(TableInfo expected, TableInfo value) {
assertEquals(expected.getNumRows(), value.getNumRows());
assertEquals(expected.getSelfLink(), value.getSelfLink());
assertEquals(expected.getLabels(), value.getLabels());
assertEquals(expected.getRequirePartitionFilter(), value.getRequirePartitionFilter());
assertEquals(expected.toString(), value.toString());
assertEquals(expected.hashCode(), value.hashCode());
}
}

0 comments on commit 3e51ea0

Please sign in to comment.