Skip to content

Commit e34cd18

Browse files
wmwongmziccard
authored andcommitted
---
yaml --- r: 5115 b: refs/heads/master c: 180b73e h: refs/heads/master i: 5113: 9da2b59 5111: de2e902
1 parent d2fbc7d commit e34cd18

10 files changed

Lines changed: 356 additions & 620 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a60d06f914b608b4bcc80896f5dd431f40ad79a8
2+
refs/heads/master: 180b73e185e5bf2ea03ac78e3f51af720b3326eb
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 7406918e071dd2c5677a638ae2a06e7592b6542c
55
refs/heads/pubsub-alpha: d6bbd32eed6cb48cda8d6798ee70ddd6bfc1f07d

trunk/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,6 @@ public Job build() {
127127
/**
128128
* Checks if this job exists.
129129
*
130-
* <p>Example of checking that a job exists.
131-
* <pre> {@code
132-
* if (!job.exists()) {
133-
* // job doesn't exist
134-
* }
135-
* }</pre>
136-
*
137130
* @return {@code true} if this job exists, {@code false} otherwise
138131
* @throws BigQueryException upon failure
139132
*/
@@ -143,14 +136,11 @@ public boolean exists() {
143136

144137
/**
145138
* Checks if this job has completed its execution, either failing or succeeding. If the job does
146-
* not exist this method returns {@code true}.
147-
*
148-
* <p>Example of waiting for a job until it reports that it is done.
139+
* not exist this method returns {@code true}. You can wait for job completion with:
149140
* <pre> {@code
150-
* while (!job.isDone()) {
141+
* while(!job.isDone()) {
151142
* Thread.sleep(1000L);
152-
* }
153-
* }</pre>
143+
* }}</pre>
154144
*
155145
* @return {@code true} if this job is in {@link JobStatus.State#DONE} state or if it does not
156146
* exist, {@code false} if the state is not {@link JobStatus.State#DONE}
@@ -168,7 +158,7 @@ public boolean isDone() {
168158
* value use {@link WaitForOption#checkEvery(long, TimeUnit)}. Use
169159
* {@link WaitForOption#timeout(long, TimeUnit)} to set the maximum time to wait.
170160
*
171-
* <p>Example usage of {@code waitFor()}.
161+
* <p>Example usage of {@code waitFor()}:
172162
* <pre> {@code
173163
* Job completedJob = job.waitFor();
174164
* if (completedJob == null) {
@@ -177,23 +167,19 @@ public boolean isDone() {
177167
* // job failed, handle error
178168
* } else {
179169
* // job completed successfully
180-
* }
181-
* }</pre>
170+
* }}</pre>
182171
*
183-
* <p>Example usage of {@code waitFor()} with checking period and timeout.
172+
* <p>Example usage of {@code waitFor()} with checking period and timeout:
184173
* <pre> {@code
185-
* Job completedJob =
186-
* job.waitFor(
187-
* WaitForOption.checkEvery(1, TimeUnit.SECONDS),
188-
* WaitForOption.timeout(60, TimeUnit.SECONDS));
174+
* Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
175+
* WaitForOption.timeout(60, TimeUnit.SECONDS));
189176
* if (completedJob == null) {
190177
* // job no longer exists
191178
* } else if (completedJob.status().error() != null) {
192179
* // job failed, handle error
193180
* } else {
194181
* // job completed successfully
195-
* }
196-
* }</pre>
182+
* }}</pre>
197183
*
198184
* @param waitOptions options to configure checking period and timeout
199185
* @throws BigQueryException upon failure
@@ -221,22 +207,6 @@ public Job waitFor(WaitForOption... waitOptions) throws InterruptedException, Ti
221207
/**
222208
* Fetches current job's latest information. Returns {@code null} if the job does not exist.
223209
*
224-
* <p>Example of reloading all fields until job status is DONE.
225-
* <pre> {@code
226-
* while (job.status().state() != JobStatus.State.DONE) {
227-
* Thread.sleep(1000L);
228-
* job = job.reload();
229-
* }
230-
* }</pre>
231-
*
232-
* <p>Example of reloading status field until job status is DONE.
233-
* <pre> {@code
234-
* while (job.status().state() != JobStatus.State.DONE) {
235-
* Thread.sleep(1000L);
236-
* job = job.reload(BigQuery.JobOption.fields(BigQuery.JobField.STATUS));
237-
* }
238-
* }</pre>
239-
*
240210
* @param options job options
241211
* @return a {@code Job} object with latest information or {@code null} if not found
242212
* @throws BigQueryException upon failure
@@ -248,15 +218,6 @@ public Job reload(JobOption... options) {
248218
/**
249219
* Sends a job cancel request.
250220
*
251-
* <p>Example of cancelling a job.
252-
* <pre> {@code
253-
* if (job.cancel()) {
254-
* return true; // job successfully cancelled
255-
* } else {
256-
* // job not found
257-
* }
258-
* }</pre>
259-
*
260221
* @return {@code true} if cancel request was sent successfully, {@code false} if job was not
261222
* found
262223
* @throws BigQueryException upon failure

trunk/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Query.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,6 @@ ToStringHelper toStringHelper() {
182182
/**
183183
* Returns a new {@link GqlQuery} builder.
184184
*
185-
* <p>Example of creating and running a GQL query.
186-
* <pre> {@code
187-
* String kind = "my_kind";
188-
* String gqlQuery = "select * from " + kind;
189-
* Query<?> query = Query.gqlQueryBuilder(gqlQuery).build();
190-
* QueryResults<?> results = datastore.run(query);
191-
* // Use results
192-
* }</pre>
193-
*
194185
* @see <a href="https://cloud.google.com/datastore/docs/apis/gql/gql_reference">GQL Reference</a>
195186
*/
196187
public static GqlQuery.Builder<?> gqlQueryBuilder(String gql) {
@@ -200,15 +191,6 @@ public static GqlQuery.Builder<?> gqlQueryBuilder(String gql) {
200191
/**
201192
* Returns a new {@link GqlQuery} builder.
202193
*
203-
* <p>Example of creating and running a typed GQL query.
204-
* <pre> {@code
205-
* String kind = "my_kind";
206-
* String gqlQuery = "select * from " + kind;
207-
* Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
208-
* QueryResults<Entity> results = datastore.run(query);
209-
* // Use results
210-
* }</pre>
211-
*
212194
* @see <a href="https://cloud.google.com/datastore/docs/apis/gql/gql_reference">GQL Reference</a>
213195
*/
214196
public static <V> GqlQuery.Builder<V> gqlQueryBuilder(ResultType<V> resultType, String gql) {
@@ -217,51 +199,20 @@ public static <V> GqlQuery.Builder<V> gqlQueryBuilder(ResultType<V> resultType,
217199

218200
/**
219201
* Returns a new {@link StructuredQuery} builder for full (complete entities) queries.
220-
*
221-
* <p>Example of creating and running an entity query.
222-
* <pre> {@code
223-
* String kind = "my_kind";
224-
* Query<Entity> query = Query.entityQueryBuilder().kind(kind).build();
225-
* QueryResults<Entity> results = datastore.run(query);
226-
* // Use results
227-
* }</pre>
228-
*
229202
*/
230203
public static EntityQuery.Builder entityQueryBuilder() {
231204
return new EntityQuery.Builder();
232205
}
233206

234207
/**
235208
* Returns a new {@link StructuredQuery} builder for key only queries.
236-
*
237-
* <p>Example of creating and running a key query.
238-
* <pre> {@code
239-
* String kind = "my_kind";
240-
* Query<Key> query = Query.keyQueryBuilder().kind(kind).build();
241-
* QueryResults<Key> results = datastore.run(query);
242-
* // Use results
243-
* }</pre>
244-
*
245209
*/
246210
public static KeyQuery.Builder keyQueryBuilder() {
247211
return new KeyQuery.Builder();
248212
}
249213

250214
/**
251215
* Returns a new {@link StructuredQuery} builder for projection queries.
252-
*
253-
* <p>Example of creating and running a projection entity query.
254-
* <pre> {@code
255-
* String kind = "my_kind";
256-
* String property = "my_property";
257-
* Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
258-
* .kind(kind)
259-
* .addProjection(property)
260-
* .build();
261-
* QueryResults<ProjectionEntity> results = datastore.run(query);
262-
* // Use results
263-
* }</pre>
264-
*
265216
*/
266217
public static ProjectionEntityQuery.Builder projectionEntityQueryBuilder() {
267218
return new ProjectionEntityQuery.Builder();
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Copyright 2016 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+
/*
18+
* EDITING INSTRUCTIONS
19+
* This file is referenced in Dataset’s javadoc. Any change to this file should be reflected in
20+
* Dataset’s javadoc.
21+
*/
22+
23+
package com.google.cloud.examples.bigquery.snippets;
24+
25+
import com.google.cloud.Page;
26+
import com.google.cloud.bigquery.BigQuery.TableListOption;
27+
import com.google.cloud.bigquery.Dataset;
28+
import com.google.cloud.bigquery.Dataset.Builder;
29+
import com.google.cloud.bigquery.Field;
30+
import com.google.cloud.bigquery.Schema;
31+
import com.google.cloud.bigquery.StandardTableDefinition;
32+
import com.google.cloud.bigquery.Table;
33+
import java.util.Iterator;
34+
35+
/**
36+
* This class contains a number of snippets for the {@link Dataset} interface.
37+
*/
38+
public class DatasetSnippets {
39+
40+
private final Dataset dataset;
41+
42+
public DatasetSnippets(Dataset dataset) {
43+
this.dataset = dataset;
44+
}
45+
46+
/**
47+
* Example of checking whether a dataset exists.
48+
*/
49+
// [TARGET exists()]
50+
public boolean doesDatasetExist() {
51+
// [START doesDatasetExist]
52+
boolean exists = this.dataset.exists();
53+
// [END doesDatasetExist]
54+
return exists;
55+
}
56+
57+
/**
58+
* Example of reloading a dataset.
59+
*/
60+
// [TARGET reload(BigQuery.DatasetOption... options)]
61+
public Dataset reloadDataset() {
62+
// [START reloadDataset]
63+
Dataset dataset = this.dataset.reload();
64+
if (dataset != null) {
65+
// The dataset was reloaded.
66+
} else {
67+
// The dataset was not found.
68+
}
69+
// [END reloadDataset]
70+
return dataset;
71+
}
72+
73+
/**
74+
* Example of updating a dataset.
75+
*/
76+
// [TARGET update(BigQuery.DatasetOption... options)]
77+
// [VARIABLE "my_friendly_name"]
78+
public Dataset updateDataset(String friendlyName) {
79+
// [START updateDataset]
80+
Builder builder = this.dataset.toBuilder();
81+
builder.friendlyName(friendlyName);
82+
Dataset updatedDataset = builder.build().update();
83+
// [END updateDataset]
84+
return updatedDataset;
85+
}
86+
87+
/**
88+
* Example of deleting a dataset.
89+
*/
90+
// [TARGET delete()]
91+
public boolean deleteDataset() {
92+
// [START deleteDataset]
93+
boolean deleted = this.dataset.delete();
94+
if (deleted) {
95+
// The dataset was deleted.
96+
} else {
97+
// The dataset was not found.
98+
}
99+
// [END deleteDataset]
100+
return deleted;
101+
}
102+
103+
/**
104+
* Example of listing dataset tables.
105+
*/
106+
// [TARGET list(BigQuery.TableListOption... options)]
107+
public Page<Table> listDataset() {
108+
// [START listDataset]
109+
Page<Table> tables = dataset.list();
110+
Iterator<Table> tableIterator = tables.iterateAll();
111+
while (tableIterator.hasNext()) {
112+
Table table = tableIterator.next();
113+
// do something with the table
114+
}
115+
// [END listDataset]
116+
return tables;
117+
}
118+
119+
/**
120+
* Example of getting a dataset table.
121+
*/
122+
// [TARGET get(String table, BigQuery.TableOption... options)]
123+
// [VARIABLE “my_table”]
124+
public Table getTable(String tableName) {
125+
// [START getTable]
126+
Table table = dataset.get(tableName);
127+
// [END getTable]
128+
return table;
129+
}
130+
131+
/**
132+
* Example of creating an empty dataset table.
133+
*/
134+
// [TARGET create(String table, TableDefinition definition, BigQuery.TableOption... options)]
135+
// [VARIABLE “my_table”]
136+
public Table createTable(String tableName) {
137+
// [START createTable]
138+
StandardTableDefinition definition = StandardTableDefinition.builder()
139+
.build();
140+
Table table = dataset.create(tableName, definition);
141+
// [END createTable]
142+
return table;
143+
}
144+
145+
/**
146+
* Example of creating a dataset table with schema and time partitioning.
147+
*/
148+
// [TARGET create(String table, TableDefinition definition, BigQuery.TableOption... options)]
149+
// [VARIABLE “my_table”]
150+
// [VARIABLE “my_field”]
151+
public Table createTable(String tableName, String fieldName) {
152+
// [START createTable]
153+
Schema schema = Schema.builder()
154+
.addField(Field.of(fieldName, Field.Type.string()))
155+
.build();
156+
StandardTableDefinition definition = StandardTableDefinition.builder()
157+
.schema(schema)
158+
.build();
159+
Table table = dataset.create(tableName, definition);
160+
// [END createTable]
161+
return table;
162+
}
163+
164+
}

trunk/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/InsertDataAndQueryTable.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ public static void main(String... args) throws InterruptedException {
7070
firstRow.put("StringField", "value1");
7171
secondRow.put("StringField", "value2");
7272
// Create an insert request
73-
InsertAllRequest insertRequest =
74-
InsertAllRequest.builder(tableId).addRow(firstRow).addRow(secondRow).build();
73+
InsertAllRequest insertRequest = InsertAllRequest.builder(tableId)
74+
.addRow(firstRow)
75+
.addRow(secondRow)
76+
.build();
7577
// Insert rows
7678
InsertAllResponse insertResponse = bigquery.insertAll(insertRequest);
7779
// Check if errors occurred
@@ -80,11 +82,10 @@ public static void main(String... args) throws InterruptedException {
8082
}
8183

8284
// Create a query request
83-
QueryRequest queryRequest =
84-
QueryRequest.builder("SELECT * FROM my_dataset_id.my_table_id")
85-
.maxWaitTime(60000L)
86-
.pageSize(1000L)
87-
.build();
85+
QueryRequest queryRequest = QueryRequest.builder("SELECT * FROM my_dataset_id.my_table_id")
86+
.maxWaitTime(60000L)
87+
.pageSize(1000L)
88+
.build();
8889
// Request query to be executed and wait for results
8990
QueryResponse queryResponse = bigquery.query(queryRequest);
9091
while (!queryResponse.jobCompleted()) {

0 commit comments

Comments
 (0)