Skip to content

Commit fda1bdf

Browse files
committed
Move StreamingBuffer to TableInfo, remove streamingBuffer from ExternalTableInfo
1 parent e91f47b commit fda1bdf

File tree

5 files changed

+87
-111
lines changed

5 files changed

+87
-111
lines changed

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableInfo.java

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -81,79 +81,6 @@ public enum Type {
8181
EXTERNAL
8282
}
8383

84-
/**
85-
* Google BigQuery Table's Streaming Buffer information. This class contains information on a
86-
* table's streaming buffer as the estimated size in number of rows/bytes.
87-
*/
88-
public static class StreamingBuffer implements Serializable {
89-
90-
private static final long serialVersionUID = -6713971364725267597L;
91-
private final long estimatedRows;
92-
private final long estimatedBytes;
93-
private final long oldestEntryTime;
94-
95-
StreamingBuffer(long estimatedRows, long estimatedBytes, long oldestEntryTime) {
96-
this.estimatedRows = estimatedRows;
97-
this.estimatedBytes = estimatedBytes;
98-
this.oldestEntryTime = oldestEntryTime;
99-
}
100-
101-
/**
102-
* Returns a lower-bound estimate of the number of rows currently in the streaming buffer.
103-
*/
104-
public long estimatedRows() {
105-
return estimatedRows;
106-
}
107-
108-
/**
109-
* Returns a lower-bound estimate of the number of bytes currently in the streaming buffer.
110-
*/
111-
public long estimatedBytes() {
112-
return estimatedBytes;
113-
}
114-
115-
/**
116-
* Returns the timestamp of the oldest entry in the streaming buffer, in milliseconds since
117-
* epoch.
118-
*/
119-
public long oldestEntryTime() {
120-
return oldestEntryTime;
121-
}
122-
123-
@Override
124-
public String toString() {
125-
return MoreObjects.toStringHelper(this)
126-
.add("estimatedRows", estimatedRows)
127-
.add("estimatedBytes", estimatedBytes)
128-
.add("oldestEntryTime", oldestEntryTime)
129-
.toString();
130-
}
131-
132-
@Override
133-
public int hashCode() {
134-
return Objects.hash(estimatedRows, estimatedBytes, oldestEntryTime);
135-
}
136-
137-
@Override
138-
public boolean equals(Object obj) {
139-
return obj instanceof StreamingBuffer
140-
&& Objects.equals(toPb(), ((StreamingBuffer) obj).toPb());
141-
}
142-
143-
Streamingbuffer toPb() {
144-
return new Streamingbuffer()
145-
.setEstimatedBytes(BigInteger.valueOf(estimatedBytes))
146-
.setEstimatedRows(BigInteger.valueOf(estimatedRows))
147-
.setOldestEntryTime(BigInteger.valueOf(oldestEntryTime));
148-
}
149-
150-
static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
151-
return new StreamingBuffer(streamingBufferPb.getEstimatedRows().longValue(),
152-
streamingBufferPb.getEstimatedBytes().longValue(),
153-
streamingBufferPb.getOldestEntryTime().longValue());
154-
}
155-
}
156-
15784
private final String etag;
15885
private final String id;
15986
private final String selfLink;

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableInfo.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,24 @@
2626
* reside outside of BigQuery but can be queried as normal BigQuery tables. External tables are
2727
* experimental and might be subject to change or removed.
2828
*
29-
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
30-
* Sources</a>
29+
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data Sources
30+
* </a>
3131
*/
3232
public class ExternalTableInfo extends BaseTableInfo {
3333

3434
private static final long serialVersionUID = -5893406738246214865L;
3535

3636
private final ExternalDataConfiguration configuration;
37-
private final StreamingBuffer streamingBuffer;
3837

3938
public static final class Builder extends BaseTableInfo.Builder<ExternalTableInfo, Builder> {
4039

4140
private ExternalDataConfiguration configuration;
42-
private StreamingBuffer streamingBuffer;
4341

4442
private Builder() {}
4543

4644
private Builder(ExternalTableInfo tableInfo) {
4745
super(tableInfo);
4846
this.configuration = tableInfo.configuration;
49-
this.streamingBuffer = tableInfo.streamingBuffer;
5047
}
5148

5249
protected Builder(Table tablePb) {
@@ -55,9 +52,6 @@ protected Builder(Table tablePb) {
5552
this.configuration =
5653
ExternalDataConfiguration.fromPb(tablePb.getExternalDataConfiguration());
5754
}
58-
if (tablePb.getStreamingBuffer() != null) {
59-
this.streamingBuffer = StreamingBuffer.fromPb(tablePb.getStreamingBuffer());
60-
}
6155
}
6256

6357
/**
@@ -71,11 +65,6 @@ public Builder configuration(ExternalDataConfiguration configuration) {
7165
return self();
7266
}
7367

74-
Builder streamingBuffer(StreamingBuffer streamingBuffer) {
75-
this.streamingBuffer = streamingBuffer;
76-
return self();
77-
}
78-
7968
/**
8069
* Creates a {@code ExternalTableInfo} object.
8170
*/
@@ -88,28 +77,19 @@ public ExternalTableInfo build() {
8877
private ExternalTableInfo(Builder builder) {
8978
super(builder);
9079
this.configuration = builder.configuration;
91-
this.streamingBuffer = builder.streamingBuffer;
9280
}
9381

9482
/**
9583
* Returns the data format, location and other properties of a table stored outside of BigQuery.
9684
* This property is experimental and might be subject to change or removed.
9785
*
98-
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
99-
* Sources</a>
86+
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data Sources
87+
* </a>
10088
*/
10189
public ExternalDataConfiguration configuration() {
10290
return configuration;
10391
}
10492

105-
/**
106-
* Returns information on the table's streaming buffer if any exists. Returns {@code null} if no
107-
* streaming buffer exists.
108-
*/
109-
public StreamingBuffer streamingBuffer() {
110-
return streamingBuffer;
111-
}
112-
11393
/**
11494
* Returns a builder for the {@code ExternalTableInfo} object.
11595
*/
@@ -120,18 +100,13 @@ public Builder toBuilder() {
120100

121101
@Override
122102
ToStringHelper toStringHelper() {
123-
return super.toStringHelper()
124-
.add("configuration", configuration)
125-
.add("streamingBuffer", streamingBuffer);
103+
return super.toStringHelper().add("configuration", configuration);
126104
}
127105

128106
@Override
129107
Table toPb() {
130108
Table tablePb = super.toPb();
131109
tablePb.setExternalDataConfiguration(configuration.toPb());
132-
if (streamingBuffer != null) {
133-
tablePb.setStreamingBuffer(streamingBuffer.toPb());
134-
}
135110
return tablePb;
136111
}
137112

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableInfo.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616

1717
package com.google.gcloud.bigquery;
1818

19+
import com.google.api.services.bigquery.model.Streamingbuffer;
1920
import com.google.api.services.bigquery.model.Table;
21+
import com.google.common.base.MoreObjects;
2022
import com.google.common.base.MoreObjects.ToStringHelper;
2123

24+
import java.io.Serializable;
25+
import java.math.BigInteger;
26+
import java.util.Objects;
27+
2228
/**
2329
* A Google BigQuery Table information. A BigQuery table is a standard, two-dimensional table with
2430
* individual records organized in rows, and a data type assigned to each column (also called a
@@ -34,6 +40,79 @@ public class TableInfo extends BaseTableInfo {
3440
private final String location;
3541
private final StreamingBuffer streamingBuffer;
3642

43+
/**
44+
* Google BigQuery Table's Streaming Buffer information. This class contains information on a
45+
* table's streaming buffer as the estimated size in number of rows/bytes.
46+
*/
47+
public static class StreamingBuffer implements Serializable {
48+
49+
private static final long serialVersionUID = -6713971364725267597L;
50+
private final long estimatedRows;
51+
private final long estimatedBytes;
52+
private final long oldestEntryTime;
53+
54+
StreamingBuffer(long estimatedRows, long estimatedBytes, long oldestEntryTime) {
55+
this.estimatedRows = estimatedRows;
56+
this.estimatedBytes = estimatedBytes;
57+
this.oldestEntryTime = oldestEntryTime;
58+
}
59+
60+
/**
61+
* Returns a lower-bound estimate of the number of rows currently in the streaming buffer.
62+
*/
63+
public long estimatedRows() {
64+
return estimatedRows;
65+
}
66+
67+
/**
68+
* Returns a lower-bound estimate of the number of bytes currently in the streaming buffer.
69+
*/
70+
public long estimatedBytes() {
71+
return estimatedBytes;
72+
}
73+
74+
/**
75+
* Returns the timestamp of the oldest entry in the streaming buffer, in milliseconds since
76+
* epoch.
77+
*/
78+
public long oldestEntryTime() {
79+
return oldestEntryTime;
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return MoreObjects.toStringHelper(this)
85+
.add("estimatedRows", estimatedRows)
86+
.add("estimatedBytes", estimatedBytes)
87+
.add("oldestEntryTime", oldestEntryTime)
88+
.toString();
89+
}
90+
91+
@Override
92+
public int hashCode() {
93+
return Objects.hash(estimatedRows, estimatedBytes, oldestEntryTime);
94+
}
95+
96+
@Override
97+
public boolean equals(Object obj) {
98+
return obj instanceof StreamingBuffer
99+
&& Objects.equals(toPb(), ((StreamingBuffer) obj).toPb());
100+
}
101+
102+
Streamingbuffer toPb() {
103+
return new Streamingbuffer()
104+
.setEstimatedBytes(BigInteger.valueOf(estimatedBytes))
105+
.setEstimatedRows(BigInteger.valueOf(estimatedRows))
106+
.setOldestEntryTime(BigInteger.valueOf(oldestEntryTime));
107+
}
108+
109+
static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
110+
return new StreamingBuffer(streamingBufferPb.getEstimatedRows().longValue(),
111+
streamingBufferPb.getEstimatedBytes().longValue(),
112+
streamingBufferPb.getOldestEntryTime().longValue());
113+
}
114+
}
115+
37116
public static final class Builder extends BaseTableInfo.Builder<TableInfo, Builder> {
38117

39118
private String location;

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/SerializationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.common.collect.ImmutableMap;
2424
import com.google.gcloud.AuthCredentials;
2525
import com.google.gcloud.RetryParams;
26+
import com.google.gcloud.bigquery.TableInfo.StreamingBuffer;
2627

2728
import org.junit.Test;
2829

@@ -94,8 +95,7 @@ public class SerializationTest {
9495
.description("FieldDescription3")
9596
.build();
9697
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
97-
private static final BaseTableInfo.StreamingBuffer STREAMING_BUFFER =
98-
new BaseTableInfo.StreamingBuffer(1L, 2L, 3L);
98+
private static final StreamingBuffer STREAMING_BUFFER = new StreamingBuffer(1L, 2L, 3L);
9999
private static final List<String> SOURCE_URIS = ImmutableList.of("uri1", "uri2");
100100
private static final ExternalDataConfiguration EXTERNAL_DATA_CONFIGURATION =
101101
ExternalDataConfiguration.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS)
@@ -128,7 +128,6 @@ public class SerializationTest {
128128
.description(DESCRIPTION)
129129
.etag(ETAG)
130130
.id(ID)
131-
.streamingBuffer(STREAMING_BUFFER)
132131
.build();
133132
private static final JobStatistics JOB_STATISTICS = JobStatistics.builder()
134133
.creationTime(1L)

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableInfoTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.junit.Assert.assertTrue;
2121

2222
import com.google.common.collect.ImmutableList;
23-
import com.google.gcloud.bigquery.BaseTableInfo.StreamingBuffer;
23+
import com.google.gcloud.bigquery.TableInfo.StreamingBuffer;
2424

2525
import org.junit.Test;
2626

@@ -46,7 +46,6 @@ public class TableInfoTest {
4646
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
4747
private static final String VIEW_QUERY = "VIEW QUERY";
4848
private static final List<String> SOURCE_URIS = ImmutableList.of("uri1", "uri2");
49-
private static final String SOURCE_FORMAT = "CSV";
5049
private static final Integer MAX_BAD_RECORDS = 42;
5150
private static final Boolean IGNORE_UNKNOWN_VALUES = true;
5251
private static final String COMPRESSION = "GZIP";
@@ -96,7 +95,6 @@ public class TableInfoTest {
9695
.numBytes(NUM_BYTES)
9796
.numRows(NUM_ROWS)
9897
.selfLink(SELF_LINK)
99-
.streamingBuffer(STREAMING_BUFFER)
10098
.build();
10199
private static final List<UserDefinedFunction> USER_DEFINED_FUNCTIONS =
102100
ImmutableList.of(UserDefinedFunction.inline("Function"), UserDefinedFunction.fromUri("URI"));
@@ -184,7 +182,6 @@ public void testBuilder() {
184182
assertEquals(NUM_BYTES, EXTERNAL_TABLE_INFO.numBytes());
185183
assertEquals(NUM_ROWS, EXTERNAL_TABLE_INFO.numRows());
186184
assertEquals(SELF_LINK, EXTERNAL_TABLE_INFO.selfLink());
187-
assertEquals(STREAMING_BUFFER, EXTERNAL_TABLE_INFO.streamingBuffer());
188185
assertEquals(BaseTableInfo.Type.EXTERNAL, EXTERNAL_TABLE_INFO.type());
189186
}
190187

@@ -235,6 +232,5 @@ private void compareExternalTableInfo(ExternalTableInfo expected, ExternalTableI
235232
compareBaseTableInfo(expected, value);
236233
assertEquals(expected, value);
237234
assertEquals(expected.configuration(), value.configuration());
238-
assertEquals(expected.streamingBuffer(), value.streamingBuffer());
239235
}
240236
}

0 commit comments

Comments
 (0)