Skip to content

Commit 83ea49e

Browse files
shollymansduskis
authored andcommitted
BigQuery: add long term storage bytes to standard table definition. (googleapis#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
1 parent cc04990 commit 83ea49e

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ public abstract static class Builder
130130

131131
public abstract Builder setNumBytes(Long numBytes);
132132

133+
public abstract Builder setNumLongTermBytes(Long numLongTermBytes);
134+
133135
public abstract Builder setNumRows(Long numRows);
134136

135137
public abstract Builder setLocation(String location);
@@ -161,6 +163,15 @@ public abstract static class Builder
161163
@Nullable
162164
public abstract Long getNumBytes();
163165

166+
/**
167+
* Returns the number of bytes considered "long-term storage" for reduced billing purposes.
168+
*
169+
* @see <a href="https://cloud.google.com/bigquery/pricing#long-term-storage">Long Term Storage
170+
* Pricing</a>
171+
*/
172+
@Nullable
173+
public abstract Long getNumLongTermBytes();
174+
164175
/** Returns the number of rows in this table, excluding any data in the streaming buffer. */
165176
@Nullable
166177
public abstract Long getNumRows();
@@ -221,6 +232,7 @@ Table toPb() {
221232
tablePb.setNumRows(BigInteger.valueOf(getNumRows()));
222233
}
223234
tablePb.setNumBytes(getNumBytes());
235+
tablePb.setNumLongTermBytes(getNumLongTermBytes());
224236
tablePb.setLocation(getLocation());
225237
if (getStreamingBuffer() != null) {
226238
tablePb.setStreamingBuffer(getStreamingBuffer().toPb());
@@ -249,6 +261,9 @@ static StandardTableDefinition fromPb(Table tablePb) {
249261
if (tablePb.getClustering() != null) {
250262
builder.setClustering(Clustering.fromPb(tablePb.getClustering()));
251263
}
264+
if (tablePb.getNumLongTermBytes() != null) {
265+
builder.setNumLongTermBytes(tablePb.getNumLongTermBytes());
266+
}
252267
return builder.setNumBytes(tablePb.getNumBytes()).setLocation(tablePb.getLocation()).build();
253268
}
254269
}

google-cloud-clients/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
@@ -108,6 +108,12 @@ Builder setNumBytes(Long numBytes) {
108108
return this;
109109
}
110110

111+
@Override
112+
Builder setNumLongTermBytes(Long numLongTermBytes) {
113+
infoBuilder.setNumLongTermBytes(numLongTermBytes);
114+
return this;
115+
}
116+
111117
@Override
112118
Builder setNumRows(BigInteger numRows) {
113119
infoBuilder.setNumRows(numRows);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public Table apply(TableInfo tableInfo) {
6666
private final Long expirationTime;
6767
private final Long lastModifiedTime;
6868
private final Long numBytes;
69+
private final Long numLongTermBytes;
6970
private final BigInteger numRows;
7071
private final TableDefinition definition;
7172
private final EncryptionConfiguration encryptionConfiguration;
@@ -96,6 +97,8 @@ public abstract static class Builder {
9697

9798
abstract Builder setNumBytes(Long numBytes);
9899

100+
abstract Builder setNumLongTermBytes(Long numLongTermBytes);
101+
99102
abstract Builder setNumRows(BigInteger numRows);
100103

101104
abstract Builder setSelfLink(String selfLink);
@@ -141,6 +144,7 @@ static class BuilderImpl extends Builder {
141144
private Long expirationTime;
142145
private Long lastModifiedTime;
143146
private Long numBytes;
147+
private Long numLongTermBytes;
144148
private BigInteger numRows;
145149
private TableDefinition definition;
146150
private EncryptionConfiguration encryptionConfiguration;
@@ -159,6 +163,7 @@ static class BuilderImpl extends Builder {
159163
this.expirationTime = tableInfo.expirationTime;
160164
this.lastModifiedTime = tableInfo.lastModifiedTime;
161165
this.numBytes = tableInfo.numBytes;
166+
this.numLongTermBytes = tableInfo.numLongTermBytes;
162167
this.numRows = tableInfo.numRows;
163168
this.definition = tableInfo.definition;
164169
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
@@ -178,6 +183,7 @@ static class BuilderImpl extends Builder {
178183
this.generatedId = tablePb.getId();
179184
this.selfLink = tablePb.getSelfLink();
180185
this.numBytes = tablePb.getNumBytes();
186+
this.numLongTermBytes = tablePb.getNumLongTermBytes();
181187
this.numRows = tablePb.getNumRows();
182188
this.definition = TableDefinition.fromPb(tablePb);
183189
if (tablePb.getEncryptionConfiguration() != null) {
@@ -235,6 +241,12 @@ Builder setNumBytes(Long numBytes) {
235241
return this;
236242
}
237243

244+
@Override
245+
Builder setNumLongTermBytes(Long numLongTermBytes) {
246+
this.numLongTermBytes = numLongTermBytes;
247+
return this;
248+
}
249+
238250
@Override
239251
Builder setNumRows(BigInteger numRows) {
240252
this.numRows = numRows;
@@ -288,6 +300,7 @@ public TableInfo build() {
288300
this.expirationTime = builder.expirationTime;
289301
this.lastModifiedTime = builder.lastModifiedTime;
290302
this.numBytes = builder.numBytes;
303+
this.numLongTermBytes = builder.numLongTermBytes;
291304
this.numRows = builder.numRows;
292305
this.definition = builder.definition;
293306
this.encryptionConfiguration = builder.encryptionConfiguration;
@@ -360,6 +373,16 @@ public Long getNumBytes() {
360373
return numBytes;
361374
}
362375

376+
/**
377+
* Returns the number of bytes considered "long-term storage" for reduced billing purposes.
378+
*
379+
* @see <a href="https://cloud.google.com/bigquery/pricing#long-term-storage">Long Term Storage
380+
* Pricing</a>
381+
*/
382+
public Long getNumLongTermBytes() {
383+
return numLongTermBytes;
384+
}
385+
363386
/** Returns the number of rows of data in this table */
364387
public BigInteger getNumRows() {
365388
return numRows;
@@ -394,6 +417,7 @@ public String toString() {
394417
.add("creationTime", creationTime)
395418
.add("lastModifiedTime", lastModifiedTime)
396419
.add("numBytes", numBytes)
420+
.add("numLongTermBytes", numLongTermBytes)
397421
.add("numRows", numRows)
398422
.add("definition", definition)
399423
.add("encryptionConfiguration", encryptionConfiguration)

google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class StandardTableDefinitionTest {
4444
.build();
4545
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
4646
private static final Long NUM_BYTES = 42L;
47+
private static final Long NUM_LONG_TERM_BYTES = 18L;
4748
private static final Long NUM_ROWS = 43L;
4849
private static final String LOCATION = "US";
4950
private static final StreamingBuffer STREAMING_BUFFER = new StreamingBuffer(1L, 2L, 3L);
@@ -56,6 +57,7 @@ public class StandardTableDefinitionTest {
5657
.setLocation(LOCATION)
5758
.setNumBytes(NUM_BYTES)
5859
.setNumRows(NUM_ROWS)
60+
.setNumLongTermBytes(NUM_LONG_TERM_BYTES)
5961
.setStreamingBuffer(STREAMING_BUFFER)
6062
.setSchema(TABLE_SCHEMA)
6163
.setTimePartitioning(TIME_PARTITIONING)
@@ -84,6 +86,7 @@ public void testBuilder() {
8486
assertEquals(TABLE_SCHEMA, TABLE_DEFINITION.getSchema());
8587
assertEquals(LOCATION, TABLE_DEFINITION.getLocation());
8688
assertEquals(NUM_BYTES, TABLE_DEFINITION.getNumBytes());
89+
assertEquals(NUM_LONG_TERM_BYTES, TABLE_DEFINITION.getNumLongTermBytes());
8790
assertEquals(NUM_ROWS, TABLE_DEFINITION.getNumRows());
8891
assertEquals(STREAMING_BUFFER, TABLE_DEFINITION.getStreamingBuffer());
8992
assertEquals(TIME_PARTITIONING, TABLE_DEFINITION.getTimePartitioning());
@@ -97,6 +100,7 @@ public void testOf() {
97100
assertEquals(TABLE_SCHEMA, TABLE_DEFINITION.getSchema());
98101
assertNull(definition.getLocation());
99102
assertNull(definition.getNumBytes());
103+
assertNull(definition.getNumLongTermBytes());
100104
assertNull(definition.getNumRows());
101105
assertNull(definition.getStreamingBuffer());
102106
assertNull(definition.getTimePartitioning());
@@ -131,6 +135,7 @@ private void compareStandardTableDefinition(
131135
assertEquals(expected.getSchema(), value.getSchema());
132136
assertEquals(expected.getType(), value.getType());
133137
assertEquals(expected.getNumBytes(), value.getNumBytes());
138+
assertEquals(expected.getNumLongTermBytes(), value.getNumLongTermBytes());
134139
assertEquals(expected.getNumRows(), value.getNumRows());
135140
assertEquals(expected.getLocation(), value.getLocation());
136141
assertEquals(expected.getStreamingBuffer(), value.getStreamingBuffer());

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class TableInfoTest {
5454
.build();
5555
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
5656
private static final Long NUM_BYTES = 42L;
57+
private static final Long NUM_LONG_TERM_BYTES = 21L;
5758
private static final Long NUM_ROWS = 43L;
5859
private static final String LOCATION = "US";
5960
private static final StandardTableDefinition.StreamingBuffer STREAMING_BUFFER =
@@ -62,6 +63,7 @@ public class TableInfoTest {
6263
StandardTableDefinition.newBuilder()
6364
.setLocation(LOCATION)
6465
.setNumBytes(NUM_BYTES)
66+
.setNumLongTermBytes(NUM_LONG_TERM_BYTES)
6567
.setNumRows(NUM_ROWS)
6668
.setStreamingBuffer(STREAMING_BUFFER)
6769
.setSchema(TABLE_SCHEMA)
@@ -95,6 +97,7 @@ public class TableInfoTest {
9597
.setGeneratedId(GENERATED_ID)
9698
.setLastModifiedTime(LAST_MODIFIED_TIME)
9799
.setNumBytes(NUM_BYTES)
100+
.setNumLongTermBytes(NUM_LONG_TERM_BYTES)
98101
.setNumRows(BigInteger.valueOf(NUM_ROWS))
99102
.setSelfLink(SELF_LINK)
100103
.setLabels(Collections.singletonMap("a", "b"))
@@ -155,6 +158,10 @@ public void testBuilder() {
155158
assertEquals(LAST_MODIFIED_TIME, TABLE_INFO.getLastModifiedTime());
156159
assertEquals(TABLE_DEFINITION, TABLE_INFO.getDefinition());
157160
assertEquals(SELF_LINK, TABLE_INFO.getSelfLink());
161+
assertEquals(NUM_BYTES, TABLE_INFO.getNumBytes());
162+
assertEquals(NUM_LONG_TERM_BYTES, TABLE_INFO.getNumLongTermBytes());
163+
assertEquals(BigInteger.valueOf(NUM_ROWS), TABLE_INFO.getNumRows());
164+
158165
assertEquals(TABLE_ID, VIEW_INFO.getTableId());
159166
assertEquals(VIEW_DEFINITION, VIEW_INFO.getDefinition());
160167
assertEquals(CREATION_TIME, VIEW_INFO.getCreationTime());
@@ -166,6 +173,7 @@ public void testBuilder() {
166173
assertEquals(LAST_MODIFIED_TIME, VIEW_INFO.getLastModifiedTime());
167174
assertEquals(VIEW_DEFINITION, VIEW_INFO.getDefinition());
168175
assertEquals(SELF_LINK, VIEW_INFO.getSelfLink());
176+
169177
assertEquals(TABLE_ID, EXTERNAL_TABLE_INFO.getTableId());
170178
assertEquals(CREATION_TIME, EXTERNAL_TABLE_INFO.getCreationTime());
171179
assertEquals(DESCRIPTION, EXTERNAL_TABLE_INFO.getDescription());
@@ -248,6 +256,7 @@ private void compareTableInfo(TableInfo expected, TableInfo value) {
248256
assertEquals(expected.getGeneratedId(), value.getGeneratedId());
249257
assertEquals(expected.getLastModifiedTime(), value.getLastModifiedTime());
250258
assertEquals(expected.getNumBytes(), value.getNumBytes());
259+
assertEquals(expected.getNumLongTermBytes(), value.getNumLongTermBytes());
251260
assertEquals(expected.getNumRows(), value.getNumRows());
252261
assertEquals(expected.getSelfLink(), value.getSelfLink());
253262
assertEquals(expected.getLabels(), value.getLabels());

google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ public void testCreateAndGetTable() {
436436
assertNotNull(remoteTable.getCreationTime());
437437
assertNotNull(remoteTable.getLastModifiedTime());
438438
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes());
439+
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumLongTermBytes());
439440
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());
440441
assertEquals(
441442
partitioning, remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning());
@@ -468,6 +469,7 @@ public void testCreateAndGetTableWithSelectedField() {
468469
assertNull(remoteTable.getDefinition().getSchema());
469470
assertNull(remoteTable.getLastModifiedTime());
470471
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes());
472+
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumLongTermBytes());
471473
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());
472474
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning());
473475
assertNull(remoteTable.<StandardTableDefinition>getDefinition().getClustering());
@@ -707,6 +709,7 @@ public void testUpdateTableWithSelectedFields() {
707709
assertNull(updatedTable.getDefinition().getSchema());
708710
assertNull(updatedTable.getLastModifiedTime());
709711
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumBytes());
712+
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumLongTermBytes());
710713
assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumRows());
711714
assertTrue(createdTable.delete());
712715
}

0 commit comments

Comments
 (0)