Skip to content

Commit 95b4bf0

Browse files
committed
---
yaml --- r: 1663 b: refs/heads/master c: edc9db7 h: refs/heads/master i: 1661: 315c38c 1659: 7d3ebf7 1655: 5b06b61 1647: efa89f7 1631: 435e06a 1599: 4e85956 1535: fb7aac1
1 parent 80e023f commit 95b4bf0

33 files changed

Lines changed: 866 additions & 176 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: 307ddf37950a95434fcffd449f8df705ca943a24
2+
refs/heads/master: edc9db78cff07f881846e8fb79e31dc15a65aa2c
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: d1b373c30c176edc08692348167bec3a244bb823
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3

trunk/README.md

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ Google Cloud BigQuery (Alpha)
123123
124124
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you
125125
must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
126+
Complete source code can be found at
127+
[gcloud-java-examples:com.google.gcloud.examples.bigquery.snippets.CreateTableAndLoadData](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/bigquery/snippets/CreateTableAndLoadData.java).
126128
127129
```java
128130
import com.google.gcloud.bigquery.BigQuery;
129131
import com.google.gcloud.bigquery.BigQueryOptions;
130132
import com.google.gcloud.bigquery.Field;
133+
import com.google.gcloud.bigquery.FormatOptions;
131134
import com.google.gcloud.bigquery.Job;
132-
import com.google.gcloud.bigquery.JobStatus;
133-
import com.google.gcloud.bigquery.JobInfo;
134-
import com.google.gcloud.bigquery.LoadJobConfiguration;
135135
import com.google.gcloud.bigquery.Schema;
136136
import com.google.gcloud.bigquery.StandardTableDefinition;
137137
import com.google.gcloud.bigquery.Table;
@@ -145,19 +145,17 @@ if (table == null) {
145145
System.out.println("Creating table " + tableId);
146146
Field integerField = Field.of("fieldName", Field.Type.integer());
147147
Schema schema = Schema.of(integerField);
148-
bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema)));
148+
table = bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema)));
149+
}
150+
System.out.println("Loading data into table " + tableId);
151+
Job loadJob = table.load(FormatOptions.csv(), "gs://bucket/path");
152+
while (!loadJob.isDone()) {
153+
Thread.sleep(1000L);
154+
}
155+
if (loadJob.status().error() != null) {
156+
System.out.println("Job completed with errors");
149157
} else {
150-
System.out.println("Loading data into table " + tableId);
151-
LoadJobConfiguration configuration = LoadJobConfiguration.of(tableId, "gs://bucket/path");
152-
Job loadJob = bigquery.create(JobInfo.of(configuration));
153-
while (!loadJob.isDone()) {
154-
Thread.sleep(1000L);
155-
}
156-
if (loadJob.status().error() != null) {
157-
System.out.println("Job completed with errors");
158-
} else {
159-
System.out.println("Job succeeded");
160-
}
158+
System.out.println("Job succeeded");
161159
}
162160
```
163161
@@ -171,7 +169,11 @@ Google Cloud Datastore
171169
172170
#### Preview
173171
174-
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
172+
Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
173+
174+
The first snippet shows how to get a Datastore entity and create it if it does not exist. Complete
175+
source code can be found at
176+
[gcloud-java-examples:com.google.gcloud.examples.datastore.snippets.GetOrCreateEntity](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/snippets/GetOrCreateEntity.java).
175177
176178
```java
177179
import com.google.gcloud.datastore.Datastore;
@@ -182,8 +184,8 @@ import com.google.gcloud.datastore.Key;
182184
import com.google.gcloud.datastore.KeyFactory;
183185
184186
Datastore datastore = DatastoreOptions.defaultInstance().service();
185-
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND);
186-
Key key = keyFactory.newKey(keyName);
187+
KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
188+
Key key = keyFactory.newKey("keyName");
187189
Entity entity = datastore.get(key);
188190
if (entity == null) {
189191
entity = Entity.builder(key)
@@ -192,7 +194,24 @@ if (entity == null) {
192194
.set("access_time", DateTime.now())
193195
.build();
194196
datastore.put(entity);
195-
} else {
197+
}
198+
```
199+
The second snippet shows how to update a Datastore entity if it exists. Complete source code can be
200+
found at
201+
[gcloud-java-examples:com.google.gcloud.examples.datastore.snippets.UpdateEntity](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/datastore/snippets/UpdateEntity.java).
202+
```java
203+
import com.google.gcloud.datastore.Datastore;
204+
import com.google.gcloud.datastore.DatastoreOptions;
205+
import com.google.gcloud.datastore.DateTime;
206+
import com.google.gcloud.datastore.Entity;
207+
import com.google.gcloud.datastore.Key;
208+
import com.google.gcloud.datastore.KeyFactory;
209+
210+
Datastore datastore = DatastoreOptions.defaultInstance().service();
211+
KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
212+
Key key = keyFactory.newKey("keyName");
213+
Entity entity = datastore.get(key);
214+
if (entity != null) {
196215
System.out.println("Updating access_time for " + entity.getString("name"));
197216
entity = Entity.builder(entity)
198217
.set("access_time", DateTime.now())
@@ -210,7 +229,8 @@ Google Cloud Resource Manager (Alpha)
210229
#### Preview
211230
212231
Here is a code snippet showing a simple usage example. Note that you must supply Google SDK credentials for this service, not other forms of authentication listed in the [Authentication section](#authentication).
213-
232+
Complete source code can be found at
233+
[gcloud-java-examples:com.google.gcloud.examples.resourcemanager.snippets.UpdateAndListProjects](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/resourcemanager/snippets/UpdateAndListProjects.java).
214234
```java
215235
import com.google.gcloud.resourcemanager.Project;
216236
import com.google.gcloud.resourcemanager.ResourceManager;
@@ -244,13 +264,36 @@ Google Cloud Storage
244264
245265
#### Preview
246266
247-
Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
267+
Here are two code snippets showing simple usage examples from within Compute/App Engine. Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
268+
269+
The first snippet shows how to get a Storage blob and create it if it does not exist. Complete
270+
source code can be found at
271+
[gcloud-java-examples:com.google.gcloud.examples.storage.snippets.GetOrCreateBlob](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/storage/snippets/GetOrCreateBlob.java).
248272
249273
```java
250274
import static java.nio.charset.StandardCharsets.UTF_8;
251275
252276
import com.google.gcloud.storage.Blob;
277+
import com.google.gcloud.storage.BlobId;
253278
import com.google.gcloud.storage.BlobInfo;
279+
import com.google.gcloud.storage.Storage;
280+
import com.google.gcloud.storage.StorageOptions;
281+
282+
Storage storage = StorageOptions.defaultInstance().service();
283+
BlobId blobId = BlobId.of("bucket", "blob_name");
284+
Blob blob = storage.get(blobId);
285+
if (blob == null) {
286+
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
287+
blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
288+
}
289+
```
290+
The second snippet shows how to update a Storage blob if it exists. Complete source code can be
291+
found at
292+
[gcloud-java-examples:com.google.gcloud.examples.storage.snippets.UpdateBlob](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/storage/snippets/UpdateBlob.java).
293+
```java
294+
import static java.nio.charset.StandardCharsets.UTF_8;
295+
296+
import com.google.gcloud.storage.Blob;
254297
import com.google.gcloud.storage.BlobId;
255298
import com.google.gcloud.storage.Storage;
256299
import com.google.gcloud.storage.StorageOptions;
@@ -261,11 +304,7 @@ import java.nio.channels.WritableByteChannel;
261304
Storage storage = StorageOptions.defaultInstance().service();
262305
BlobId blobId = BlobId.of("bucket", "blob_name");
263306
Blob blob = storage.get(blobId);
264-
if (blob == null) {
265-
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build();
266-
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
267-
} else {
268-
System.out.println("Updating content for " + blobId.name());
307+
if (blob != null) {
269308
byte[] prevContent = blob.content();
270309
System.out.println(new String(prevContent, UTF_8));
271310
WritableByteChannel channel = blob.writer();

trunk/gcloud-java-bigquery/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ while (rowIterator.hasNext()) {
203203
Here we put together all the code shown above into one program. This program assumes that you are
204204
running on Compute Engine or from your own desktop. To run this example on App Engine, simply move
205205
the code from the main method to your application's servlet class and change the print statements to
206-
display on your webpage.
206+
display on your webpage. Complete source code can be found at
207+
[gcloud-java-examples:com.google.gcloud.examples.bigquery.snippets.InsertDataAndQueryTable](https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/bigquery/snippets/InsertDataAndQueryTable.java).
208+
207209

208210
```java
209211
import com.google.gcloud.bigquery.BigQuery;
@@ -217,7 +219,6 @@ import com.google.gcloud.bigquery.QueryRequest;
217219
import com.google.gcloud.bigquery.QueryResponse;
218220
import com.google.gcloud.bigquery.Schema;
219221
import com.google.gcloud.bigquery.StandardTableDefinition;
220-
import com.google.gcloud.bigquery.Table;
221222
import com.google.gcloud.bigquery.TableId;
222223
import com.google.gcloud.bigquery.TableInfo;
223224

