|
25 | 25 | from gcloud.bigtable.column_family import ColumnFamily |
26 | 26 | from gcloud.bigtable.row import Row |
27 | 27 | from gcloud.bigtable.row_data import PartialRowData |
| 28 | +from gcloud.bigtable.row_data import PartialRowsData |
28 | 29 |
|
29 | 30 |
|
30 | 31 | class Table(object): |
@@ -255,6 +256,59 @@ def read_row(self, row_key, filter_=None): |
255 | 256 | raise ValueError('The row remains partial / is not committed.') |
256 | 257 | return result |
257 | 258 |
|
| 259 | + def read_rows(self, start_key=None, end_key=None, |
| 260 | + allow_row_interleaving=None, limit=None, filter_=None): |
| 261 | + """Read rows from this table. |
| 262 | +
|
| 263 | + :type start_key: bytes |
| 264 | + :param start_key: (Optional) The beginning of a range of row keys to |
| 265 | + read from. The range will include ``start_key``. If |
| 266 | + left empty, will be interpreted as the empty string. |
| 267 | +
|
| 268 | + :type end_key: bytes |
| 269 | + :param end_key: (Optional) The end of a range of row keys to read from. |
| 270 | + The range will not include ``end_key``. If left empty, |
| 271 | + will be interpreted as an infinite string. |
| 272 | +
|
| 273 | + :type allow_row_interleaving: bool |
| 274 | + :param allow_row_interleaving: (Optional) By default, rows are read |
| 275 | + sequentially, producing results which |
| 276 | + are guaranteed to arrive in increasing |
| 277 | + row order. Setting |
| 278 | + ``allow_row_interleaving`` to |
| 279 | + :data:`True` allows multiple rows to be |
| 280 | + interleaved in the response stream, |
| 281 | + which increases throughput but breaks |
| 282 | + this guarantee, and may force the |
| 283 | + client to use more memory to buffer |
| 284 | + partially-received rows. |
| 285 | +
|
| 286 | + :type limit: int |
| 287 | + :param limit: (Optional) The read will terminate after committing to N |
| 288 | + rows' worth of results. The default (zero) is to return |
| 289 | + all results. Note that if ``allow_row_interleaving`` is |
| 290 | + set to :data:`True`, partial results may be returned for |
| 291 | + more than N rows. However, only N ``commit_row`` chunks |
| 292 | + will be sent. |
| 293 | +
|
| 294 | + :type filter_: :class:`.row.RowFilter` |
| 295 | + :param filter_: (Optional) The filter to apply to the contents of the |
| 296 | + specified row(s). If unset, reads every column in |
| 297 | + each row. |
| 298 | +
|
| 299 | + :rtype: :class:`.PartialRowsData` |
| 300 | + :returns: A :class:`.PartialRowsData` convenience wrapper for consuming |
| 301 | + the streamed results. |
| 302 | + """ |
| 303 | + request_pb = _create_row_request( |
| 304 | + self.name, start_key=start_key, end_key=end_key, filter_=filter_, |
| 305 | + allow_row_interleaving=allow_row_interleaving, limit=limit) |
| 306 | + client = self._cluster._client |
| 307 | + response_iterator = client._data_stub.ReadRows(request_pb, |
| 308 | + client.timeout_seconds) |
| 309 | + # We expect an iterator of `data_messages_pb2.ReadRowsResponse` |
| 310 | + return PartialRowsData(response_iterator) |
| 311 | + |
258 | 312 | def sample_row_keys(self): |
259 | 313 | """Read a sample of row keys in the table. |
260 | 314 |
|
@@ -314,9 +368,7 @@ def _create_row_request(table_name, row_key=None, start_key=None, end_key=None, |
314 | 368 | The range will not include ``end_key``. If left empty, |
315 | 369 | will be interpreted as an infinite string. |
316 | 370 |
|
317 | | - :type filter_: :class:`.row.RowFilter`, :class:`.row.RowFilterChain`, |
318 | | - :class:`.row.RowFilterUnion` or |
319 | | - :class:`.row.ConditionalRowFilter` |
| 371 | + :type filter_: :class:`.row.RowFilter` |
320 | 372 | :param filter_: (Optional) The filter to apply to the contents of the |
321 | 373 | specified row(s). If unset, reads the entire table. |
322 | 374 |
|
|
0 commit comments