Skip to content

Commit

Permalink
Adding HappyBase Table class.
Browse files Browse the repository at this point in the history
For now, just implementing the constructor.

Also had to fix a lot of ambiguous references caused by two
classes named Table.
  • Loading branch information
dhermes committed Sep 4, 2015
1 parent 8e09214 commit b8b5e97
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 17 deletions.
5 changes: 3 additions & 2 deletions docs/column-family.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Column Families
===============

When creating a :class:`Table <gcloud_bigtable.column_family.ColumnFamily>`,
it is possible to set garbage collection rules for expired data.
When creating a
:class:`ColumnFamily <gcloud_bigtable.column_family.ColumnFamily>`, it is
possible to set garbage collection rules for expired data.

By setting a rule, cells in the table matching the rule will be deleted
during periodic garbage collection (which executes opportunistically in the
Expand Down
6 changes: 3 additions & 3 deletions gcloud_bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
In the hierarchy of API concepts
* a :class:`Client` owns a :class:`.Cluster`
* a :class:`.Cluster` owns a :class:`Table <.table.Table>`
* a :class:`Table <.table.Table>` owns a
* a :class:`.Cluster` owns a :class:`Table <gcloud_bigtable.table.Table>`
* a :class:`Table <gcloud_bigtable.table.Table>` owns a
:class:`ColumnFamily <.column_family.ColumnFamily>`
* a :class:`Table <.table.Table>` owns a :class:`Row <.row.Row>`
* a :class:`Table <gcloud_bigtable.table.Table>` owns a :class:`Row <.row.Row>`
(and all the cells in the row)
"""

Expand Down
4 changes: 2 additions & 2 deletions gcloud_bigtable/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def table(self, table_id):
:type table_id: str
:param table_id: The ID of the table.
:rtype: :class:`.Table`
:rtype: :class:`Table <gcloud_bigtable.table.Table>`
:returns: The table owned by this cluster.
"""
return Table(table_id, self)
Expand Down Expand Up @@ -403,7 +403,7 @@ def list_tables(self, timeout_seconds=None):
If not passed, defaults to value set on
cluster.
:rtype: list of :class:`.Table`
:rtype: list of :class:`Table <gcloud_bigtable.table.Table>`
:returns: The list of tables owned by the cluster.
:raises: :class:`ValueError <exceptions.ValueError>` if one of the
returned tables has a name that is not of the expected format.
Expand Down
4 changes: 2 additions & 2 deletions gcloud_bigtable/column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class ColumnFamily(object):
:param column_family_id: The ID of the column family. Must be of the
form ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``.
:type table: :class:`.table.Table`
:type table: :class:`Table <gcloud_bigtable.table.Table>`
:param table: The table that owns the column family.
:type gc_rule: :class:`GarbageCollectionRule`,
Expand All @@ -186,7 +186,7 @@ def __init__(self, column_family_id, table, gc_rule=None):
def table(self):
"""Getter for column family's table.
:rtype: :class:`.table.Table`
:rtype: :class:`Table <gcloud_bigtable.table.Table>`
:returns: The table stored on the column family.
"""
return self._table
Expand Down
6 changes: 1 addition & 5 deletions gcloud_bigtable/happybase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
from gcloud_bigtable.happybase.connection import DEFAULT_PORT
from gcloud_bigtable.happybase.pool import ConnectionPool
from gcloud_bigtable.happybase.pool import NoConnectionsAvailable


# Types that have yet to be implemented
class Table(object):
"""Unimplemented Table stub."""
from gcloud_bigtable.happybase.table import Table


# Values from HappyBase that we don't reproduce / are not relevant.
Expand Down
2 changes: 1 addition & 1 deletion gcloud_bigtable/happybase/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Batch(object):
"""Batch class for accumulating mutations.
:type table: :class:`.Table`
:type table: :class:`Table <gcloud_bigtable.happybase.table.Table>`
:param table: The table where mutations will be applied.
:type timestamp: int
Expand Down
17 changes: 17 additions & 0 deletions gcloud_bigtable/happybase/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,20 @@ def make_ordered_row(sorted_columns, include_timestamp):
'as the output from the Thrift server, so this '
'helper can not be implemented.', 'Called with',
sorted_columns, include_timestamp)


class Table(object):
"""Representation of Cloud Bigtable table.
Used for adding data and
:type name: str
:param name: The name of the table.
:type connection: :class:`.Connection`
:param connection: The connection which has access to the table.
"""

def __init__(self, name, connection):
self.name = name
self.connection = connection
17 changes: 17 additions & 0 deletions gcloud_bigtable/happybase/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ def _callFUT(self, *args, **kwargs):
def test_it(self):
with self.assertRaises(NotImplementedError):
self._callFUT([], False)


class TestTable(unittest2.TestCase):

def _getTargetClass(self):
from gcloud_bigtable.happybase.table import Table
return Table

def _makeOne(self, *args, **kwargs):
return self._getTargetClass()(*args, **kwargs)

def test_constructor(self):
name = 'table-name'
connection = object()
table = self._makeOne(name, connection)
self.assertEqual(table.name, name)
self.assertEqual(table.connection, connection)
4 changes: 2 additions & 2 deletions gcloud_bigtable/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Row(object):
:type row_key: bytes
:param row_key: The key for the current row.
:type table: :class:`.table.Table`
:type table: :class:`Table <gcloud_bigtable.table.Table>`
:param table: The table that owns the row.
:type filter_: :class:`RowFilter`, :class:`RowFilterChain`,
Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(self, row_key, table, filter_=None):
def table(self):
"""Getter for row's table.
:rtype: :class:`.table.Table`
:rtype: :class:`Table <gcloud_bigtable.table.Table>`
:returns: The table stored on the row.
"""
return self._table
Expand Down

0 comments on commit b8b5e97

Please sign in to comment.