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 7fee00952bae..d38957bd6186 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 @@ -21,10 +21,10 @@ import com.google.cloud.bigquery.BigQuery.JobOption; import com.google.cloud.bigquery.BigQuery.TableDataListOption; import com.google.cloud.bigquery.BigQuery.TableOption; -import com.google.cloud.bigquery.TableInfo.Builder; import com.google.common.collect.ImmutableList; import java.io.IOException; import java.io.ObjectInputStream; +import java.math.BigInteger; import java.util.List; import java.util.Map; import java.util.Objects; @@ -102,6 +102,18 @@ Builder setLastModifiedTime(Long lastModifiedTime) { return this; } + @Override + Builder setNumBytes(Long numBytes) { + infoBuilder.setNumBytes(numBytes); + return this; + } + + @Override + Builder setNumRows(BigInteger numRows) { + infoBuilder.setNumRows(numRows); + return this; + } + @Override Builder setSelfLink(String selfLink) { infoBuilder.setSelfLink(selfLink); 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 37831cf943e4..8fad66d20a7e 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 @@ -65,6 +65,8 @@ public Table apply(TableInfo tableInfo) { private final Long creationTime; private final Long expirationTime; private final Long lastModifiedTime; + private final Long numBytes; + private final BigInteger numRows; private final TableDefinition definition; private final EncryptionConfiguration encryptionConfiguration; private final Labels labels; @@ -92,6 +94,10 @@ public abstract static class Builder { abstract Builder setLastModifiedTime(Long lastModifiedTime); + abstract Builder setNumBytes(Long numBytes); + + abstract Builder setNumRows(BigInteger numRows); + abstract Builder setSelfLink(String selfLink); /** Sets the table identity. */ @@ -134,6 +140,8 @@ static class BuilderImpl extends Builder { private Long creationTime; private Long expirationTime; private Long lastModifiedTime; + private Long numBytes; + private BigInteger numRows; private TableDefinition definition; private EncryptionConfiguration encryptionConfiguration; private Labels labels = Labels.ZERO; @@ -150,6 +158,8 @@ static class BuilderImpl extends Builder { this.creationTime = tableInfo.creationTime; this.expirationTime = tableInfo.expirationTime; this.lastModifiedTime = tableInfo.lastModifiedTime; + this.numBytes = tableInfo.numBytes; + this.numRows = tableInfo.numRows; this.definition = tableInfo.definition; this.encryptionConfiguration = tableInfo.encryptionConfiguration; this.labels = tableInfo.labels; @@ -167,6 +177,8 @@ static class BuilderImpl extends Builder { this.etag = tablePb.getEtag(); this.generatedId = tablePb.getId(); this.selfLink = tablePb.getSelfLink(); + this.numBytes = tablePb.getNumBytes(); + this.numRows = tablePb.getNumRows(); this.definition = TableDefinition.fromPb(tablePb); if (tablePb.getEncryptionConfiguration() != null) { this.encryptionConfiguration = @@ -217,6 +229,18 @@ Builder setLastModifiedTime(Long lastModifiedTime) { return this; } + @Override + Builder setNumBytes(Long numBytes) { + this.numBytes = numBytes; + return this; + } + + @Override + Builder setNumRows(BigInteger numRows) { + this.numRows = numRows; + return this; + } + @Override Builder setSelfLink(String selfLink) { this.selfLink = selfLink; @@ -263,6 +287,8 @@ public TableInfo build() { this.creationTime = builder.creationTime; this.expirationTime = builder.expirationTime; this.lastModifiedTime = builder.lastModifiedTime; + this.numBytes = builder.numBytes; + this.numRows = builder.numRows; this.definition = builder.definition; this.encryptionConfiguration = builder.encryptionConfiguration; labels = builder.labels; @@ -329,6 +355,16 @@ public T getDefinition() { return (T) definition; } + /** Returns the size of this table in bytes */ + public Long getNumBytes() { + return numBytes; + } + + /** Returns the number of rows of data in this table */ + public BigInteger getNumRows() { + return numRows; + } + /** * Return a map for labels applied to the table. * @@ -357,6 +393,8 @@ public String toString() { .add("expirationTime", expirationTime) .add("creationTime", creationTime) .add("lastModifiedTime", lastModifiedTime) + .add("numBytes", numBytes) + .add("numRows", numRows) .add("definition", definition) .add("encryptionConfiguration", encryptionConfiguration) .add("labels", labels) 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 98434713478d..6e35ce6cb620 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 @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNull; import com.google.common.collect.ImmutableList; +import java.math.BigInteger; import java.util.Collections; import java.util.List; import org.junit.Test; @@ -93,6 +94,8 @@ public class TableInfoTest { .setFriendlyName(FRIENDLY_NAME) .setGeneratedId(GENERATED_ID) .setLastModifiedTime(LAST_MODIFIED_TIME) + .setNumBytes(NUM_BYTES) + .setNumRows(BigInteger.valueOf(NUM_ROWS)) .setSelfLink(SELF_LINK) .setLabels(Collections.singletonMap("a", "b")) .build(); @@ -244,6 +247,8 @@ private void compareTableInfo(TableInfo expected, TableInfo value) { assertEquals(expected.getFriendlyName(), value.getFriendlyName()); assertEquals(expected.getGeneratedId(), value.getGeneratedId()); assertEquals(expected.getLastModifiedTime(), value.getLastModifiedTime()); + assertEquals(expected.getNumBytes(), value.getNumBytes()); + assertEquals(expected.getNumRows(), value.getNumRows()); assertEquals(expected.getSelfLink(), value.getSelfLink()); assertEquals(expected.getLabels(), value.getLabels()); assertEquals(expected.hashCode(), value.hashCode());