@@ -15,6 +15,7 @@ This client supports the following Google Cloud Platform services:
15
15
- [ Google Cloud Datastore] (#google-cloud-datastore)
16
16
- [ Google Cloud Storage] (#google-cloud-storage)
17
17
- [ Google Cloud Resource Manager] (#google-cloud-resource-manager)
18
+ - [ Google Cloud BigQuery] (#google-cloud-bigquery)
18
19
19
20
> Note: This client is a work-in-progress, and may occasionally
20
21
> make backwards-incompatible changes.
@@ -214,6 +215,51 @@ while (projectIterator.hasNext()) {
214
215
}
215
216
```
216
217
218
+ Google Cloud BigQuery
219
+ ----------------------
220
+
221
+ - [API Documentation][bigquery-api]
222
+ - [Official Documentation][cloud-bigquery-docs]
223
+
224
+ #### Preview
225
+
226
+ Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you
227
+ must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
228
+
229
+ ```java
230
+ import com.google.gcloud.bigquery.BaseTableInfo;
231
+ import com.google.gcloud.bigquery.BigQuery;
232
+ import com.google.gcloud.bigquery.BigQueryOptions;
233
+ import com.google.gcloud.bigquery.Field;
234
+ import com.google.gcloud.bigquery.JobStatus;
235
+ import com.google.gcloud.bigquery.LoadJobInfo;
236
+ import com.google.gcloud.bigquery.Schema;
237
+ import com.google.gcloud.bigquery.TableId;
238
+ import com.google.gcloud.bigquery.TableInfo;
239
+
240
+ BigQuery bigquery = BigQueryOptions.defaultInstance().service();
241
+ TableId tableId = TableId.of("dataset", "table");
242
+ BaseTableInfo info = bigquery.getTable(tableId);
243
+ if (info == null) {
244
+ System.out.println("Creating table " + tableId);
245
+ Field integerField = Field.of("fieldName", Field.Type.integer());
246
+ bigquery.create(TableInfo.of(tableId, Schema.of(integerField)));
247
+ } else {
248
+ System.out.println("Loading data into table " + tableId);
249
+ LoadJobInfo loadJob = LoadJobInfo.of(tableId, "gs://bucket/path");
250
+ loadJob = bigquery.create(loadJob);
251
+ while (loadJob.status().state() != JobStatus.State.DONE) {
252
+ Thread.sleep(1000L);
253
+ loadJob = bigquery.getJob(loadJob.jobId());
254
+ }
255
+ if (loadJob.status().error() != null) {
256
+ System.out.println("Job completed with errors");
257
+ } else {
258
+ System.out.println("Job succeeded");
259
+ }
260
+ }
261
+ ```
262
+
217
263
Troubleshooting
218
264
---------------
219
265
@@ -276,3 +322,7 @@ Apache 2.0 - See [LICENSE] for more information.
276
322
277
323
[resourcemanager-api]:http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html? com/google/gcloud/resourcemanager/package-summary.html
278
324
[cloud-resourcemanager-docs]:https://cloud.google.com/resource-manager/
325
+
326
+ [cloud-bigquery]: https://cloud.google.com/bigquery/
327
+ [cloud-bigquery-docs]: https://cloud.google.com/bigquery/docs/overview
328
+ [bigquery-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html? com/google/gcloud/bigquery/package-summary.html
0 commit comments