From 329bd70010b0bf49a2a096e1b35524102f364ff0 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 29 Dec 2015 11:27:30 +0100 Subject: [PATCH 1/4] Minor fixes to READMEs and pom.xml - Add load to bigquery usage example - Sort modules alphabetically in both READMEs and pom.xml - Use BigQuery API instead of Google Cloud BigQuery API in example's README --- README.md | 156 ++++++++++++++++----------------- gcloud-java-examples/README.md | 33 +++---- pom.xml | 6 +- 3 files changed, 98 insertions(+), 97 deletions(-) diff --git a/README.md b/README.md index cce721b86a89..e3c810b200f2 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,10 @@ Java idiomatic client for [Google Cloud Platform][cloud-platform] services. This client supports the following Google Cloud Platform services: +- [Google Cloud BigQuery] (#google-cloud-bigquery) - [Google Cloud Datastore] (#google-cloud-datastore) -- [Google Cloud Storage] (#google-cloud-storage) - [Google Cloud Resource Manager] (#google-cloud-resource-manager) -- [Google Cloud BigQuery] (#google-cloud-bigquery) +- [Google Cloud Storage] (#google-cloud-storage) > Note: This client is a work-in-progress, and may occasionally > make backwards-incompatible changes. @@ -42,14 +42,14 @@ libraryDependencies += "com.google.gcloud" % "gcloud-java" % "0.1.1" Example Applications -------------------- +- [`BigQueryExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality + - Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/BigQueryExample.html). - [`DatastoreExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java) - A simple command line interface for the Cloud Datastore - Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/DatastoreExample.html). -- [`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality - - Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html). - [`ResourceManagerExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/ResourceManagerExample.java) - A simple command line interface providing some of Cloud Resource Manager's functionality - Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/ResourceManagerExample.html). -- [`BigQueryExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality - - Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/BigQueryExample.html). +- [`StorageExample`](https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java) - A simple command line interface providing some of Cloud Storage's functionality + - Read more about using this application on the [`gcloud-java-examples` docs page](http://googlecloudplatform.github.io/gcloud-java/apidocs/?com/google/gcloud/examples/StorageExample.html). Specifying a Project ID ----------------------- @@ -109,6 +109,51 @@ Next, choose a method for authenticating API requests from within your project: 4. Google Cloud SDK credentials 5. Compute Engine credentials +Google Cloud BigQuery +---------------------- + +- [API Documentation][bigquery-api] +- [Official Documentation][cloud-bigquery-docs] + +#### Preview + +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. + +```java +import com.google.gcloud.bigquery.BaseTableInfo; +import com.google.gcloud.bigquery.BigQuery; +import com.google.gcloud.bigquery.BigQueryOptions; +import com.google.gcloud.bigquery.Field; +import com.google.gcloud.bigquery.JobStatus; +import com.google.gcloud.bigquery.LoadJobInfo; +import com.google.gcloud.bigquery.Schema; +import com.google.gcloud.bigquery.TableId; +import com.google.gcloud.bigquery.TableInfo; + +BigQuery bigquery = BigQueryOptions.defaultInstance().service(); +TableId tableId = TableId.of("dataset", "table"); +BaseTableInfo info = bigquery.getTable(tableId); +if (info == null) { + System.out.println("Creating table " + tableId); + Field integerField = Field.of("fieldName", Field.Type.integer()); + bigquery.create(TableInfo.of(tableId, Schema.of(integerField))); +} else { + System.out.println("Loading data into table " + tableId); + LoadJobInfo loadJob = LoadJobInfo.of(tableId, "gs://bucket/path"); + loadJob = bigquery.create(loadJob); + while (loadJob.status().state() != JobStatus.State.DONE) { + Thread.sleep(1000L); + loadJob = bigquery.getJob(loadJob.jobId()); + } + if (loadJob.status().error() != null) { + System.out.println("Job completed with errors"); + } else { + System.out.println("Job succeeded"); + } +} +``` + Google Cloud Datastore ---------------------- @@ -149,45 +194,6 @@ if (entity == null) { } ``` -Google Cloud Storage ----------------------- - -- [API Documentation][storage-api] -- [Official Documentation][cloud-storage-docs] - -*Follow the [activation instructions][cloud-storage-activation] to use the Google Cloud Storage API with your project.* - -#### Preview - -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. - -```java -import static java.nio.charset.StandardCharsets.UTF_8; - -import com.google.gcloud.storage.Blob; -import com.google.gcloud.storage.BlobId; -import com.google.gcloud.storage.Storage; -import com.google.gcloud.storage.StorageOptions; - -import java.nio.ByteBuffer; -import java.nio.channels.WritableByteChannel; - -Storage storage = StorageOptions.defaultInstance().service(); -BlobId blobId = BlobId.of("bucket", "blob_name"); -Blob blob = Blob.load(storage, blobId); -if (blob == null) { - BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build(); - storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8)); -} else { - System.out.println("Updating content for " + blobId.name()); - byte[] prevContent = blob.content(); - System.out.println(new String(prevContent, UTF_8)); - WritableByteChannel channel = blob.writer(); - channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8))); - channel.close(); -} -``` - Google Cloud Resource Manager ---------------------- @@ -219,48 +225,42 @@ while (projectIterator.hasNext()) { } ``` -Google Cloud BigQuery +Google Cloud Storage ---------------------- -- [API Documentation][bigquery-api] -- [Official Documentation][cloud-bigquery-docs] +- [API Documentation][storage-api] +- [Official Documentation][cloud-storage-docs] + +*Follow the [activation instructions][cloud-storage-activation] to use the Google Cloud Storage API with your project.* #### Preview -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. +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. ```java -import com.google.gcloud.bigquery.BaseTableInfo; -import com.google.gcloud.bigquery.BigQuery; -import com.google.gcloud.bigquery.BigQueryOptions; -import com.google.gcloud.bigquery.Field; -import com.google.gcloud.bigquery.JobStatus; -import com.google.gcloud.bigquery.LoadJobInfo; -import com.google.gcloud.bigquery.Schema; -import com.google.gcloud.bigquery.TableId; -import com.google.gcloud.bigquery.TableInfo; +import static java.nio.charset.StandardCharsets.UTF_8; -BigQuery bigquery = BigQueryOptions.defaultInstance().service(); -TableId tableId = TableId.of("dataset", "table"); -BaseTableInfo info = bigquery.getTable(tableId); -if (info == null) { - System.out.println("Creating table " + tableId); - Field integerField = Field.of("fieldName", Field.Type.integer()); - bigquery.create(TableInfo.of(tableId, Schema.of(integerField))); +import com.google.gcloud.storage.Blob; +import com.google.gcloud.storage.BlobId; +import com.google.gcloud.storage.Storage; +import com.google.gcloud.storage.StorageOptions; + +import java.nio.ByteBuffer; +import java.nio.channels.WritableByteChannel; + +Storage storage = StorageOptions.defaultInstance().service(); +BlobId blobId = BlobId.of("bucket", "blob_name"); +Blob blob = Blob.load(storage, blobId); +if (blob == null) { + BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("text/plain").build(); + storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8)); } else { - System.out.println("Loading data into table " + tableId); - LoadJobInfo loadJob = LoadJobInfo.of(tableId, "gs://bucket/path"); - loadJob = bigquery.create(loadJob); - while (loadJob.status().state() != JobStatus.State.DONE) { - Thread.sleep(1000L); - loadJob = bigquery.getJob(loadJob.jobId()); - } - if (loadJob.status().error() != null) { - System.out.println("Job completed with errors"); - } else { - System.out.println("Job succeeded"); - } + System.out.println("Updating content for " + blobId.name()); + byte[] prevContent = blob.content(); + System.out.println(new String(prevContent, UTF_8)); + WritableByteChannel channel = blob.writer(); + channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8))); + channel.close(); } ``` diff --git a/gcloud-java-examples/README.md b/gcloud-java-examples/README.md index f0131e6ade84..0f66fe523e26 100644 --- a/gcloud-java-examples/README.md +++ b/gcloud-java-examples/README.md @@ -39,6 +39,17 @@ To run examples from your command line: 4. Run an example using Maven from command line. + Here's an example run of `BigQueryExample`. + + Before running the example, go to the [Google Developers Console][developers-console] to ensure that BigQuery API is enabled. + ``` + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create dataset new_dataset_id" + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create table new_dataset_id new_table_id field_name:string" + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="list tables new_dataset_id" + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="load new_dataset_id new_table_id CSV gs://my_bucket/my_csv_file" + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="query 'select * from new_dataset_id.new_table_id'" + ``` + Here's an example run of `DatastoreExample`. Note that you have to enable the Google Cloud Datastore API on the [Google Developers Console][developers-console] before running the following commands. @@ -48,16 +59,6 @@ To run examples from your command line: $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name delete" ``` - Here's an example run of `StorageExample`. - - Before running the example, go to the [Google Developers Console][developers-console] to ensure that Google Cloud Storage API is enabled and that you have a bucket. Also ensure that you have a test file (`test.txt` is chosen here) to upload to Cloud Storage stored locally on your machine. - ``` - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="upload /path/to/test.txt " - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="list " - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="download test.txt" - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="delete test.txt" - ``` - Here's an example run of `ResourceManagerExample`. Be sure to change the placeholder project ID "my-project-id" with your own globally unique project ID. @@ -67,14 +68,14 @@ To run examples from your command line: $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.ResourceManagerExample" -Dexec.args="get my-project-id" ``` - Here's an example run of `BigQueryExample`. + Here's an example run of `StorageExample`. - Before running the example, go to the [Google Developers Console][developers-console] to ensure that Google Cloud BigQuery API is enabled. + Before running the example, go to the [Google Developers Console][developers-console] to ensure that Google Cloud Storage API is enabled and that you have a bucket. Also ensure that you have a test file (`test.txt` is chosen here) to upload to Cloud Storage stored locally on your machine. ``` - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create dataset new_dataset_id" - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create table new_dataset_id new_table_id field_name:string" - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="list tables new_dataset_id" - $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="query 'select * from new_dataset_id.new_table_id'" + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="upload /path/to/test.txt " + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="list " + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="download test.txt" + $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="delete test.txt" ``` Troubleshooting diff --git a/pom.xml b/pom.xml index 20aa2c057a99..b27c9cc123a4 100644 --- a/pom.xml +++ b/pom.xml @@ -66,13 +66,13 @@ gcloud-java + gcloud-java + gcloud-java-bigquery gcloud-java-core gcloud-java-datastore + gcloud-java-examples gcloud-java-resourcemanager gcloud-java-storage - gcloud-java - gcloud-java-examples - gcloud-java-bigquery From 7e052dae27b857ed3301e6aed83e41bd01d40e48 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 29 Dec 2015 11:29:29 +0100 Subject: [PATCH 2/4] Minor changes to gcloud-java-examples - Remove unnecessary 'the' in examples javadoc - Split long usage examples into multiple lines for BigQueryExample and StorageExample - Add messages to IllegalArgumentException in BigQueryExample and display better error - Handle no arguments case in BigQueryExample - Handle boolean result of delete and cancel actions in BigQueryExample --- .../gcloud/examples/BigQueryExample.java | 122 +++++++++++++----- .../gcloud/examples/DatastoreExample.java | 2 +- .../examples/ResourceManagerExample.java | 2 +- .../gcloud/examples/StorageExample.java | 18 ++- 4 files changed, 101 insertions(+), 43 deletions(-) diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java index eb46bc69adf4..a1190c705faf 100644 --- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java +++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java @@ -49,7 +49,7 @@ import java.util.Map; /** - * An example of using the Google BigQuery. + * An example of using Google BigQuery. * *

This example demonstrates a simple/typical BigQuery usage. * @@ -58,17 +58,25 @@ *

  • login using gcloud SDK - {@code gcloud auth login}.
  • *
  • compile using maven - {@code mvn compile}
  • *
  • run using maven - - * {@code mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" - * -Dexec.args="[] list datasets | list tables | list jobs | - * list data | info dataset | info table
    | - * info job | create dataset | + *
    {@code mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="[]
    + *  list datasets |
    + *  list tables  |
    + *  list jobs |
    + *  list data  
    | + * info dataset | + * info table
    | + * info job | + * create dataset | * create table
    (:)+ | * create view
    | * create external-table
    (:)+ | - * delete dataset | delete table
    | cancel | + * delete dataset | + * delete table
    | + * cancel | * copy | * load
    + | - * extract
    + | query "} + * extract
    + | + * query "} * * * @@ -122,16 +130,18 @@ Tuple parse(String... args) throws Exception { if (action != null) { Object actionArguments = action.parse(Arrays.copyOfRange(args, 1, args.length)); return Tuple.of(action, actionArguments); + } else { + throw new IllegalArgumentException("Unrecognized entity '" + args[0] + "'."); } } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Missing required entity."); } @Override public String params() { StringBuilder builder = new StringBuilder(); for (Map.Entry entry : subActions.entrySet()) { - builder.append("\n").append(entry.getKey()); + builder.append('\n').append(entry.getKey()); String param = entry.getValue().params(); if (param != null && !param.isEmpty()) { builder.append(' ').append(param); @@ -141,13 +151,13 @@ public String params() { } } - private abstract static class VoidAction extends BigQueryAction { + private abstract static class NoArgsAction extends BigQueryAction { @Override Void parse(String... args) throws Exception { if (args.length == 0) { return null; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException("This action takes no arguments."); } } @@ -157,7 +167,7 @@ Void parse(String... args) throws Exception { * @see Datasets: list * */ - private static class ListDatasetsAction extends VoidAction { + private static class ListDatasetsAction extends NoArgsAction { @Override public void run(BigQuery bigquery, Void arg) { Iterator datasetInfoIterator = bigquery.listDatasets().iterateAll(); @@ -170,10 +180,15 @@ public void run(BigQuery bigquery, Void arg) { private abstract static class DatasetAction extends BigQueryAction { @Override DatasetId parse(String... args) throws Exception { + String message; if (args.length == 1) { return DatasetId.of(args[0]); + } else if (args.length > 1) { + message = "Too many arguments."; + } else { + message = "Missing required dataset id."; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(message); } @Override @@ -233,18 +248,26 @@ public void run(BigQuery bigquery, DatasetId datasetId) { private static class DeleteDatasetAction extends DatasetAction { @Override public void run(BigQuery bigquery, DatasetId datasetId) { - bigquery.delete(datasetId); - System.out.println("Dataset " + datasetId + " was deleted"); + if (bigquery.delete(datasetId)) { + System.out.println("Dataset " + datasetId + " was deleted"); + } else { + System.out.println("Dataset " + datasetId + " not found"); + } } } private abstract static class TableAction extends BigQueryAction { @Override TableId parse(String... args) throws Exception { + String message; if (args.length == 2) { return TableId.of(args[0], args[1]); + } else if (args.length < 2) { + message = "Missing required dataset and table id."; + } else { + message = "Too many arguments."; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(message); } @Override @@ -274,8 +297,11 @@ public void run(BigQuery bigquery, TableId tableId) { private static class DeleteTableAction extends TableAction { @Override public void run(BigQuery bigquery, TableId tableId) { - bigquery.delete(tableId); - System.out.println("Table " + tableId + " was deleted"); + if (bigquery.delete(tableId)) { + System.out.println("Table " + tableId + " was deleted"); + } else { + System.out.println("Table " + tableId + " not found"); + } } } @@ -298,10 +324,15 @@ public void run(BigQuery bigquery, TableId tableId) { private abstract static class JobAction extends BigQueryAction { @Override JobId parse(String... args) throws Exception { + String message; if (args.length == 1) { return JobId.of(args[0]); + } else if (args.length > 1) { + message = "Too many arguments."; + } else { + message = "Missing required query."; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(message); } @Override @@ -315,7 +346,7 @@ public String params() { * * @see Jobs: list */ - private static class ListJobsAction extends VoidAction { + private static class ListJobsAction extends NoArgsAction { @Override public void run(BigQuery bigquery, Void arg) { Iterator datasetInfoIterator = bigquery.listJobs().iterateAll(); @@ -345,8 +376,11 @@ public void run(BigQuery bigquery, JobId jobId) { private static class CancelJobAction extends JobAction { @Override public void run(BigQuery bigquery, JobId jobId) { - bigquery.cancel(jobId); - System.out.println("Requested cancel for job " + jobId); + if (bigquery.cancel(jobId)) { + System.out.println("Requested cancel for job " + jobId); + } else { + System.out.println("Job " + jobId + " not found"); + } } } @@ -354,7 +388,7 @@ private abstract static class CreateTableAction extends BigQueryAction 1) { + message = "Too many arguments."; + } else { + message = "Missing required query."; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException(message); } @Override @@ -650,6 +699,11 @@ private static void printUsage() { @SuppressWarnings("unchecked") public static void main(String... args) throws Exception { + if (args.length < 1) { + System.out.println("Missing required project id and action"); + printUsage(); + return; + } BigQueryOptions.Builder optionsBuilder = BigQueryOptions.builder(); BigQueryAction action; String actionName; @@ -673,7 +727,7 @@ public static void main(String... args) throws Exception { try { request = action.parse(args); } catch (IllegalArgumentException ex) { - System.out.println("Invalid input for action '" + actionName + "'"); + System.out.println("Invalid input for action '" + actionName + "'. " + ex.getMessage()); System.out.println("Expected: " + action.params()); return; } catch (Exception ex) { diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java index 0951e3e93978..e408bab1338e 100644 --- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java +++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java @@ -36,7 +36,7 @@ import java.util.TreeMap; /** - * An example of using the Google Cloud Datastore. + * An example of using Google Cloud Datastore. * *

    This example adds, display or clear comments for a given user. * diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/ResourceManagerExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/ResourceManagerExample.java index 049ed35368db..c1ba4e06cf7d 100644 --- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/ResourceManagerExample.java +++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/ResourceManagerExample.java @@ -27,7 +27,7 @@ import java.util.Scanner; /** - * An example of using the Google Cloud Resource Manager. + * An example of using Google Cloud Resource Manager. * *

    This example creates, deletes, gets, and lists projects. * diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java index e042e8eb54bc..deaedfa7f027 100644 --- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java +++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java @@ -58,7 +58,7 @@ import java.util.concurrent.TimeUnit; /** - * An example of using the Google Cloud Storage. + * An example of using Google Cloud Storage. * *

    This example demonstrates a simple/typical storage usage. * @@ -67,12 +67,16 @@ *

  • login using gcloud SDK - {@code gcloud auth login}.
  • *
  • compile using maven - {@code mvn compile}
  • *
  • run using maven - - * {@code mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" - * -Dexec.args="[] list [] | info [ []] | - * download [local_file] | upload [] | - * delete + | cp | - * compose + | update_metadata [key=value]* | - * sign_url "} + *
    {@code mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="[]
    + *  list [] |
    + *  info [ []] |
    + *  download   [local_file] |
    + *  upload   [] |
    + *  delete  + |
    + *  cp     |
    + *  compose  +  |
    + *  update_metadata   [key=value]* |
    + *  sign_url    "}
    *
  • * * From f78da9d7f3a4f069d05208384d9a53dbd59689df Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 29 Dec 2015 11:32:59 +0100 Subject: [PATCH 3/4] Add checkNotNull to FormatOptions.of method --- .../main/java/com/google/gcloud/bigquery/FormatOptions.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java index ebf9f651a8d2..f46e7b40f4c1 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/FormatOptions.java @@ -16,6 +16,8 @@ package com.google.gcloud.bigquery; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.MoreObjects; import java.io.Serializable; @@ -85,7 +87,7 @@ public static FormatOptions datastoreBackup() { * Default options for the provided format. */ public static FormatOptions of(String format) { - if (format.equals(CSV)) { + if (checkNotNull(format).equals(CSV)) { return csv(); } return new FormatOptions(format); From 6af6db4cdfbc1adf69f5eb8e668fdf5f8b089766 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 30 Dec 2015 12:52:31 +0100 Subject: [PATCH 4/4] Add more info on BigQuery load's source file --- gcloud-java-examples/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gcloud-java-examples/README.md b/gcloud-java-examples/README.md index 0f66fe523e26..031d18fc0c19 100644 --- a/gcloud-java-examples/README.md +++ b/gcloud-java-examples/README.md @@ -41,7 +41,17 @@ To run examples from your command line: Here's an example run of `BigQueryExample`. - Before running the example, go to the [Google Developers Console][developers-console] to ensure that BigQuery API is enabled. + Before running the example, go to the [Google Developers Console][developers-console] to ensure + that BigQuery API is enabled. You can upload a CSV file `my_csv_file` to the `my_bucket` bucket + (replace `my_csv_file` and `my_bucket` with actual file and bucket names) using the GCS + [web browser](https://console.developers.google.com/storage/browser). The CSV file will be used to + load data into a BigQuery table and should look something like: + ```csv + value1 + value2 + value3 + ``` + Then you are ready to run the following example: ``` $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create dataset new_dataset_id" $mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.BigQueryExample" -Dexec.args="create table new_dataset_id new_table_id field_name:string"