Skip to content

Commit

Permalink
Clean up snippets for BatchClient and Spanner (googleapis#3684)
Browse files Browse the repository at this point in the history
* Clean up snippets for BatchClient and Spanner

* Remove trivial batch_client_read_with_id snippet
  • Loading branch information
nithinsujir authored and pongad committed Sep 18, 2018
1 parent 3fa1fa0 commit fbf8715
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 43 deletions.
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

0 comments on commit fbf8715

Please sign in to comment.