Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into materialize-view-…
Browse files Browse the repository at this point in the history
…definition
  • Loading branch information
Praful Makani committed Feb 18, 2020
2 parents 3e99712 + 5212b2f commit 29f154d
Show file tree
Hide file tree
Showing 15 changed files with 527 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/trusted-contribution.yml
@@ -0,0 +1,2 @@
trustedContributors:
- renovate-bot
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -52,7 +52,7 @@ libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "1.106.0"

Example Application
-------------------
- [`BigQueryExample`](../../google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality.
- [`BigQueryExample`](https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/BigQueryExample.java) - A simple command line interface providing some of Cloud BigQuery's functionality.
Read more about using this application on the [`BigQueryExample` docs page](https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/examples/bigquery/BigQueryExample.html).

Authentication
Expand Down Expand Up @@ -205,7 +205,7 @@ for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
#### Complete source code

In
[InsertDataAndQueryTable.java](../../google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/InsertDataAndQueryTable.java)
[InsertDataAndQueryTable.java](https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/InsertDataAndQueryTable.java)
we put together all the code shown above into one program. The program assumes that you are
running on Compute Engine or from your own desktop. To run the example on App Engine, simply move
the code from the main method to your application's servlet class and change the print statements to
Expand Down
Expand Up @@ -163,6 +163,7 @@ static QueryStep fromPb(com.google.api.services.bigquery.model.ExplainQueryStep
private final long writeMsMax;
private final double writeRatioAvg;
private final double writeRatioMax;
private final long slotMs;

static final class Builder {

Expand Down Expand Up @@ -195,6 +196,7 @@ static final class Builder {
private long writeMsMax;
private double writeRatioAvg;
private double writeRatioMax;
private long slotMs;

private Builder() {}

Expand Down Expand Up @@ -343,6 +345,11 @@ Builder setWriteRatioMax(double writeRatioMax) {
return this;
}

Builder setSlotMs(long slotMs) {
this.slotMs = slotMs;
return this;
}

QueryStage build() {
return new QueryStage(this);
}
Expand Down Expand Up @@ -378,6 +385,7 @@ QueryStage build() {
writeMsMax = builder.writeMsMax;
writeRatioAvg = builder.writeRatioAvg;
writeRatioMax = builder.writeRatioMax;
slotMs = builder.slotMs;
}

/** Returns the number of parallel input segments completed. */
Expand Down Expand Up @@ -551,6 +559,11 @@ public double getWriteRatioMax() {
return writeRatioMax;
}

/** Returns the slot-milliseconds used by the stage. */
public long getSlotMs() {
return slotMs;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down Expand Up @@ -583,6 +596,7 @@ public String toString() {
.add("writeMsMax", writeMsMax)
.add("writeRatioAvg", writeRatioAvg)
.add("writeRatioMax", writeRatioMax)
.add("slotMs", slotMs)
.toString();
}

Expand Down Expand Up @@ -617,7 +631,8 @@ public final int hashCode() {
writeMsAvg,
writeMsMax,
writeRatioAvg,
writeRatioMax);
writeRatioMax,
slotMs);
}

@Override
Expand Down Expand Up @@ -657,7 +672,8 @@ public final boolean equals(Object obj) {
&& Objects.equals(steps, other.steps)
&& Objects.equals(name, other.name)
&& Objects.equals(status, other.status)
&& Objects.equals(inputStages, other.inputStages);
&& Objects.equals(inputStages, other.inputStages)
&& Objects.equals(slotMs, other.slotMs);
}

static Builder newBuilder() {
Expand Down Expand Up @@ -694,7 +710,8 @@ ExplainQueryStage toPb() {
.setWriteMsAvg(writeMsAvg)
.setWriteMsMax(writeMsMax)
.setWriteRatioAvg(writeRatioAvg)
.setWriteRatioMax(writeRatioMax);
.setWriteRatioMax(writeRatioMax)
.setSlotMs(slotMs);
if (steps != null) {
stagePb.setSteps(Lists.transform(steps, QueryStep.TO_PB_FUNCTION));
}
Expand Down Expand Up @@ -734,6 +751,7 @@ static QueryStage fromPb(com.google.api.services.bigquery.model.ExplainQueryStag
builder.setWriteMsMax(stagePb.getWriteMsMax());
builder.setWriteRatioAvg(stagePb.getWriteRatioAvg());
builder.setWriteRatioMax(stagePb.getWriteRatioMax());
builder.setSlotMs(stagePb.getSlotMs());
return builder.build();
}
}
Expand Up @@ -59,6 +59,7 @@ public class QueryStageTest {
private static final long WRITE_MS_MAX = 50;
private static final double WRITE_RATIO_AVG = 9.9;
private static final double WRITE_RATIO_MAX = 10.10;
private static final long SLOTMS = 1522540800000L;
private static final QueryStage QUERY_STAGE =
QueryStage.newBuilder()
.setCompletedParallelInputs(COMPLETED_PARALLEL_INPUTS)
Expand Down Expand Up @@ -90,6 +91,7 @@ public class QueryStageTest {
.setWriteMsMax(WRITE_MS_MAX)
.setWriteRatioAvg(WRITE_RATIO_AVG)
.setWriteRatioMax(WRITE_RATIO_MAX)
.setSlotMs(SLOTMS)
.build();

@Test
Expand All @@ -112,6 +114,8 @@ public void testBuilder() {
assertEquals(INPUT_STAGES, QUERY_STAGE.getInputStages());
assertEquals(PARALLEL_INPUTS, QUERY_STAGE.getParallelInputs());
assertEquals(NAME, QUERY_STAGE.getName());
assertEquals(READ_MS_AVG, QUERY_STAGE.getReadMsAvg());
assertEquals(READ_MS_MAX, QUERY_STAGE.getReadMsMax());
assertEquals(READ_RATIO_AVG, QUERY_STAGE.getReadRatioAvg(), 0);
assertEquals(READ_RATIO_MAX, QUERY_STAGE.getReadRatioMax(), 0);
assertEquals(RECORDS_READ, QUERY_STAGE.getRecordsRead());
Expand All @@ -129,6 +133,7 @@ public void testBuilder() {
assertEquals(WRITE_MS_MAX, QUERY_STAGE.getWriteMsMax());
assertEquals(WRITE_RATIO_AVG, QUERY_STAGE.getWriteRatioAvg(), 0);
assertEquals(WRITE_RATIO_MAX, QUERY_STAGE.getWriteRatioMax(), 0);
assertEquals(SLOTMS, QUERY_STAGE.getSlotMs());
}

@Test
Expand Down Expand Up @@ -178,7 +183,9 @@ private void compareQueryStage(QueryStage expected, QueryStage value) {
assertEquals(expected.getWriteMsMax(), expected.getWriteMsMax());
assertEquals(expected.getWriteRatioAvg(), value.getWriteRatioAvg(), 0);
assertEquals(expected.getWriteRatioMax(), value.getWriteRatioMax(), 0);
assertEquals(expected.getSlotMs(), value.getSlotMs());
assertEquals(expected.hashCode(), value.hashCode());
assertEquals(expected.toString(), value.toString());
}

private void compareQueryStep(QueryStep expected, QueryStep value) {
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Expand Up @@ -63,18 +63,18 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<github.global.server>github</github.global.server>
<site.installationModule>google-cloud-bigquery-parent</site.installationModule>
<google.core.version>1.92.4</google.core.version>
<google.core.version>1.92.5</google.core.version>
<google.api-common.version>1.8.1</google.api-common.version>
<google.common-protos.version>1.17.0</google.common-protos.version>
<gax.version>1.53.1</gax.version>
<grpc.version>1.27.0</grpc.version>
<protobuf.version>3.11.3</protobuf.version>
<grpc.version>1.27.1</grpc.version>
<protobuf.version>3.11.4</protobuf.version>
<junit.version>4.13</junit.version>
<guava.version>28.2-android</guava.version>
<threeten.version>1.4.1</threeten.version>
<javax.annotations.version>1.3.2</javax.annotations.version>
<animal-sniffer.version>1.18</animal-sniffer.version>
<google-api-services-bigquery.version>v2-rev20191211-1.30.3
<google-api-services-bigquery.version>v2-rev20191211-1.30.8
</google-api-services-bigquery.version>
</properties>

Expand All @@ -88,12 +88,12 @@
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>1.34.1</version>
<version>1.34.2</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.34.1</version>
<version>1.34.2</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
Expand Down
4 changes: 2 additions & 2 deletions samples/pom.xml
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>3.5.0</version>
<version>4.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -64,7 +64,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<version>1.92.4</version>
<version>1.92.5</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
Expand Down
50 changes: 50 additions & 0 deletions samples/src/main/java/com/example/bigquery/GetTable.java
@@ -0,0 +1,50 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.bigquery;

// [START bigquery_get_table]
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.Table;
import com.google.cloud.bigquery.TableId;

public class GetTable {

public static void runGetTable() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "bigquery_public_data";
String datasetName = "samples";
String tableName = "shakespeare";
getTable(projectId, datasetName, tableName);
}

public static void getTable(String projectId, String datasetName, String tableName) {
try {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests.
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

TableId tableId = TableId.of(projectId, datasetName, tableName);
Table table = bigquery.getTable(tableId);
System.out.println("Table info: " + table.getDescription());
} catch (BigQueryException e) {
System.out.println("Table not retrieved. \n" + e.toString());
}
}
}
// [END bigquery_get_table]
53 changes: 53 additions & 0 deletions samples/src/main/java/com/example/bigquery/ListTables.java
@@ -0,0 +1,53 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.bigquery;

// [START bigquery_list_tables]
import com.google.api.gax.paging.Page;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQuery.TableListOption;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.DatasetId;
import com.google.cloud.bigquery.Table;

public class ListTables {

public static void runListTables() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "bigquery-public-data";
String datasetName = "samples";
listTables(projectId, datasetName);
}

public static void listTables(String projectId, String datasetName) {
try {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests.
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

DatasetId datasetId = DatasetId.of(projectId, datasetName);
Page<Table> tables = bigquery.listTables(datasetId, TableListOption.pageSize(100));
tables.iterateAll().forEach(table -> System.out.print(table.getTableId().getTable() + "\n"));

System.out.println("Tables listed successfully.");
} catch (BigQueryException e) {
System.out.println("Tables were not listed. Error occurred: " + e.toString());
}
}
}
// [END bigquery_list_tables]

0 comments on commit 29f154d

Please sign in to comment.