Skip to content

Commit

Permalink
BigQuery: add long term storage bytes to standard table definition. (g…
Browse files Browse the repository at this point in the history
…oogleapis#4387)

* BigQuery: Add long term storage bytes for managed tables.

* formatting

* let maven format the things

* plumb this upwards into Table/TableInfo

* return

* assertion mismatch

* Update TableInfoTest.java
  • Loading branch information
shollyman authored and sduskis committed Mar 7, 2019
1 parent cc04990 commit 83ea49e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public abstract static class Builder

public abstract Builder setNumBytes(Long numBytes);

public abstract Builder setNumLongTermBytes(Long numLongTermBytes);

public abstract Builder setNumRows(Long numRows);

public abstract Builder setLocation(String location);
Expand Down Expand Up @@ -161,6 +163,15 @@ public abstract static class Builder
@Nullable
public abstract Long getNumBytes();

/**
* Returns the number of bytes considered "long-term storage" for reduced billing purposes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#long-term-storage">Long Term Storage
* Pricing</a>
*/
@Nullable
public abstract Long getNumLongTermBytes();

/** Returns the number of rows in this table, excluding any data in the streaming buffer. */
@Nullable
public abstract Long getNumRows();
Expand Down Expand Up @@ -221,6 +232,7 @@ Table toPb() {
tablePb.setNumRows(BigInteger.valueOf(getNumRows()));
}
tablePb.setNumBytes(getNumBytes());
tablePb.setNumLongTermBytes(getNumLongTermBytes());
tablePb.setLocation(getLocation());
if (getStreamingBuffer() != null) {
tablePb.setStreamingBuffer(getStreamingBuffer().toPb());
Expand Down Expand Up @@ -249,6 +261,9 @@ static StandardTableDefinition fromPb(Table tablePb) {
if (tablePb.getClustering() != null) {
builder.setClustering(Clustering.fromPb(tablePb.getClustering()));
}
if (tablePb.getNumLongTermBytes() != null) {
builder.setNumLongTermBytes(tablePb.getNumLongTermBytes());
}
return builder.setNumBytes(tablePb.getNumBytes()).setLocation(tablePb.getLocation()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ Builder setNumBytes(Long numBytes) {
return this;
}

@Override
Builder setNumLongTermBytes(Long numLongTermBytes) {
infoBuilder.setNumLongTermBytes(numLongTermBytes);
return this;
}

@Override
Builder setNumRows(BigInteger numRows) {
infoBuilder.setNumRows(numRows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public Table apply(TableInfo tableInfo) {
private final Long expirationTime;
private final Long lastModifiedTime;
private final Long numBytes;
private final Long numLongTermBytes;
private final BigInteger numRows;
private final TableDefinition definition;
private final EncryptionConfiguration encryptionConfiguration;
Expand Down Expand Up @@ -96,6 +97,8 @@ public abstract static class Builder {

abstract Builder setNumBytes(Long numBytes);

abstract Builder setNumLongTermBytes(Long numLongTermBytes);

abstract Builder setNumRows(BigInteger numRows);

abstract Builder setSelfLink(String selfLink);
Expand Down Expand Up @@ -141,6 +144,7 @@ static class BuilderImpl extends Builder {
private Long expirationTime;
private Long lastModifiedTime;
private Long numBytes;
private Long numLongTermBytes;
private BigInteger numRows;
private TableDefinition definition;
private EncryptionConfiguration encryptionConfiguration;
Expand All @@ -159,6 +163,7 @@ static class BuilderImpl extends Builder {
this.expirationTime = tableInfo.expirationTime;
this.lastModifiedTime = tableInfo.lastModifiedTime;
this.numBytes = tableInfo.numBytes;
this.numLongTermBytes = tableInfo.numLongTermBytes;
this.numRows = tableInfo.numRows;
this.definition = tableInfo.definition;
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
Expand All @@ -178,6 +183,7 @@ static class BuilderImpl extends Builder {
this.generatedId = tablePb.getId();
this.selfLink = tablePb.getSelfLink();
this.numBytes = tablePb.getNumBytes();
this.numLongTermBytes = tablePb.getNumLongTermBytes();
this.numRows = tablePb.getNumRows();
this.definition = TableDefinition.fromPb(tablePb);
if (tablePb.getEncryptionConfiguration() != null) {
Expand Down Expand Up @@ -235,6 +241,12 @@ Builder setNumBytes(Long numBytes) {
return this;
}

@Override
Builder setNumLongTermBytes(Long numLongTermBytes) {
this.numLongTermBytes = numLongTermBytes;
return this;
}

@Override
Builder setNumRows(BigInteger numRows) {
this.numRows = numRows;
Expand Down Expand Up @@ -288,6 +300,7 @@ public TableInfo build() {
this.expirationTime = builder.expirationTime;
this.lastModifiedTime = builder.lastModifiedTime;
this.numBytes = builder.numBytes;
this.numLongTermBytes = builder.numLongTermBytes;
this.numRows = builder.numRows;
this.definition = builder.definition;
this.encryptionConfiguration = builder.encryptionConfiguration;
Expand Down Expand Up @@ -360,6 +373,16 @@ public Long getNumBytes() {
return numBytes;
}

/**
* Returns the number of bytes considered "long-term storage" for reduced billing purposes.
*
* @see <a href="https://cloud.google.com/bigquery/pricing#long-term-storage">Long Term Storage
* Pricing</a>
*/
public Long getNumLongTermBytes() {
return numLongTermBytes;
}

/** Returns the number of rows of data in this table */
public BigInteger getNumRows() {
return numRows;
Expand Down Expand Up @@ -394,6 +417,7 @@ public String toString() {
.add("creationTime", creationTime)
.add("lastModifiedTime", lastModifiedTime)
.add("numBytes", numBytes)
.add("numLongTermBytes", numLongTermBytes)
.add("numRows", numRows)
.add("definition", definition)
.add("encryptionConfiguration", encryptionConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class StandardTableDefinitionTest {
.build();
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
private static final Long NUM_BYTES = 42L;
private static final Long NUM_LONG_TERM_BYTES = 18L;
private static final Long NUM_ROWS = 43L;
private static final String LOCATION = "US";
private static final StreamingBuffer STREAMING_BUFFER = new StreamingBuffer(1L, 2L, 3L);
Expand All @@ -56,6 +57,7 @@ public class StandardTableDefinitionTest {
.setLocation(LOCATION)
.setNumBytes(NUM_BYTES)
.setNumRows(NUM_ROWS)
.setNumLongTermBytes(NUM_LONG_TERM_BYTES)
.setStreamingBuffer(STREAMING_BUFFER)
.setSchema(TABLE_SCHEMA)
.setTimePartitioning(TIME_PARTITIONING)
Expand Down Expand Up @@ -84,6 +86,7 @@ public void testBuilder() {
assertEquals(TABLE_SCHEMA, TABLE_DEFINITION.getSchema());
assertEquals(LOCATION, TABLE_DEFINITION.getLocation());
assertEquals(NUM_BYTES, TABLE_DEFINITION.getNumBytes());
assertEquals(NUM_LONG_TERM_BYTES, TABLE_DEFINITION.getNumLongTermBytes());
assertEquals(NUM_ROWS, TABLE_DEFINITION.getNumRows());
assertEquals(STREAMING_BUFFER, TABLE_DEFINITION.getStreamingBuffer());
assertEquals(TIME_PARTITIONING, TABLE_DEFINITION.getTimePartitioning());
Expand All @@ -97,6 +100,7 @@ public void testOf() {
assertEquals(TABLE_SCHEMA, TABLE_DEFINITION.getSchema());
assertNull(definition.getLocation());
assertNull(definition.getNumBytes());
assertNull(definition.getNumLongTermBytes());
assertNull(definition.getNumRows());
assertNull(definition.getStreamingBuffer());
assertNull(definition.getTimePartitioning());
Expand Down Expand Up @@ -131,6 +135,7 @@ private void compareStandardTableDefinition(
assertEquals(expected.getSchema(), value.getSchema());
assertEquals(expected.getType(), value.getType());
assertEquals(expected.getNumBytes(), value.getNumBytes());
assertEquals(expected.getNumLongTermBytes(), value.getNumLongTermBytes());
assertEquals(expected.getNumRows(), value.getNumRows());
assertEquals(expected.getLocation(), value.getLocation());
assertEquals(expected.getStreamingBuffer(), value.getStreamingBuffer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class TableInfoTest {
.build();
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
private static final Long NUM_BYTES = 42L;
private static final Long NUM_LONG_TERM_BYTES = 21L;
private static final Long NUM_ROWS = 43L;
private static final String LOCATION = "US";
private static final StandardTableDefinition.StreamingBuffer STREAMING_BUFFER =
Expand All @@ -62,6 +63,7 @@ public class TableInfoTest {
StandardTableDefinition.newBuilder()
.setLocation(LOCATION)
.setNumBytes(NUM_BYTES)
.setNumLongTermBytes(NUM_LONG_TERM_BYTES)
.setNumRows(NUM_ROWS)
.setStreamingBuffer(STREAMING_BUFFER)
.setSchema(TABLE_SCHEMA)
Expand Down Expand Up @@ -95,6 +97,7 @@ public class TableInfoTest {
.setGeneratedId(GENERATED_ID)
.setLastModifiedTime(LAST_MODIFIED_TIME)
.setNumBytes(NUM_BYTES)
.setNumLongTermBytes(NUM_LONG_TERM_BYTES)
.setNumRows(BigInteger.valueOf(NUM_ROWS))
.setSelfLink(SELF_LINK)
.setLabels(Collections.singletonMap("a", "b"))
Expand Down Expand Up @@ -155,6 +158,10 @@ public void testBuilder() {
assertEquals(LAST_MODIFIED_TIME, TABLE_INFO.getLastModifiedTime());
assertEquals(TABLE_DEFINITION, TABLE_INFO.getDefinition());
assertEquals(SELF_LINK, TABLE_INFO.getSelfLink());
assertEquals(NUM_BYTES, TABLE_INFO.getNumBytes());
assertEquals(NUM_LONG_TERM_BYTES, TABLE_INFO.getNumLongTermBytes());
assertEquals(BigInteger.valueOf(NUM_ROWS), TABLE_INFO.getNumRows());

assertEquals(TABLE_ID, VIEW_INFO.getTableId());
assertEquals(VIEW_DEFINITION, VIEW_INFO.getDefinition());
assertEquals(CREATION_TIME, VIEW_INFO.getCreationTime());
Expand All @@ -166,6 +173,7 @@ public void testBuilder() {
assertEquals(LAST_MODIFIED_TIME, VIEW_INFO.getLastModifiedTime());
assertEquals(VIEW_DEFINITION, VIEW_INFO.getDefinition());
assertEquals(SELF_LINK, VIEW_INFO.getSelfLink());

assertEquals(TABLE_ID, EXTERNAL_TABLE_INFO.getTableId());
assertEquals(CREATION_TIME, EXTERNAL_TABLE_INFO.getCreationTime());
assertEquals(DESCRIPTION, EXTERNAL_TABLE_INFO.getDescription());
Expand Down Expand Up @@ -248,6 +256,7 @@ private void compareTableInfo(TableInfo expected, TableInfo value) {
assertEquals(expected.getGeneratedId(), value.getGeneratedId());
assertEquals(expected.getLastModifiedTime(), value.getLastModifiedTime());
assertEquals(expected.getNumBytes(), value.getNumBytes());
assertEquals(expected.getNumLongTermBytes(), value.getNumLongTermBytes());
assertEquals(expected.getNumRows(), value.getNumRows());
assertEquals(expected.getSelfLink(), value.getSelfLink());
assertEquals(expected.getLabels(), value.getLabels());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ public void testCreateAndGetTable() {
assertNotNull(remoteTable.getCreationTime());
assertNotNull(remoteTable.getLastModifiedTime());
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes());
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumLongTermBytes());
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());
assertEquals(
partitioning, remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning());
Expand Down Expand Up @@ -468,6 +469,7 @@ public void testCreateAndGetTableWithSelectedField() {
assertNull(remoteTable.getDefinition().getSchema());
assertNull(remoteTable.getLastModifiedTime());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumLongTermBytes());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning());
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getClustering());
Expand Down Expand Up @@ -707,6 +709,7 @@ public void testUpdateTableWithSelectedFields() {
assertNull(updatedTable.getDefinition().getSchema());
assertNull(updatedTable.getLastModifiedTime());
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumBytes());
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumLongTermBytes());
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumRows());
assertTrue(createdTable.delete());
}
Expand Down

0 comments on commit 83ea49e

Please sign in to comment.