Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery : Fix numBytes, numRows in TableInfo/Table #4271

Merged
merged 4 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -329,6 +355,16 @@ public <T extends TableDefinition> 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.
*
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down