@@ -54,6 +54,29 @@ public interface BatchReadOnlyTransaction extends ReadOnlyTransaction {
5454 * @param columns the columns to read
5555 * @param options the options to configure the read, supported values are
5656 * {@link Options#prefetchChunks()}
57+ *
58+ * <!--SNIPPET partition_read-->
59+ * <pre>{@code
60+ * final BatchReadOnlyTransaction txn =
61+ * batchClient.batchReadOnlyTransaction(TimestampBound.strong());
62+ * List<Partition> partitions =
63+ * txn.partitionRead(
64+ * PartitionOptions.getDefaultInstance(),
65+ * "Singers",
66+ * KeySet.all(),
67+ * Arrays.asList("SingerId", "FirstName", "LastName"));
68+ * for (final Partition p : partitions) {
69+ * try (ResultSet results = txn.execute(p)) {
70+ * while (results.next()) {
71+ * long singerId = results.getLong(0);
72+ * String firstName = results.getString(1);
73+ * String lastName = results.getString(2);
74+ * System.out.println("P2 [" + singerId + "] " + firstName + " " + lastName);
75+ * }
76+ * }
77+ * }
78+ * }</pre>
79+ * <!--SNIPPET partition_read-->
5780 */
5881 List <Partition > partitionRead (
5982 PartitionOptions partitionOptions ,
@@ -76,6 +99,30 @@ List<Partition> partitionRead(
7699 * rows are returned in the natural key order of the index.
77100 * @param columns the columns to read
78101 * @param options the options to configure the read
102+ *
103+ * <!--SNIPPET partition_read_using_index-->
104+ * <pre>{@code
105+ * final BatchReadOnlyTransaction txn =
106+ * batchClient.batchReadOnlyTransaction(TimestampBound.strong());
107+ * List<Partition> partitions =
108+ * txn.partitionReadUsingIndex(
109+ * PartitionOptions.getDefaultInstance(),
110+ * "Singers",
111+ * "SingerId",
112+ * KeySet.all(),
113+ * Arrays.asList("FirstName"));
114+ * BatchTransactionId txnID = txn.getBatchTransactionId();
115+ * int numRowsRead = 0;
116+ * for (Partition p : partitions) {
117+ * BatchReadOnlyTransaction batchTxnOnEachWorker = batchClient.batchReadOnlyTransaction(txnID);
118+ * try (ResultSet results = batchTxnOnEachWorker.execute(p)) {
119+ * while (results.next()) {
120+ * System.out.println(results.getString(0));
121+ * }
122+ * }
123+ * }
124+ * }</pre>
125+ * <!--SNIPPET partition_read_using_index-->
79126 */
80127 List <Partition > partitionReadUsingIndex (
81128 PartitionOptions partitionOptions ,
@@ -95,6 +142,26 @@ List<Partition> partitionReadUsingIndex(
95142 * @param partitionOptions configuration for size and count of partitions returned
96143 * @param statement the query statement to execute
97144 * @param options the options to configure the query
145+ *
146+ * <!--SNIPPET partition_query-->
147+ * <pre>{@code
148+ * final BatchReadOnlyTransaction txn =
149+ * batchClient.batchReadOnlyTransaction(TimestampBound.strong());
150+ * List<Partition> partitions = txn.partitionQuery(PartitionOptions.getDefaultInstance(),
151+ * Statement.of("SELECT SingerId, FirstName, LastName FROM Singers"));
152+ *
153+ * for (final Partition p : partitions) {
154+ * try (ResultSet results = txn.execute(p)) {
155+ * while (results.next()) {
156+ * long singerId = results.getLong(0);
157+ * String firstName = results.getString(1);
158+ * String lastName = results.getString(2);
159+ * System.out.println("[" + singerId + "] " + firstName + " " + lastName);
160+ * }
161+ * }
162+ * }
163+ * }</pre>
164+ * <!--SNIPPET partition_query-->
98165 */
99166 List <Partition > partitionQuery (
100167 PartitionOptions partitionOptions , Statement statement , QueryOption ... options )
@@ -103,12 +170,41 @@ List<Partition> partitionQuery(
103170 /**
104171 * Execute the partition to return {@link ResultSet}. The result returned could be zero or more
105172 * rows. The row metadata may be absent if no rows are returned.
173+ *
174+ * <!--SNIPPET partition_query-->
175+ * <pre>{@code
176+ * final BatchReadOnlyTransaction txn =
177+ * batchClient.batchReadOnlyTransaction(TimestampBound.strong());
178+ * List<Partition> partitions = txn.partitionQuery(PartitionOptions.getDefaultInstance(),
179+ * Statement.of("SELECT SingerId, FirstName, LastName FROM Singers"));
180+ *
181+ * for (final Partition p : partitions) {
182+ * try (ResultSet results = txn.execute(p)) {
183+ * while (results.next()) {
184+ * long singerId = results.getLong(0);
185+ * String firstName = results.getString(1);
186+ * String lastName = results.getString(2);
187+ * System.out.println("[" + singerId + "] " + firstName + " " + lastName);
188+ * }
189+ * }
190+ * }
191+ * }</pre>
192+ * <!--SNIPPET partition_query-->
193+ *
106194 */
107195 ResultSet execute (Partition partition ) throws SpannerException ;
108196
109197 /**
110198 * Returns a {@link BatchTransactionId} to be re-used across several machines/processes. This
111199 * BatchTransactionId guarantees the subsequent read/query to be executed at the same timestamp.
200+ *
201+ * <!--SNIPPET batch_client_read_with_id-->
202+ * <pre>{@code
203+ * BatchTransactionId txnId = my_txn.getBatchTransactionId();
204+ * BatchReadOnlyTransaction txn = batchClient.batchReadOnlyTransaction(txnId);
205+ * }</pre>
206+ * <!--SNIPPET batch_client_read_with_id-->
207+ *
112208 */
113209 BatchTransactionId getBatchTransactionId ();
114210}
0 commit comments