table Package

table Package

class starbase.client.table.Table(connection, name)[source]

Bases: object

For HBase table operations.

Parameters:
  • connection (stargate.base.Connection) – Connection instance.
  • name (str) – Table name.
FALSE_ROW_KEY = 'false-row-key'
add_columns(*columns)[source]

Add columns to existing table (POST). If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 200 status.

Parameters:
  • name (str) – Table name.
  • *columns (list) –

    List of columns (plain strins) to ADD.

Return int:

HTTP response status code (200 on success).

Example :

In the example below we create a new table named table1 with columns column1 and column2. In the next step we add columns column3 and columns4 to it.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2')
>>> table.add_columns('column3', 'column4')
batch(size=None)[source]

Returns a Batch instance. Returns None if table does not exist.

Parameters:size (int) – Size of auto-commit. If not given, auto-commit is disabled.
Return starbase.client.table.batch.Batch:
 
Example :

Assuming that we have a table named table1 with columns column1 and column2.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> batch = table.batch()
>>> batch.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> batch.insert('row2', {'column1': {'id': '12', 'name': 'Some name'}, 'column2': {'id': '22', 'age': '322'}})
>>> batch.insert('row3', {'column1': {'id': '13', 'name': 'Some name'}, 'column2': {'id': '23', 'age': '323'}})
>>> batch.commit(finalize=True)
columns()[source]

Gets a plain list of column families of the table given.

Return list:Just a list of plain strings of column family names.
Example :
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.columns()
create(*columns)[source]

Creates a table schema. If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 201 status.

Parameters:*columns (list) –

List of columns (plain strins).

Return int:HTTP response status code (201 on success). Returns boolean False on failure.
Example :
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2')
drop()[source]

Drops current table. If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 200 status.

Return int:HTTP response status code (200 on success).
Example :

In the example below we check if table named table1 exists and if so - drop it.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> if table.exists():
>>>     table.drop()
drop_columns(*columns)[source]

Removes/drops columns from table (PUT).If not successful, returns appropriate HTTP error status code. If successful, returns HTTP 201 status.

Parameters:
  • name (str) – Table name.
  • *columns (list) –

    List of columns (plain strins) to REMOVE.

Return int:

HTTP response status code (201 on success).

Example :

Assuming that we have a table named table1 with columns column1 and column2.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.drop_columns('column1', 'column2')
exists()[source]

Checks if table exists.

Return bool:
Example :
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.exists()
fetch(row, columns=None, timestamp=None, number_of_versions=None, raw=False, perfect_dict=None)[source]

Fetches a single row from table.

Parameters:
  • row (str) –
  • columns (list|set|tuple|dict) –
  • timestamp – Not yet used.
  • number_of_versions (int) – If provided, multiple versions of the given record are returned.
  • perfect_dict (bool) –
  • raw (bool) –
Return dict:
Example :

In the example below we first create a table named table1 with columns column1, column2 and column3, then insert a row with column1 and column2 data, then update the same row with column3 data and then fetch the data.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.update('row2', {'column3': {'gender': 'male', 'favourite_book': 'Steppenwolf', 'active': '1'}})

Fetching entire row1.

>>> table.fetch('row1')

Fetching the row row1 with data from column1 and column3 only.

>>> table.fetch('row1', ['column1', 'column3'])

Fetching the row row1 with fields gender and favourite_book from column3 and fild age of column column2.

>>> table.fetch('row1', {'column3': ['gender', 'favourite_book'], 'column2': ['age']})
fetch_all_rows(with_row_id=False, raw=False, perfect_dict=None, flat=False, filter_string=None, scanner_config='')[source]

Fetches all table rows.

Parameters:
  • with_row_id (bool) – If set to True, returned along with row id.
  • raw (bool) – If set to True, raw response is returned.
  • perfect_dict (bool) – If set to True, a perfect dict struture is used for output data.
  • filter_string (string) – If set, applies the given filter string to the scanner.
Returns list:
Example :
>>> filter_string = '{"type": "RowFilter", "op": "EQUAL", "comparator": '
>>>                 '{"type": "RegexStringComparator", "value": "^row_1.+"}}'
>>> rows = self.table.fetch_all_rows(
>>>            with_row_id = True,
>>>            perfect_dict = perfect_dict,
>>>            filter_string = row_filter_string
>>>            )
insert(row, columns, timestamp=None)[source]

Inserts a single row into a table.

Parameters:
  • row (str) –
  • tuple or set) columns ((list,) –
  • timestamp
Return int:

HTTP status code (200 on success).

Example :

In the example below we first create a table named table1 and then insert two rows to it.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.insert('row2', {'column3': {'gender': 'male', 'favourite_book': 'Steppenwolf'}})
metadata()

Table metadata. Retrieves table region metadata.

Return dict:
regions()[source]

Table metadata. Retrieves table region metadata.

Return dict:
remove(row, column=None, qualifier=None, timestamp=None)[source]

Removes/delets a single row/column/qualifier from a table (depending on the depth given). If only row is given, the entire row is deleted. If row and column, only the column value is deleted (entirely for the row given). If qualifier is given as well, then only the qualifier value would be deleted.

Parameters:
  • row (str) –
  • column (str) –
  • qualifier (str) –
Return int:

HTTP status code.

Example :

In the example below we first create a table named table1 with columns column1, column2 and column3. Then we insert a single row with multiple columns and then remove parts from that row.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.remove('row1', 'column2', 'id')
>>> table.remove('row1', 'column1')
>>> table.remove('row1')
schema()[source]

Table schema. Retrieves table schema.

Return dict:Dictionary with schema info (detailed information on column families).
Example :
>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.schema()
update(row, columns, timestamp=None)[source]

Updates a single row in a table.

Parameters:
  • row (str) –
  • columns (dict) –
  • timestamp – Not yet used.
Return int:

HTTP response status code (200 on success).

Example :

In the example below we first create a table named table1 with columns column1, column2 and column3. Then we insert a row with column1 and column2 data and then update the same row with column3 data.

>>> from starbase import Connection
>>> connection = Connection()
>>> table = connection.table('table1')
>>> table.create('column1', 'column2', 'column3')
>>> table.insert('row1', {'column1': {'id': '1', 'name': 'Some name'}, 'column2': {'id': '2', 'age': '32'}})
>>> table.update('row1', {'column3': {'gender': 'female', 'favourite_book': 'Solaris'}})

batch Module

class starbase.client.table.batch.Batch(table, size=None)[source]

Bases: object

Table batch operations.

Parameters:
  • table (starbase.client.table.Table) –
  • size (int) – Batch size. When set, auto commits stacked records when the stack reaches the size value.
commit(finalize=False)[source]

Sends all queued items to Stargate.

Parameters:finalize (bool) – If set to True, the batch is finalized, settings are cleared up and response is returned.
Return dict:If finalize set to True, returns the returned value of method meth::starbase.client.batch.Batch.finalize.
finalize()[source]

Finalize the batch operation. Clear all settings.

Return dict:
insert(row, columns, timestamp=None)[source]
outgoing()[source]

Returns number of outgoing requests.

Return int:
update(row, columns, timestamp=None, encode_content=True)[source]

scanner Module

class starbase.client.table.scanner.Scanner(table, url, batch_size=None, start_row=None, end_row=None, start_time=None, end_time=None, data={}, extra_headers={}, method=None)[source]

Bases: object

Table scanner operations.

delete()[source]

Delete scanner.

results(with_row_id=False, raw=False, perfect_dict=None)[source]
Read the Docs v: 0.2.4
Versions
latest
0.2.4
0.1
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.