@@ -54,6 +54,29 @@ public interface BatchReadOnlyTransaction extends ReadOnlyTransaction {
54
54
* @param columns the columns to read
55
55
* @param options the options to configure the read, supported values are
56
56
* {@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-->
57
80
*/
58
81
List <Partition > partitionRead (
59
82
PartitionOptions partitionOptions ,
@@ -76,6 +99,30 @@ List<Partition> partitionRead(
76
99
* rows are returned in the natural key order of the index.
77
100
* @param columns the columns to read
78
101
* @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-->
79
126
*/
80
127
List <Partition > partitionReadUsingIndex (
81
128
PartitionOptions partitionOptions ,
@@ -95,6 +142,26 @@ List<Partition> partitionReadUsingIndex(
95
142
* @param partitionOptions configuration for size and count of partitions returned
96
143
* @param statement the query statement to execute
97
144
* @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-->
98
165
*/
99
166
List <Partition > partitionQuery (
100
167
PartitionOptions partitionOptions , Statement statement , QueryOption ... options )
@@ -103,12 +170,41 @@ List<Partition> partitionQuery(
103
170
/**
104
171
* Execute the partition to return {@link ResultSet}. The result returned could be zero or more
105
172
* 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
+ *
106
194
*/
107
195
ResultSet execute (Partition partition ) throws SpannerException ;
108
196
109
197
/**
110
198
* Returns a {@link BatchTransactionId} to be re-used across several machines/processes. This
111
199
* 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
+ *
112
208
*/
113
209
BatchTransactionId getBatchTransactionId ();
114
210
}
0 commit comments