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

Clean up snippets for BatchClient and Spanner #3684

Merged
merged 2 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ public interface BatchClient {
* @param batchTransactionId to re-initialize the transaction, re-using the timestamp for
* successive read/query.
*
* <!--SNIPPET batch_client_read_with_id-->
* <pre>{@code
* BatchTransactionId txnId = my_txn.getBatchTransactionId();
* BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
* }</pre>
* <!--SNIPPET batch_client_read_with_id-->
*/
BatchReadOnlyTransaction batchReadOnlyTransaction(BatchTransactionId batchTransactionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface BatchReadOnlyTransaction extends ReadOnlyTransaction {
* long singerId = results.getLong(0);
* String firstName = results.getString(1);
* String lastName = results.getString(2);
* System.out.println("P2 [" + singerId + "] " + firstName + " " + lastName);
* System.out.println("[" + singerId + "] " + firstName + " " + lastName);
* }
* }
* }
Expand Down Expand Up @@ -110,14 +110,15 @@ List<Partition> partitionRead(
* "Singers",
* "SingerId",
* KeySet.all(),
* Arrays.asList("FirstName"));
* BatchTransactionId txnID = txn.getBatchTransactionId();
* int numRowsRead = 0;
* Arrays.asList("SingerId", "FirstName", "LastName"));
*
* for (Partition p : partitions) {
* BatchReadOnlyTransaction batchTxnOnEachWorker = batchClient.batchReadOnlyTransaction(txnID);
* try (ResultSet results = batchTxnOnEachWorker.execute(p)) {
* try (ResultSet results = txn.execute(p)) {
* while (results.next()) {
* System.out.println(results.getString(0));
* long singerId = results.getLong(0);
* String firstName = results.getString(1);
* String lastName = results.getString(2);
* System.out.println("[" + singerId + "] " + firstName + " " + lastName);
* }
* }
* }
Expand Down Expand Up @@ -198,13 +199,6 @@ List<Partition> partitionQuery(
* Returns a {@link BatchTransactionId} to be re-used across several machines/processes. This
* BatchTransactionId guarantees the subsequent read/query to be executed at the same timestamp.
*
* <!--SNIPPET batch_client_read_with_id-->
* <pre>{@code
* BatchTransactionId txnId = my_txn.getBatchTransactionId();
* BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
* }</pre>
* <!--SNIPPET batch_client_read_with_id-->
*
*/
BatchTransactionId getBatchTransactionId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface Spanner extends Service<SpannerOptions> {
* final String instance = "test-instance";
* final String database = "example-db";
* DatabaseId db =
* DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
* DatabaseId.of(project, instance, database);
* DatabaseClient dbClient = spanner.getDatabaseClient(db);
* }</pre>
* <!--SNIPPET get_db_client-->
Expand All @@ -85,7 +85,7 @@ public interface Spanner extends Service<SpannerOptions> {
* final String instance = "test-instance";
* final String database = "example-db";
* DatabaseId db =
* DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
* DatabaseId.of(project, instance, database);
* BatchClient batchClient = spanner.getBatchClient(db);
* }</pre>
* <!--SNIPPET get_batch_client-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ BatchReadOnlyTransaction readStrong() {
return txn;
}

/**
* Example to do a batch read with txn id.
*/
BatchReadOnlyTransaction readWithId(BatchReadOnlyTransaction my_txn) {
// [START batch_client_read_with_id]
BatchTransactionId txnId = my_txn.getBatchTransactionId();
BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
// [END batch_client_read_with_id]

return txn;
}

void partitionQuery() {
// [START partition_query]
final BatchReadOnlyTransaction txn =
Expand Down Expand Up @@ -104,7 +92,7 @@ void partitionRead() {
long singerId = results.getLong(0);
String firstName = results.getString(1);
String lastName = results.getString(2);
System.out.println("P2 [" + singerId + "] " + firstName + " " + lastName);
System.out.println("[" + singerId + "] " + firstName + " " + lastName);
}
}
}
Expand All @@ -121,14 +109,15 @@ void partitionReadUsingIndex() {
"Singers",
"SingerId",
KeySet.all(),
Arrays.asList("FirstName"));
BatchTransactionId txnID = txn.getBatchTransactionId();
int numRowsRead = 0;
Arrays.asList("SingerId", "FirstName", "LastName"));

for (Partition p : partitions) {
BatchReadOnlyTransaction batchTxnOnEachWorker = batchClient.batchReadOnlyTransaction(txnID);
try (ResultSet results = batchTxnOnEachWorker.execute(p)) {
try (ResultSet results = txn.execute(p)) {
while (results.next()) {
System.out.println(results.getString(0));
long singerId = results.getLong(0);
String firstName = results.getString(1);
String lastName = results.getString(2);
System.out.println("[" + singerId + "] " + firstName + " " + lastName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ DatabaseClient getDatabaseClient() {
final String instance = "test-instance";
final String database = "example-db";
DatabaseId db =
DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
DatabaseId.of(project, instance, database);
DatabaseClient dbClient = spanner.getDatabaseClient(db);
// [END get_db_client]

Expand All @@ -78,7 +78,7 @@ BatchClient getBatchClient() {
final String instance = "test-instance";
final String database = "example-db";
DatabaseId db =
DatabaseId.of("span-cloud-testing", "nsujir-ins", "example-db");
DatabaseId.of(project, instance, database);
BatchClient batchClient = spanner.getBatchClient(db);
// [END get_batch_client]

Expand Down