From 83ea49e5d4959ee9616530e32afdcf114345bf15 Mon Sep 17 00:00:00 2001 From: shollyman Date: Thu, 7 Mar 2019 10:49:23 -0800 Subject: [PATCH] BigQuery: add long term storage bytes to standard table definition. (#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 --- .../bigquery/StandardTableDefinition.java | 15 ++++++++++++ .../java/com/google/cloud/bigquery/Table.java | 6 +++++ .../com/google/cloud/bigquery/TableInfo.java | 24 +++++++++++++++++++ .../bigquery/StandardTableDefinitionTest.java | 5 ++++ .../google/cloud/bigquery/TableInfoTest.java | 9 +++++++ .../cloud/bigquery/it/ITBigQueryTest.java | 3 +++ 6 files changed, 62 insertions(+) diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java index f12e6b608a91..9b2ae343875f 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java @@ -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); @@ -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 Long Term Storage + * Pricing + */ + @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(); @@ -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()); @@ -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(); } } diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java index d38957bd6186..ab341c62c4ff 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java @@ -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); diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java index 8fad66d20a7e..e64e85ebae22 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableInfo.java @@ -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; @@ -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); @@ -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; @@ -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; @@ -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) { @@ -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; @@ -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; @@ -360,6 +373,16 @@ public Long getNumBytes() { return numBytes; } + /** + * Returns the number of bytes considered "long-term storage" for reduced billing purposes. + * + * @see Long Term Storage + * Pricing + */ + public Long getNumLongTermBytes() { + return numLongTermBytes; + } + /** Returns the number of rows of data in this table */ public BigInteger getNumRows() { return numRows; @@ -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) diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java index d70d33fb119b..7bfbf62754b8 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java @@ -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); @@ -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) @@ -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()); @@ -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()); @@ -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()); diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableInfoTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableInfoTest.java index 6e35ce6cb620..324f562cdfdf 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableInfoTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/TableInfoTest.java @@ -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 = @@ -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) @@ -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")) @@ -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()); @@ -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()); @@ -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()); diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 2fa28612ffd4..c7fe1ee35c75 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -436,6 +436,7 @@ public void testCreateAndGetTable() { assertNotNull(remoteTable.getCreationTime()); assertNotNull(remoteTable.getLastModifiedTime()); assertNotNull(remoteTable.getDefinition().getNumBytes()); + assertNotNull(remoteTable.getDefinition().getNumLongTermBytes()); assertNotNull(remoteTable.getDefinition().getNumRows()); assertEquals( partitioning, remoteTable.getDefinition().getTimePartitioning()); @@ -468,6 +469,7 @@ public void testCreateAndGetTableWithSelectedField() { assertNull(remoteTable.getDefinition().getSchema()); assertNull(remoteTable.getLastModifiedTime()); assertNull(remoteTable.getDefinition().getNumBytes()); + assertNull(remoteTable.getDefinition().getNumLongTermBytes()); assertNull(remoteTable.getDefinition().getNumRows()); assertNull(remoteTable.getDefinition().getTimePartitioning()); assertNull(remoteTable.getDefinition().getClustering()); @@ -707,6 +709,7 @@ public void testUpdateTableWithSelectedFields() { assertNull(updatedTable.getDefinition().getSchema()); assertNull(updatedTable.getLastModifiedTime()); assertNull(updatedTable.getDefinition().getNumBytes()); + assertNull(updatedTable.getDefinition().getNumLongTermBytes()); assertNull(updatedTable.getDefinition().getNumRows()); assertTrue(createdTable.delete()); }