Skip to content

Commit 0b23332

Browse files
authored
Merge branch 'master' into cloud-cdn
2 parents a0df10f + 97a40da commit 0b23332

File tree

9 files changed

+148
-280
lines changed

9 files changed

+148
-280
lines changed

appengine-java8/logs/README.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

appengine-java8/logs/pom.xml

Lines changed: 0 additions & 91 deletions
This file was deleted.

appengine-java8/logs/src/main/java/com/example/appengine/logs/LogsServlet.java

Lines changed: 0 additions & 100 deletions
This file was deleted.

appengine-java8/logs/src/main/webapp/WEB-INF/appengine-web.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

appengine-java8/logs/src/main/webapp/WEB-INF/logging.properties

Lines changed: 0 additions & 14 deletions
This file was deleted.

appengine-java8/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
<module>guestbook-cloud-datastore</module>
5858
<module>guestbook-objectify</module>
5959
<module>images</module>
60-
<module>logs</module>
6160
<module>mailgun</module>
6261
<module>mailjet</module>
6362
<module>memcache</module>

spanner/cloud-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ limitations under the License.
128128
<dependency>
129129
<groupId>com.google.cloud</groupId>
130130
<artifactId>google-cloud-bom</artifactId>
131-
<version>0.34.0-alpha</version>
131+
<version>0.37.0-alpha</version>
132132
<type>pom</type>
133133
<scope>import</scope>
134134
</dependency>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright 2018 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.spanner;
18+
19+
import com.google.cloud.spanner.BatchClient;
20+
import com.google.cloud.spanner.BatchReadOnlyTransaction;
21+
import com.google.cloud.spanner.DatabaseId;
22+
import com.google.cloud.spanner.Partition;
23+
import com.google.cloud.spanner.PartitionOptions;
24+
import com.google.cloud.spanner.ResultSet;
25+
import com.google.cloud.spanner.Spanner;
26+
import com.google.cloud.spanner.SpannerOptions;
27+
import com.google.cloud.spanner.Statement;
28+
import com.google.cloud.spanner.TimestampBound;
29+
30+
import java.util.List;
31+
import java.util.concurrent.ExecutorService;
32+
import java.util.concurrent.Executors;
33+
import java.util.concurrent.TimeUnit;
34+
import java.util.concurrent.atomic.AtomicInteger;
35+
36+
/**
37+
* Sample showing how to run a query using the Batch API.
38+
*/
39+
public class BatchSample {
40+
41+
/**
42+
* This example showcases how to create a batch client, partition a query, and concurrently read
43+
* from multiple partitions.
44+
*/
45+
public static void main(String[] args) throws InterruptedException {
46+
if (args.length != 2) {
47+
System.err.println("Usage: BatchSample <instance_id> <database_id>");
48+
return;
49+
}
50+
51+
/*
52+
* CREATE TABLE Singers (
53+
* SingerId INT64 NOT NULL,
54+
* FirstName STRING(1024),
55+
* LastName STRING(1024),
56+
* SingerInfo BYTES(MAX),
57+
* ) PRIMARY KEY (SingerId);
58+
*/
59+
60+
String instanceId = args[0];
61+
String databaseId = args[1];
62+
63+
SpannerOptions options = SpannerOptions.newBuilder().build();
64+
Spanner spanner = options.getService();
65+
66+
// [START spanner_batch_client]
67+
int numThreads = Runtime.getRuntime().availableProcessors();
68+
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
69+
70+
// Statistics
71+
int totalPartitions;
72+
AtomicInteger totalRecords = new AtomicInteger(0);
73+
74+
try {
75+
BatchClient batchClient = spanner.getBatchClient(
76+
DatabaseId.of(options.getProjectId(), instanceId, databaseId));
77+
78+
final BatchReadOnlyTransaction txn =
79+
batchClient.batchReadOnlyTransaction(TimestampBound.strong());
80+
81+
// A Partition object is serializable and can be used from a different process.
82+
List<Partition> partitions = txn.partitionQuery(PartitionOptions.getDefaultInstance(),
83+
Statement.of("SELECT SingerId, FirstName, LastName FROM Singers"));
84+
85+
totalPartitions = partitions.size();
86+
87+
for (final Partition p : partitions) {
88+
executor.execute(() -> {
89+
try (ResultSet results = txn.execute(p)) {
90+
while (results.next()) {
91+
long singerId = results.getLong(0);
92+
String firstName = results.getString(1);
93+
String lastName = results.getString(2);
94+
System.out.println("[" + singerId + "] " + firstName + " " + lastName);
95+
totalRecords.getAndIncrement();
96+
}
97+
}
98+
});
99+
}
100+
} finally {
101+
executor.shutdown();
102+
executor.awaitTermination(1, TimeUnit.HOURS);
103+
spanner.close();
104+
}
105+
106+
double avgRecordsPerPartition = 0.0;
107+
if (totalPartitions != 0) {
108+
avgRecordsPerPartition = (double) totalRecords.get() / totalPartitions;
109+
}
110+
System.out.println("totalPartitions=" + totalPartitions);
111+
System.out.println("totalRecords=" + totalRecords);
112+
System.out.println("avgRecordsPerPartition=" + avgRecordsPerPartition);
113+
// [END spanner_batch_client]
114+
}
115+
}

0 commit comments

Comments
 (0)