@@ -226,9 +227,9 @@ import java.util.Iterator;
226227
import java.util.List;
227228
import java.util.Map;
228229

229-
public class GcloudBigQueryExample {
230+
public class InsertDataAndQueryTable {
230231

231-
public static void main(String[] args) throws InterruptedException {
232+
public static void main(String... args) throws InterruptedException {
232233

233234
// Create a service instance
234235
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
@@ -244,7 +245,7 @@ public class GcloudBigQueryExample {
244245
Schema schema = Schema.of(stringField);
245246
// Create a table
246247
StandardTableDefinition tableDefinition = StandardTableDefinition.of(schema);
247-
Table createdTable = bigquery.create(TableInfo.of(tableId, tableDefinition));
248+
bigquery.create(TableInfo.of(tableId, tableDefinition));
248249

249250
// Define rows to insert
250251
Map<String, Object> firstRow = new HashMap<>();

trunk/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DatasetInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ public int hashCode() {
396396

397397
@Override
398398
public boolean equals(Object obj) {
399-
return obj != null
400-
&& obj.getClass().equals(DatasetInfo.class)
399+
return obj.getClass().equals(DatasetInfo.class)
401400
&& Objects.equals(toPb(), ((DatasetInfo) obj).toPb());
402401
}
403402

trunk/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import java.util.Objects;
2929

3030
/**
31-
* Google BigQuery external table definition. BigQuery's external tables are tables whose data
32-
* reside outside of BigQuery but can be queried as normal BigQuery tables. External tables are
31+
* Google BigQuery external table type. BigQuery's external tables are tables whose data reside
32+
* outside of BigQuery but can be queried as normal BigQuery tables. External tables are
3333
* experimental and might be subject to change or removed.
3434
*
3535
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data Sources

trunk/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/JobInfo.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ public int hashCode() {
319319

320320
@Override
321321
public boolean equals(Object obj) {
322-
return obj != null
323-
&& obj.getClass().equals(JobInfo.class)
324-
&& Objects.equals(toPb(), ((JobInfo) obj).toPb());
322+
return obj.getClass().equals(JobInfo.class) && Objects.equals(toPb(), ((JobInfo) obj).toPb());
325323
}
326324

327325
JobInfo setProjectId(String projectId) {

trunk/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/StandardTableDefinition.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
import java.util.Objects;
2727

2828
/**
29-
* A Google BigQuery default table definition. This definition is used for standard, two-dimensional
30-
* tables with individual records organized in rows, and a data type assigned to each column (also
31-
* called a field). Individual fields within a record may contain nested and repeated children
32-
* fields. Every table is described by a schema that describes field names, types, and other
33-
* information.
29+
* A Google BigQuery default table type. This type is used for standard, two-dimensional tables with
30+
* individual records organized in rows, and a data type assigned to each column (also called a
31+
* field). Individual fields within a record may contain nested and repeated children fields. Every
32+
* table is described by a schema that describes field names, types, and other information.
3433
*
3534
* @see <a href="https://cloud.google.com/bigquery/docs/tables">Managing Tables</a>
3635
*/
@@ -219,14 +218,14 @@ public StreamingBuffer streamingBuffer() {
219218
}
220219

221220
/**
222-
* Returns a builder for a BigQuery standard table definition.
221+
* Returns a builder for a BigQuery default table type.
223222
*/
224223
public static Builder builder() {
225224
return new Builder();
226225
}
227226

228227
/**
229-
* Creates a BigQuery standard table definition given its schema.
228+
* Creates a BigQuery default table type given its schema.
230229
*
231230
* @param schema the schema of the table
232231
*/

trunk/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Table.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ public InsertAllResponse insert(Iterable<InsertAllRequest.RowToInsert> rows,
213213
* @param options table data list options
214214
* @throws BigQueryException upon failure
215215
*/
216-
public Page<List<FieldValue>> list(BigQuery.TableDataListOption... options)
217-
throws BigQueryException {
216+
public Page<List<FieldValue>> list(BigQuery.TableDataListOption... options) throws BigQueryException {
218217
return bigquery.listTableData(tableId(), options);
219218
}
220219

trunk/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableDefinition.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.util.Objects;
2626

2727
/**
28-
* Base class for a Google BigQuery table definition.
28+
* Base class for a Google BigQuery table type.
2929
*/
3030
public abstract class TableDefinition implements Serializable {
3131

@@ -63,10 +63,10 @@ public enum Type {
6363
}
6464

6565
/**
66-
* Base builder for table definitions.
66+
* Base builder for table types.
6767
*
68-
* @param <T> the table definition class
69-
* @param <B> the table definition builder
68+
* @param <T> the table type class
69+
* @param <B> the table type builder
7070
*/
7171
public abstract static class Builder<T extends TableDefinition, B extends Builder<T, B>> {
7272

@@ -152,8 +152,8 @@ final int baseHashCode() {
152152
return Objects.hash(type);
153153
}
154154

155-
final boolean baseEquals(TableDefinition tableDefinition) {
156-
return Objects.equals(toPb(), tableDefinition.toPb());
155+
final boolean baseEquals(TableDefinition jobConfiguration) {
156+
return Objects.equals(toPb(), jobConfiguration.toPb());
157157
}
158158

159159
Table toPb() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ public int hashCode() {
339339

340340
@Override
341341
public boolean equals(Object obj) {
342-
return obj != null
343-
&& obj.getClass().equals(TableInfo.class)
342+
return obj.getClass().equals(TableInfo.class)
344343
&& Objects.equals(toPb(), ((TableInfo) obj).toPb());
345344
}
346345

0 commit comments

Comments
 (0)