Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update samples README.md #667

Merged
merged 3 commits into from Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions samples/README.md
Expand Up @@ -2,16 +2,26 @@

## Running a sample using Cloud Shell

The Google Cloud Shell has application default credentials from its compute instance which will allow you to run an integration test without having to obtain `GOOGLE_APPLICATION_CREDENTIANS`.
The Google Cloud Shell has application default credentials from its compute instance which will allow you to run an integration test without having to obtain `GOOGLE_APPLICATION_CREDENTIANS`. Go to [BigQuery Client Readme](https://github.com/googleapis/java-bigquery#samples) to run each sample in the Cloud Shell.
stephaniewang526 marked this conversation as resolved.
Show resolved Hide resolved

However, certain samples require environment variables to be set. For instance, in `CreateDatasetIT.java`:
## Running a sample using command line

First set up `GOOGLE_APPLICATION_CREDENTIANS` and `GOOGLE_CLOUD_PROJECT` environment variables before running any samples.
stephaniewang526 marked this conversation as resolved.
Show resolved Hide resolved

To run a sample:
1. `cd samples/snippets` - all samples are located in `java-bigquery/samples/snippets` directory.
2. `mvn compile exec:java -Dexec.mainClass=com.example.bigquery.SimpleQuery` - this runs the [SimpleQuery sample](https://github.com/googleapis/java-bigquery/blob/master/samples/snippets/src/main/java/com/example/bigquery/SimpleQuery.java) which runs the BigQuery query method. You can update the developer's `TODO` section in the snippet if you wish to run a different query.
3. `mvn compile exec:java -Dexec.mainClass=com.example.bigquery.SimpleQuery -Dexec.args="'SELECT word_count FROM bigquery-public-data.samples.shakespeare GROUP BY word_count;'"` - this will run the [SimpleQuery sample](https://github.com/googleapis/java-bigquery/blob/master/samples/snippets/src/main/java/com/example/bigquery/SimpleQuery.java) with your command line arguments.

## Running a sample integration test using command line

Note that some samples require environment variables to be set. For instance, in `CreateDatasetIT.java`:

`private static final String GOOGLE_CLOUD_PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT");` - this sample integration test requires you to specific the [Google Cloud Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects) you would like to run the test in.

Make sure to set environment variables, if necessary, before running the sample, or else you will get an error asking you to set it.

To run a samples integration tests in the cloud shell, simply run the following commands:

`cd samples/snippets` - all samples are located in `java-bigquery/samples/snippets` directory.
To run a samples integration tests:

`mvn -Dtest=GetTableIT test` - this runs the integration test of `GetTable.java` sample.
1. `cd samples/snippets` - all samples are located in `java-bigquery/samples/snippets` directory.
2. `mvn -Dtest=GetTableIT test` - this runs the integration test of `GetTable.java` sample.
Expand Up @@ -26,9 +26,15 @@
public class SimpleQuery {

public static void main(String[] args) {
// TODO(developer): Replace this query before running the sample.
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
simpleQuery(query);
if (args.length == 0) {
// no command-line args passed
// TODO(developer): Replace this query before running the sample.
String query = "SELECT corpus FROM bigquery-public-data.samples.shakespeare GROUP BY corpus;";
simpleQuery(query);
} else {
// use command-line args
simpleQuery(args[0]);
}
}
stephaniewang526 marked this conversation as resolved.
Show resolved Hide resolved

public static void simpleQuery(String query) {
Expand Down