From b4bea96e44752193e6ee7e096d8dfb9ad66d5c62 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Fri, 28 Dec 2018 18:00:28 +0530 Subject: [PATCH 1/4] Fix NumBytes and NumRows --- .../main/java/com/google/cloud/bigquery/TableInfo.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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..3d6ecc1005a9 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 @@ -329,6 +329,16 @@ public T getDefinition() { return (T) definition; } + /** Returns the size of this table in bytes */ + public Long getNumBytes() { + return getDefinition().toPb().getNumBytes(); + } + + /** Returns the number of rows of data in this table */ + public BigInteger getNumRows() { + return getDefinition().toPb().getNumRows(); + } + /** * Return a map for labels applied to the table. * From e172bee4a1404ef70108f882877133c93ec4ca52 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Mon, 31 Dec 2018 20:12:08 +0530 Subject: [PATCH 2/4] update NumBytes and NumRows --- .../java/com/google/cloud/bigquery/Table.java | 13 +++++++ .../com/google/cloud/bigquery/TableInfo.java | 34 +++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) 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..ee13903010f0 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 @@ -25,6 +25,7 @@ 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; @@ -120,6 +121,18 @@ public Builder setDefinition(TableDefinition definition) { return this; } + @Override + Builder setNumBytes(Long numBytes) { + infoBuilder.setNumBytes(numBytes); + return this; + } + + @Override + Builder setNumRows(BigInteger numRows) { + infoBuilder.setNumRows(numRows); + return this; + } + @Override public TableInfo.Builder setEncryptionConfiguration(EncryptionConfiguration configuration) { infoBuilder.setEncryptionConfiguration(configuration); 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 3d6ecc1005a9..c3968f8df0af 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; @@ -331,12 +357,12 @@ public T getDefinition() { /** Returns the size of this table in bytes */ public Long getNumBytes() { - return getDefinition().toPb().getNumBytes(); + return numBytes; } /** Returns the number of rows of data in this table */ public BigInteger getNumRows() { - return getDefinition().toPb().getNumRows(); + return numRows; } /** @@ -367,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) @@ -419,6 +447,8 @@ Table toPb() { if (lastModifiedTime != null) { tablePb.setLastModifiedTime(BigInteger.valueOf(lastModifiedTime)); } + tablePb.setNumBytes(numBytes); + tablePb.setNumRows(numRows); tablePb.setCreationTime(creationTime); tablePb.setDescription(description); tablePb.setEtag(etag); From 7a4a35080af2b08e34d47219474f4ac229228a54 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Mon, 31 Dec 2018 20:19:59 +0530 Subject: [PATCH 3/4] remove setter --- .../java/com/google/cloud/bigquery/Table.java | 14 -------------- .../com/google/cloud/bigquery/TableInfo.java | 16 ---------------- 2 files changed, 30 deletions(-) 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 ee13903010f0..ec7d71247253 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,11 +21,9 @@ 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; @@ -121,18 +119,6 @@ public Builder setDefinition(TableDefinition definition) { return this; } - @Override - Builder setNumBytes(Long numBytes) { - infoBuilder.setNumBytes(numBytes); - return this; - } - - @Override - Builder setNumRows(BigInteger numRows) { - infoBuilder.setNumRows(numRows); - return this; - } - @Override public TableInfo.Builder setEncryptionConfiguration(EncryptionConfiguration configuration) { infoBuilder.setEncryptionConfiguration(configuration); 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 c3968f8df0af..ef938437d2a2 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 @@ -94,10 +94,6 @@ 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. */ @@ -229,18 +225,6 @@ 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; From ce54e37a0e963eb03a00fe25cce8fd1b3cee8926 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Tue, 1 Jan 2019 20:10:52 +0530 Subject: [PATCH 4/4] update methods and resolved test case --- .../java/com/google/cloud/bigquery/Table.java | 13 +++++++++++++ .../com/google/cloud/bigquery/TableInfo.java | 18 ++++++++++++++++-- .../google/cloud/bigquery/TableInfoTest.java | 5 +++++ 3 files changed, 34 insertions(+), 2 deletions(-) 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 ec7d71247253..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 @@ -24,6 +24,7 @@ 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; @@ -101,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 ef938437d2a2..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 @@ -94,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. */ @@ -225,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; @@ -431,8 +447,6 @@ Table toPb() { if (lastModifiedTime != null) { tablePb.setLastModifiedTime(BigInteger.valueOf(lastModifiedTime)); } - tablePb.setNumBytes(numBytes); - tablePb.setNumRows(numRows); tablePb.setCreationTime(creationTime); tablePb.setDescription(description); tablePb.setEtag(etag); 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());