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

BigQuery: Standardizes region tags and adds query snippets from java-docs-samples #3180

Merged
merged 11 commits into from
Apr 24, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ public int hashCode() {
*
* <p>Example of listing datasets, specifying the page size.
* <pre> {@code
* // List datasets in the default project
* Page<Dataset> datasets = bigquery.listDatasets(DatasetListOption.pageSize(100));
* for (Dataset dataset : datasets.iterateAll()) {
* // do something with the dataset
Expand All @@ -653,6 +654,7 @@ public int hashCode() {
* <p>Example of listing datasets in a project, specifying the page size.
* <pre> {@code
* String projectId = "my_project_id";
* // List datasets in a specified project
* Page<Dataset> datasets = bigquery.listDatasets(projectId, DatasetListOption.pageSize(100));
* for (Dataset dataset : datasets.iterateAll()) {
* // do something with the dataset
Expand Down Expand Up @@ -748,12 +750,12 @@ public int hashCode() {
/**
* Updates dataset information.
*
* <p>Example of updating a dataset by changing its friendly name.
* <p>Example of updating a dataset by changing its description.
* <pre> {@code
* String datasetName = "my_dataset_name";
* String newFriendlyName = "some_new_friendly_name";
* String newDescription = "some_new_description";
* Dataset oldDataset = bigquery.getDataset(datasetName);
* DatasetInfo datasetInfo = oldDataset.toBuilder().setFriendlyName(newFriendlyName).build();
* DatasetInfo datasetInfo = oldDataset.toBuilder().setDescription(newDescription).build();
* Dataset newDataset = bigquery.update(datasetInfo);
* }</pre>
*
Expand All @@ -764,13 +766,13 @@ public int hashCode() {
/**
* Updates table information.
*
* <p>Example of updating a table by changing its friendly name.
* <p>Example of updating a table by changing its description.
* <pre> {@code
* String datasetName = "my_dataset_name";
* String tableName = "my_table_name";
* String newFriendlyName = "new_friendly_name";
* String newDescription = "new_description";
* Table oldTable = bigquery.getTable(datasetName, tableName);
* TableInfo tableInfo = oldTable.toBuilder().setFriendlyName(newFriendlyName).build();
* TableInfo tableInfo = oldTable.toBuilder().setDescription(newDescription).build();
* Table newTable = bigquery.update(tableInfo);
* }</pre>
*
Expand Down Expand Up @@ -974,8 +976,7 @@ TableResult listTableData(
* or "EU", {@link #getJob(JobId, JobOption...)} must be used instead.
*
* <p>Example of getting a job.
*
* <pre>{@code
* <pre> {@code
* String jobName = "my_job_name";
* Job job = bigquery.getJob(jobName);
* if (job == null) {
Expand All @@ -992,8 +993,7 @@ TableResult listTableData(
* or "EU", the {@code jobId} must specify the job location.
*
* <p>Example of getting a job.
*
* <pre>{@code
* <pre> {@code
* String jobName = "my_job_name";
* JobId jobIdObject = JobId.of(jobName);
* Job job = bigquery.getJob(jobIdObject);
Expand Down Expand Up @@ -1029,8 +1029,7 @@ TableResult listTableData(
* <p>If the location of the job is not "US" or "EU", {@link #cancel(JobId)} must be used instead.
*
* <p>Example of cancelling a job.
*
* <pre>{@code
* <pre> {@code
* String jobName = "my_job_name";
* boolean success = bigquery.cancel(jobName);
* if (success) {
Expand All @@ -1055,8 +1054,7 @@ TableResult listTableData(
* location.
*
* <p>Example of cancelling a job.
*
* <pre>{@code
* <pre> {@code
* String jobName = "my_job_name";
* JobId jobId = JobId.of(jobName);
* boolean success = bigquery.cancel(jobId);
Expand All @@ -1083,26 +1081,19 @@ TableResult listTableData(
* queries. Since dry-run queries are not actually executed, there's no way to retrieve results.
*
* <p>Example of running a query.
*
* <pre>{@code
* String query = "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]";
* <pre> {@code
* // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
* String query =
* "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
* QueryJobConfiguration queryConfig =
* QueryJobConfiguration.newBuilder(query).setUseLegacySql(true).build();
* QueryJobConfiguration.newBuilder(query).build();
*
* // Print the results.
* for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
* // do something with the data
* }
* }</pre>
*
* <p>Example of running a query with query parameters.
*
* <pre>{@code
* String query = "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > @wordCount";
* // Note, standard SQL is required to use query parameters. Legacy SQL will not work.
* QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query)
* .addNamedParameter("wordCount", QueryParameterValue.int64(5))
* .build();
* for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
* // do something with the data
* for (FieldValue val : row) {
* System.out.printf("%s,", val.toString());
* }
* System.out.printf("\n");
* }
* }</pre>
*
Expand Down Expand Up @@ -1148,8 +1139,7 @@ TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption...
* not in "US" or "EU", {@link #writer(JobId, WriteChannelConfiguration)} must be used instead.
*
* <p>Example of creating a channel with which to write to a table.
*
* <pre>{@code
* <pre> {@code
* String datasetName = "my_dataset_name";
* String tableName = "my_table_name";
* String csvData = "StringValue1\nStringValue2\n";
Expand All @@ -1159,31 +1149,33 @@ TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption...
* .setFormatOptions(FormatOptions.csv())
* .build();
* TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
* // Write data to writer
* try {
* writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
* } finally {
* writer.close();
* }
* // Get load job
* Job job = writer.getJob();
* job = job.waitFor();
* LoadStatistics stats = job.getStatistics();
* return stats.getOutputRows();
* // Write data to writer
* try {
* writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
* } finally {
* writer.close();
* }
* // Get load job
* Job job = writer.getJob();
* job = job.waitFor();
* LoadStatistics stats = job.getStatistics();
* return stats.getOutputRows();
* }</pre>
*
* <p>Example of writing a local file to a table.
*
* <pre>{@code
* <pre> {@code
* String datasetName = "my_dataset_name";
* String tableName = "my_table_name";
* Path csvPath = FileSystems.getDefault().getPath(".", "my-data.csv");
* String location = "us";
* TableId tableId = TableId.of(datasetName, tableName);
* WriteChannelConfiguration writeChannelConfiguration =
* WriteChannelConfiguration.newBuilder(tableId)
* .setFormatOptions(FormatOptions.csv())
* .build();
* TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
* // The location must be specified; other fields can be auto-detected.
* JobId jobId = JobId.newBuilder().setLocation(location).build();
* TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
* // Write data to writer
* try (OutputStream stream = Channels.newOutputStream(writer)) {
* Files.copy(csvPath, stream);
Expand All @@ -1205,13 +1197,11 @@ TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption...
* not in "US" or "EU", the {@code jobId} must contain the location of the job.
*
* <p>Example of creating a channel with which to write to a table.
*
* <pre>{@code
* <pre> {@code
* String datasetName = "my_dataset_name";
* String tableName = "my_table_name";
* String csvData = "StringValue1\nStringValue2\n";
* String csvData = "StringValue1\nStringValue2\n";
* String location = "asia-northeast1";
* String location = "us";
* TableId tableId = TableId.of(datasetName, tableName);
* WriteChannelConfiguration writeChannelConfiguration =
* WriteChannelConfiguration.newBuilder(tableId).setFormatOptions(FormatOptions.csv()).build();
Expand All @@ -1230,6 +1220,7 @@ TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption...
* LoadStatistics stats = job.getStatistics();
* return stats.getOutputRows();
* }</pre>
*
*/
TableDataWriteChannel writer(JobId jobId, WriteChannelConfiguration writeChannelConfiguration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ public boolean delete(DatasetDeleteOption... options) {
* <p>Example of listing tables in the dataset.
* <pre> {@code
* Page<Table> tables = dataset.list();
* Iterator<Table> tableIterator = tables.iterateAll();
* while (tableIterator.hasNext()) {
* Table table = tableIterator.next();
* for (Table table : tables.iterateAll()) {
* // do something with the table
* }
* }</pre>
Expand Down Expand Up @@ -278,7 +276,7 @@ public Table get(String tableId, TableOption... options) {
* <pre> {@code
* String tableName = “my_table”;
* String fieldName = “my_field”;
* Schema schema = Schema.of(Field.of(fieldName, Type.string()));
* Schema schema = Schema.of(Field.of(fieldName, LegacySQLTypeName.STRING));
* StandardTableDefinition definition = StandardTableDefinition.newBuilder()
* .setSchema(schema)
* .setTimePartitioning(TimePartitioning.of(TimePartitioning.Type.DAY))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ public Job build() {
* Checks if this job exists.
*
* <p>Example of checking that a job exists.
*
* <pre>{@code
* <pre> {@code
* if (!job.exists()) {
* // job doesn't exist
* }
Expand All @@ -174,8 +173,7 @@ public boolean exists() {
* not exist this method returns {@code true}.
*
* <p>Example of waiting for a job until it reports that it is done.
*
* <pre>{@code
* <pre> {@code
* while (!job.isDone()) {
* Thread.sleep(1000L);
* }
Expand All @@ -198,8 +196,7 @@ public boolean isDone() {
* 12 hours as a total timeout and unlimited number of attempts.
*
* <p>Example usage of {@code waitFor()}.
*
* <pre>{@code
* <pre> {@code
* Job completedJob = job.waitFor();
* if (completedJob == null) {
* // job no longer exists
Expand All @@ -210,14 +207,12 @@ public boolean isDone() {
* }
* }</pre>
*
* <p>Example usage of {@code waitFor()} with non-jittered custom max delay and total timeout.
*
* <pre>{@code
* <p>Example usage of {@code waitFor()} with checking period and timeout.
* <pre> {@code
* Job completedJob =
* job.waitFor(
* RetryOption.maxRetryDelay(Duration.ofSeconds(30)),
* RetryOption.totalTimeout(Duration.ofMinutes(1)),
* RetryOption.jittered(false));
* RetryOption.initialRetryDelay(Duration.ofSeconds(1)),
* RetryOption.totalTimeout(Duration.ofMinutes(1)));
* if (completedJob == null) {
* // job no longer exists
* } else if (completedJob.getStatus().getError() != null) {
Expand Down Expand Up @@ -257,16 +252,6 @@ public Job waitFor(RetryOption... waitOptions) throws InterruptedException {
* the current {@code Job} instance is not updated. To get the new state, call {@link
* #waitFor(RetryOption...)} or {@link #reload(JobOption...)}.
*
* <p>Example of getting the results of a query job.
*
* <pre>{@code
* Job job = bigquery.create(queryJobInfo);
* TableResult result = job.getQueryResults();
* for (FieldValueList row : result.iterateAll()) {
* // do something with the data
* }
* }</pre>
*
* @throws BigQueryException upon failure
*/
public TableResult getQueryResults(QueryResultsOption... options)
Expand Down Expand Up @@ -371,17 +356,15 @@ public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) {
* Fetches current job's latest information. Returns {@code null} if the job does not exist.
*
* <p>Example of reloading all fields until job status is DONE.
*
* <pre>{@code
* <pre> {@code
* while (job.getStatus().getState() != JobStatus.State.DONE) {
* Thread.sleep(1000L);
* job = job.reload();
* }
* }</pre>
*
* <p>Example of reloading status field until job status is DONE.
*
* <pre>{@code
* <pre> {@code
* while (job.getStatus().getState() != JobStatus.State.DONE) {
* Thread.sleep(1000L);
* job = job.reload(BigQuery.JobOption.fields(BigQuery.JobField.STATUS));
Expand All @@ -401,8 +384,7 @@ public Job reload(JobOption... options) {
* Sends a job cancel request.
*
* <p>Example of cancelling a job.
*
* <pre>{@code
* <pre> {@code
* if (job.cancel()) {
* return true; // job successfully cancelled
* } else {
Expand Down
Loading