The panko.tests.mocks Module

The panko.tests.mocks Module

class panko.tests.mocks.MockHBaseTable(name, connection, data_prefix)[source]

Bases: happybase.table.Table

delete(row, *args, **kwargs)[source]

Delete data from the table.

This method deletes all columns for the row specified by row, or only some columns if the columns argument is specified.

Note that, in many situations, batch() is a more appropriate method to manipulate data.

New in version 0.7: wal argument

Parameters:
  • row (str) – the row key
  • columns (list_or_tuple) – list of columns (optional)
  • timestamp (int) – timestamp (optional)
  • bool (wal) – whether to write to the WAL (optional)
put(row, *args, **kwargs)[source]

Store data in the table.

This method stores the data in the data argument for the row specified by row. The data argument is dictionary that maps columns to values. Column names must include a family and qualifier part, e.g. b'cf:col', though the qualifier part may be the empty string, e.g. b'cf:'.

Note that, in many situations, batch() is a more appropriate method to manipulate data.

New in version 0.7: wal argument

Parameters:
  • row (str) – the row key
  • data (dict) – the data to store
  • timestamp (int) – timestamp (optional)
  • bool (wal) – whether to write to the WAL (optional)
row(row, *args, **kwargs)[source]

Retrieve a single row of data.

This method retrieves the row with the row key specified in the row argument and returns the columns and values for this row as a dictionary.

The row argument is the row key of the row. If the columns argument is specified, only the values for these columns will be returned instead of all available columns. The columns argument should be a list or tuple containing byte strings. Each name can be a column family, such as b'cf1' or b'cf1:' (the trailing colon is not required), or a column family with a qualifier, such as b'cf1:col1'.

If specified, the timestamp argument specifies the maximum version that results may have. The include_timestamp argument specifies whether cells are returned as single values or as (value, timestamp) tuples.

Parameters:
  • row (str) – the row key
  • columns (list_or_tuple) – list of columns (optional)
  • timestamp (int) – timestamp (optional)
  • include_timestamp (bool) – whether timestamps are returned
Returns:

Mapping of columns (both qualifier and family) to values

Return type:

dict

scan(row_start=None, row_stop=None, row_prefix=None, columns=None, filter=None, timestamp=None, include_timestamp=False, batch_size=10, scan_batching=None, limit=None, sorted_columns=False)[source]

Create a scanner for data in the table.

This method returns an iterable that can be used for looping over the matching rows. Scanners can be created in two ways:

  • The row_start and row_stop arguments specify the row keys where the scanner should start and stop. It does not matter whether the table contains any rows with the specified keys: the first row after row_start will be the first result, and the last row before row_stop will be the last result. Note that the start of the range is inclusive, while the end is exclusive.

    Both row_start and row_stop can be None to specify the start and the end of the table respectively. If both are omitted, a full table scan is done. Note that this usually results in severe performance problems.

  • Alternatively, if row_prefix is specified, only rows with row keys matching the prefix will be returned. If given, row_start and row_stop cannot be used.

The columns, timestamp and include_timestamp arguments behave exactly the same as for row().

The filter argument may be a filter string that will be applied at the server by the region servers.

If limit is given, at most limit results will be returned.

The batch_size argument specifies how many results should be retrieved per batch when retrieving results from the scanner. Only set this to a low value (or even 1) if your data is large, since a low batch size results in added round-trips to the server.

The optional scan_batching is for advanced usage only; it translates to Scan.setBatching() at the Java side (inside the Thrift server). By setting this value rows may be split into partial rows, so result rows may be incomplete, and the number of results returned by te scanner may no longer correspond to the number of rows matched by the scan.

If sorted_columns is True, the columns in the rows returned by this scanner will be retrieved in sorted order, and the data will be stored in OrderedDict instances.

If reverse is True, the scanner will perform the scan in reverse. This means that row_start must be lexicographically after row_stop. Note that the start of the range is inclusive, while the end is exclusive just as in the forward scan.

Compatibility notes:

  • The filter argument is only available when using HBase 0.92 (or up). In HBase 0.90 compatibility mode, specifying a filter raises an exception.
  • The sorted_columns argument is only available when using HBase 0.96 (or up).
  • The reverse argument is only available when using HBase 0.98 (or up).

New in version TODO: reverse argument

New in version 0.8: sorted_columns argument

New in version 0.8: scan_batching argument

Parameters:
  • row_start (str) – the row key to start at (inclusive)
  • row_stop (str) – the row key to stop at (exclusive)
  • row_prefix (str) – a prefix of the row key that must match
  • columns (list_or_tuple) – list of columns (optional)
  • filter (str) – a filter string (optional)
  • timestamp (int) – timestamp (optional)
  • include_timestamp (bool) – whether timestamps are returned
  • batch_size (int) – batch size for retrieving results
  • scan_batching (bool) – server-side scan batching (optional)
  • limit (int) – max number of rows to return
  • sorted_columns (bool) – whether to return sorted columns
  • reverse (bool) – whether to perform scan in reverse
Returns:

generator yielding the rows matching the scan

Return type:

iterable of (row_key, row_data) tuples

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.