Skip to content

Commit

Permalink
Fix NPE in BQ's StandardTableDefinition (#4247)
Browse files Browse the repository at this point in the history
  • Loading branch information
nktaushanov authored and sduskis committed Dec 28, 2018
1 parent 9bf5b35 commit 31971fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public static class StreamingBuffer implements Serializable {
}

/** Returns a lower-bound estimate of the number of rows currently in the streaming buffer. */
public long getEstimatedRows() {
public Long getEstimatedRows() {
return estimatedRows;
}

/** Returns a lower-bound estimate of the number of bytes currently in the streaming buffer. */
public long getEstimatedBytes() {
public Long getEstimatedBytes() {
return estimatedBytes;
}

Expand Down Expand Up @@ -95,10 +95,17 @@ public boolean equals(Object obj) {
}

Streamingbuffer toPb() {
return new Streamingbuffer()
.setEstimatedBytes(BigInteger.valueOf(estimatedBytes))
.setEstimatedRows(BigInteger.valueOf(estimatedRows))
.setOldestEntryTime(BigInteger.valueOf(oldestEntryTime));
Streamingbuffer buffer = new Streamingbuffer();
if (estimatedBytes != null) {
buffer.setEstimatedBytes(BigInteger.valueOf(estimatedBytes));
}
if (estimatedRows != null) {
buffer.setEstimatedRows(BigInteger.valueOf(estimatedRows));
}
if (oldestEntryTime != null) {
buffer.setOldestEntryTime(BigInteger.valueOf(oldestEntryTime));
}
return buffer;
}

static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public void testFromPbWithNullEstimatedRowsAndBytes() {
TABLE_DEFINITION.toPb().setStreamingBuffer(new Streamingbuffer()));
}

@Test
public void testStreamingBufferWithNullFieldsToPb() {
new StreamingBuffer(null, null, null).toPb();
}

private void compareStandardTableDefinition(
StandardTableDefinition expected, StandardTableDefinition value) {
assertEquals(expected, value);
Expand Down

0 comments on commit 31971fb

Please sign in to comment.