Skip to content

Commit 73e93c0

Browse files
Praful Makanichingor13
authored andcommitted
BigQuery : Fix numBytes, numRows in TableInfo/Table (#4271)
* Fix NumBytes and NumRows * update NumBytes and NumRows * remove setter * update methods and resolved test case
1 parent 2b9f530 commit 73e93c0

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import com.google.cloud.bigquery.BigQuery.JobOption;
2222
import com.google.cloud.bigquery.BigQuery.TableDataListOption;
2323
import com.google.cloud.bigquery.BigQuery.TableOption;
24-
import com.google.cloud.bigquery.TableInfo.Builder;
2524
import com.google.common.collect.ImmutableList;
2625
import java.io.IOException;
2726
import java.io.ObjectInputStream;
27+
import java.math.BigInteger;
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.Objects;
@@ -102,6 +102,18 @@ Builder setLastModifiedTime(Long lastModifiedTime) {
102102
return this;
103103
}
104104

105+
@Override
106+
Builder setNumBytes(Long numBytes) {
107+
infoBuilder.setNumBytes(numBytes);
108+
return this;
109+
}
110+
111+
@Override
112+
Builder setNumRows(BigInteger numRows) {
113+
infoBuilder.setNumRows(numRows);
114+
return this;
115+
}
116+
105117
@Override
106118
Builder setSelfLink(String selfLink) {
107119
infoBuilder.setSelfLink(selfLink);

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public Table apply(TableInfo tableInfo) {
6565
private final Long creationTime;
6666
private final Long expirationTime;
6767
private final Long lastModifiedTime;
68+
private final Long numBytes;
69+
private final BigInteger numRows;
6870
private final TableDefinition definition;
6971
private final EncryptionConfiguration encryptionConfiguration;
7072
private final Labels labels;
@@ -92,6 +94,10 @@ public abstract static class Builder {
9294

9395
abstract Builder setLastModifiedTime(Long lastModifiedTime);
9496

97+
abstract Builder setNumBytes(Long numBytes);
98+
99+
abstract Builder setNumRows(BigInteger numRows);
100+
95101
abstract Builder setSelfLink(String selfLink);
96102

97103
/** Sets the table identity. */
@@ -134,6 +140,8 @@ static class BuilderImpl extends Builder {
134140
private Long creationTime;
135141
private Long expirationTime;
136142
private Long lastModifiedTime;
143+
private Long numBytes;
144+
private BigInteger numRows;
137145
private TableDefinition definition;
138146
private EncryptionConfiguration encryptionConfiguration;
139147
private Labels labels = Labels.ZERO;
@@ -150,6 +158,8 @@ static class BuilderImpl extends Builder {
150158
this.creationTime = tableInfo.creationTime;
151159
this.expirationTime = tableInfo.expirationTime;
152160
this.lastModifiedTime = tableInfo.lastModifiedTime;
161+
this.numBytes = tableInfo.numBytes;
162+
this.numRows = tableInfo.numRows;
153163
this.definition = tableInfo.definition;
154164
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
155165
this.labels = tableInfo.labels;
@@ -167,6 +177,8 @@ static class BuilderImpl extends Builder {
167177
this.etag = tablePb.getEtag();
168178
this.generatedId = tablePb.getId();
169179
this.selfLink = tablePb.getSelfLink();
180+
this.numBytes = tablePb.getNumBytes();
181+
this.numRows = tablePb.getNumRows();
170182
this.definition = TableDefinition.fromPb(tablePb);
171183
if (tablePb.getEncryptionConfiguration() != null) {
172184
this.encryptionConfiguration =
@@ -217,6 +229,18 @@ Builder setLastModifiedTime(Long lastModifiedTime) {
217229
return this;
218230
}
219231

232+
@Override
233+
Builder setNumBytes(Long numBytes) {
234+
this.numBytes = numBytes;
235+
return this;
236+
}
237+
238+
@Override
239+
Builder setNumRows(BigInteger numRows) {
240+
this.numRows = numRows;
241+
return this;
242+
}
243+
220244
@Override
221245
Builder setSelfLink(String selfLink) {
222246
this.selfLink = selfLink;
@@ -263,6 +287,8 @@ public TableInfo build() {
263287
this.creationTime = builder.creationTime;
264288
this.expirationTime = builder.expirationTime;
265289
this.lastModifiedTime = builder.lastModifiedTime;
290+
this.numBytes = builder.numBytes;
291+
this.numRows = builder.numRows;
266292
this.definition = builder.definition;
267293
this.encryptionConfiguration = builder.encryptionConfiguration;
268294
labels = builder.labels;
@@ -329,6 +355,16 @@ public <T extends TableDefinition> T getDefinition() {
329355
return (T) definition;
330356
}
331357

358+
/** Returns the size of this table in bytes */
359+
public Long getNumBytes() {
360+
return numBytes;
361+
}
362+
363+
/** Returns the number of rows of data in this table */
364+
public BigInteger getNumRows() {
365+
return numRows;
366+
}
367+
332368
/**
333369
* Return a map for labels applied to the table.
334370
*
@@ -357,6 +393,8 @@ public String toString() {
357393
.add("expirationTime", expirationTime)
358394
.add("creationTime", creationTime)
359395
.add("lastModifiedTime", lastModifiedTime)
396+
.add("numBytes", numBytes)
397+
.add("numRows", numRows)
360398
.add("definition", definition)
361399
.add("encryptionConfiguration", encryptionConfiguration)
362400
.add("labels", labels)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.Assert.assertNull;
2121

2222
import com.google.common.collect.ImmutableList;
23+
import java.math.BigInteger;
2324
import java.util.Collections;
2425
import java.util.List;
2526
import org.junit.Test;
@@ -93,6 +94,8 @@ public class TableInfoTest {
9394
.setFriendlyName(FRIENDLY_NAME)
9495
.setGeneratedId(GENERATED_ID)
9596
.setLastModifiedTime(LAST_MODIFIED_TIME)
97+
.setNumBytes(NUM_BYTES)
98+
.setNumRows(BigInteger.valueOf(NUM_ROWS))
9699
.setSelfLink(SELF_LINK)
97100
.setLabels(Collections.singletonMap("a", "b"))
98101
.build();
@@ -244,6 +247,8 @@ private void compareTableInfo(TableInfo expected, TableInfo value) {
244247
assertEquals(expected.getFriendlyName(), value.getFriendlyName());
245248
assertEquals(expected.getGeneratedId(), value.getGeneratedId());
246249
assertEquals(expected.getLastModifiedTime(), value.getLastModifiedTime());
250+
assertEquals(expected.getNumBytes(), value.getNumBytes());
251+
assertEquals(expected.getNumRows(), value.getNumRows());
247252
assertEquals(expected.getSelfLink(), value.getSelfLink());
248253
assertEquals(expected.getLabels(), value.getLabels());
249254
assertEquals(expected.hashCode(), value.hashCode());

0 commit comments

Comments
 (0)