8000 Fix BigQuery NullPointerException when estimatedFields is empty by ajaaym · Pull Request #3984 · googleapis/google-cloud-java · GitHub
[go: up one dir, main page]

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public abstract class StandardTableDefinition extends TableDefinition {
public static class StreamingBuffer implements Serializable {

private static final long serialVersionUID = 822027055549277843L;
private final long estimatedRows;
private final long estimatedBytes;
private final Long estimatedRows;
private final Long estimatedBytes;
private final Long oldestEntryTime;

StreamingBuffer(long estimatedRows, long estimatedBytes, Long oldestEntryTime) {
StreamingBuffer(Long estimatedRows, Long estimatedBytes, Long oldestEntryTime) {
this.estimatedRows = estimatedRows;
this.estimatedBytes = estimatedBytes;
this.oldestEntryTime = oldestEntryTime;
Expand Down Expand Up @@ -113,8 +113,13 @@ static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
if (streamingBufferPb.getOldestEntryTime() != null) {
oldestEntryTime = streamingBufferPb.getOldestEntryTime().longValue();
}
return new StreamingBuffer(streamingBufferPb.getEstimatedRows().longValue(),
streamingBufferPb.getEstimatedBytes().longValue(),
return new StreamingBuffer(
streamingBufferPb.getEstimatedRows() != null
? streamingBufferPb.getEstimatedRows().longValue()
: null,
streamingBufferPb.getEstimatedBytes() != null
? streamingBufferPb.getEstimatedBytes().longValue()
: null,
oldestEntryTime);
}
}
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 static org.junit.Assert.assertTrue;

import com.google.api.services.bigquery.model.Streamingbuffer;
import com.google.cloud.bigquery.StandardTableDefinition.StreamingBuffer;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -117,6 +118,12 @@ public void testToAndFromPb() {
TableDefinition.<StandardTableDefinition>fromPb(definition.toPb()));
}

@Test
public void testFromPbWithNullEstimatedRowsAndBytes() {
StandardTableDefinition.fromPb(
TABLE_DEFINITION.toPb().setStreamingBuffer(new Streamingbuffer()));
}

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