Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8defc9c
feat: add QueryOptions to Spanner samples
olavloite Mar 5, 2020
706b5dc
fix: review comments + dependencies
olavloite Mar 15, 2020
611dae9
chore(deps): update dependency io.ktor:ktor-bom to v1.3.2 (#2382)
renovate-bot Mar 19, 2020
a4412b7
Correct path to task queues sample. (#2444)
dzlier-gcp Mar 19, 2020
29294d0
chore(deps): update dependency com.amazonaws:aws-java-sdk-s3 to v1.11…
renovate-bot Mar 19, 2020
4f55144
Correct error message for unset GOOGLE_CLOUD_PROJECT. (#2448)
dzlier-gcp Mar 19, 2020
df9e9cc
chore(deps): update dependency com.google.apis:google-api-services-st…
renovate-bot Mar 19, 2020
9352d2c
deps: upgrade to spanner 1.52
olavloite Mar 20, 2020
7464e85
Maven GAE plugin config updates (#2442)
averikitsch Mar 20, 2020
29f3c4d
Update Maven config GAE 11 (#2441)
averikitsch Mar 20, 2020
4ae9e6c
chore(deps): update dependency com.google.cloud:google-cloud-spanner …
renovate-bot Mar 20, 2020
93f282f
chore(deps): update dependency com.google.cloud:google-cloud-bigquery…
renovate-bot Mar 20, 2020
7098d52
chore(deps): update appengine packages to v1.9.79 (#2453)
renovate-bot Mar 20, 2020
3b9e37b
chore(deps): update dependency com.amazonaws:aws-java-sdk-s3 to v1.11…
renovate-bot Mar 20, 2020
f482c4d
Fix Flaky DLP tests (#2447)
shubha-rajan Mar 20, 2020
e3ee897
GCF: Add Slack sample + clean up imports (#2394)
Mar 21, 2020
c29d879
functions/logging: add stdout/stderr + ignored logs severity note (#2…
Mar 21, 2020
9696181
Merge branch 'master' into spanner-query-options
skuruppu Mar 24, 2020
4e60e83
Merge branch 'master' into spanner-query-options
skuruppu Mar 24, 2020
236a83c
Merge branch 'master' into spanner-query-options
skuruppu Mar 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions spanner/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ limitations under the License.
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<opencensus.version>0.26.0</opencensus.version>
<spanner.version>1.52.0</spanner.version>
</properties>

<!-- Include the BOM to ensure compatibility across multiple google-cloud-* libraries -->
Expand All @@ -42,7 +43,7 @@ limitations under the License.
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bom</artifactId>
<version>0.84.0-alpha</version>
<version>0.122.4-alpha</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -51,34 +52,26 @@ limitations under the License.
<!-- End of BOM -->
<dependencies>
<dependency>
<!-- Version auto-managed by BOM -->
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava-jdk5</artifactId>
</exclusion>
<exclusion>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</exclusion>
</exclusions>
<version>${spanner.version}</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-instance-v1</artifactId>
<version>${spanner.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-v1</artifactId>
<version>${spanner.version}</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-database-v1</artifactId>
<version>${spanner.version}</version>
</dependency>

<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.google.common.io.BaseEncoding;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -1433,6 +1434,45 @@ static void queryWithTimestampParameter(DatabaseClient dbClient) {
}
// [END spanner_query_with_timestamp_parameter]

// [START spanner_create_client_with_query_options]
static void clientWithQueryOptions(DatabaseId db) {
SpannerOptions options =
SpannerOptions.newBuilder()
.setDefaultQueryOptions(
db, QueryOptions.newBuilder().setOptimizerVersion("1").build())
.build();
Spanner spanner = options.getService();
DatabaseClient dbClient = spanner.getDatabaseClient(db);
try (ResultSet resultSet =
dbClient
.singleUse()
.executeQuery(Statement.of("SELECT SingerId, AlbumId, AlbumTitle FROM Albums"))) {
while (resultSet.next()) {
System.out.printf(
"%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
}
}
}
// [END spanner_create_client_with_query_options]

// [START spanner_query_with_query_options]
static void queryWithQueryOptions(DatabaseClient dbClient) {
try (ResultSet resultSet =
dbClient
.singleUse()
.executeQuery(
Statement
.newBuilder("SELECT SingerId, AlbumId, AlbumTitle FROM Albums")
.withQueryOptions(QueryOptions.newBuilder().setOptimizerVersion("1").build())
.build())) {
while (resultSet.next()) {
System.out.printf(
"%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
}
}
}
// [END spanner_query_with_query_options]

static void run(
DatabaseClient dbClient,
DatabaseAdminClient dbAdminClient,
Expand Down Expand Up @@ -1589,6 +1629,12 @@ static void run(
case "querywithtimestampparameter":
queryWithTimestampParameter(dbClient);
break;
case "clientwithqueryoptions":
clientWithQueryOptions(database);
break;
case "querywithqueryoptions":
queryWithQueryOptions(dbClient);
break;
default:
printUsageAndExit();
}
Expand Down Expand Up @@ -1649,6 +1695,8 @@ static void printUsageAndExit() {
System.err.println(" SpannerExample querywithint my-instance example-db");
System.err.println(" SpannerExample querywithstring my-instance example-db");
System.err.println(" SpannerExample querywithtimestampparameter my-instance example-db");
System.err.println(" SpannerExample clientwithqueryoptions my-instance example-db");
System.err.println(" SpannerExample querywithqueryoptions my-instance example-db");
System.exit(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void testSample() throws Exception {

out = runSample("querywithbytes");
assertThat(out).contains("4 Venue 4");

out = runSample("querywithdate");
assertThat(out).contains("4 Venue 4 2018-09-02");
assertThat(out).contains("42 Venue 42 2018-10-01");
Expand All @@ -236,6 +236,11 @@ public void testSample() throws Exception {
assertThat(out).contains("4 Venue 4");
assertThat(out).contains("19 Venue 19");
assertThat(out).contains("42 Venue 42");

out = runSample("clientwithqueryoptions");
assertThat(out).contains("1 1 Total Junk");
out = runSample("querywithqueryoptions");
assertThat(out).contains("1 1 Total Junk");
}

private String formatForTest(String name) {
Expand Down