Skip to content

Commit ae2a484

Browse files
committed
Remove TableType, add TableInfo, ViewInfo ExternalTableInfo hierarcy
1 parent 66972df commit ae2a484

File tree

8 files changed

+1041
-882
lines changed

8 files changed

+1041
-882
lines changed

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

Lines changed: 541 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.bigquery;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import com.google.api.services.bigquery.model.Table;
22+
import com.google.common.base.MoreObjects;
23+
24+
import java.util.Objects;
25+
26+
/**
27+
* Google BigQuery External Table information. BigQuery's external tables are tables whose data
28+
* reside outside of BigQuery but can be queried as normal BigQuery tables. External tables are
29+
* experimental and might be subject to change or removed.
30+
*
31+
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
32+
* Sources</a>
33+
*/
34+
public class ExternalTableInfo extends BaseTableInfo {
35+
36+
private static final long serialVersionUID = -5893406738246214865L;
37+
38+
private final ExternalDataConfiguration configuration;
39+
private final StreamingBuffer streamingBuffer;
40+
41+
public static final class Builder extends BaseTableInfo.Builder<ExternalTableInfo, Builder> {
42+
43+
private ExternalDataConfiguration configuration;
44+
private StreamingBuffer streamingBuffer;
45+
46+
private Builder() {}
47+
48+
private Builder(ExternalTableInfo tableInfo) {
49+
super(tableInfo);
50+
this.configuration = tableInfo.configuration;
51+
this.streamingBuffer = tableInfo.streamingBuffer;
52+
}
53+
54+
@Override
55+
protected Builder self() {
56+
return this;
57+
}
58+
59+
/**
60+
* Sets the data format, location and other properties of a table stored outside of BigQuery.
61+
*
62+
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
63+
* Sources</a>
64+
*/
65+
public Builder configuration(ExternalDataConfiguration configuration) {
66+
this.configuration = checkNotNull(configuration);
67+
return self();
68+
}
69+
70+
Builder streamingBuffer(StreamingBuffer streamingBuffer) {
71+
this.streamingBuffer = streamingBuffer;
72+
return self();
73+
}
74+
75+
/**
76+
* Creates a {@code ExternalTableInfo} object.
77+
*/
78+
@Override
79+
public ExternalTableInfo build() {
80+
return new ExternalTableInfo(this);
81+
}
82+
}
83+
84+
private ExternalTableInfo(Builder builder) {
85+
super(builder);
86+
this.configuration = checkNotNull(builder.configuration);
87+
this.streamingBuffer = builder.streamingBuffer;
88+
}
89+
90+
/**
91+
* Returns the data format, location and other properties of a table stored outside of BigQuery.
92+
* This property is experimental and might be subject to change or removed.
93+
*
94+
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
95+
* Sources</a>
96+
*/
97+
public ExternalDataConfiguration configuration() {
98+
return configuration;
99+
};
100+
101+
/**
102+
* Returns information on the table's streaming buffer if any exists. Returns {@code null} if no
103+
* streaming buffer exists.
104+
*/
105+
public StreamingBuffer streamingBuffer() {
106+
return streamingBuffer;
107+
}
108+
109+
/**
110+
* Returns a builder for the {@code ExternalTableInfo} object.
111+
*/
112+
@Override
113+
public Builder toBuilder() {
114+
return new Builder(this);
115+
}
116+
117+
@Override
118+
protected MoreObjects.ToStringHelper toStringHelper() {
119+
return super.toStringHelper()
120+
.add("configuration", configuration)
121+
.add("streamingBuffer", streamingBuffer);
122+
}
123+
124+
@Override
125+
public boolean equals(Object obj) {
126+
return obj instanceof ExternalTableInfo
127+
&& Objects.equals(toPb(), ((ExternalTableInfo) obj).toPb());
128+
}
129+
130+
@Override
131+
Table toPb() {
132+
Table tablePb = super.toPb();
133+
tablePb.setExternalDataConfiguration(configuration.toPb());
134+
if (streamingBuffer != null) {
135+
tablePb.setStreamingBuffer(streamingBuffer.toPb());
136+
}
137+
return tablePb;
138+
}
139+
140+
/**
141+
* Returns a builder for a BigQuery External Table.
142+
*
143+
* @param tableId table id
144+
* @param configuration data format, location and other properties of an External Table
145+
*/
146+
public static Builder builder(TableId tableId, ExternalDataConfiguration configuration) {
147+
return new Builder().tableId(tableId).type(Type.EXTERNAL).configuration(configuration);
148+
}
149+
150+
/**
151+
* Returns a BigQuery External Table.
152+
*
153+
* @param table table id
154+
* @param configuration data format, location and other properties of an External Table
155+
*/
156+
public static ExternalTableInfo of(TableId table, ExternalDataConfiguration configuration) {
157+
return builder(table, configuration).build();
158+
}
159+
}

0 commit comments

Comments
 (0)