From dd5f2417b106b4e46c898872c70196c90254778e Mon Sep 17 00:00:00 2001 From: Lukas Biermann Date: Sat, 30 Sep 2017 12:20:03 +0200 Subject: [PATCH 1/3] fixes #165 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e96b6a5..1113be3 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ def get_install_requires(): include_package_data=True, license="MIT", classifiers=( - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", From 4be0b77e999745d0716edb7054a6850fbf8ac7d8 Mon Sep 17 00:00:00 2001 From: Lukas Biermann Date: Mon, 2 Oct 2017 15:02:10 +0200 Subject: [PATCH 2/3] added append function and test to happybase --- happybase/table.py | 24 +++++++++++++++++++++++- tests/test_api.py | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/happybase/table.py b/happybase/table.py index d0469e1..9ab7c44 100644 --- a/happybase/table.py +++ b/happybase/table.py @@ -8,7 +8,7 @@ from six import iteritems -from Hbase_thrift import TScan +from Hbase_thrift import TScan, TAppend from .util import thrift_type_to_dict, bytes_increment, OrderedDict from .batch import Batch @@ -440,6 +440,28 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None, # Data manipulation # + def append(self, row, data): + """Appends data to an existing row. + + This method appends data in the `data` argument to + existing data for the row specified by `row`. The `data argument is a + 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:'``. If there is no data for the specified cell, append will act like put. + + + :param row: the row key + :param data: the data to store + """ + columns, values = map(list, zip(*data.items())) + append = TAppend(table = self.name, + row = row, + columns = columns, + values = values) + self.connection.client.append(append) + + + def put(self, row, data, timestamp=None, wal=True): """Store data in the table. diff --git a/tests/test_api.py b/tests/test_api.py index f5242a5..5aa72a6 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -163,6 +163,11 @@ def test_put(): table.put(b'r1', {b'cf1:c4': b'v2'}, timestamp=2345678) table.put(b'r1', {b'cf1:c4': b'v2'}, timestamp=1369168852994) +def test_append(): + table.append(b'rAppend',{b'cf1:c1':b'test123'}) + table.append(b'rAppend', {b'cf1:c1':b'test123'}) + assert_equal((table.row(b'rAppend')[b'cf1:c1']),b'test123test123') + def test_atomic_counters(): row = b'row-with-counter' From 8bca5c103b137e433863d9d68c531774bbeb01a2 Mon Sep 17 00:00:00 2001 From: Lukas Biermann Date: Tue, 3 Oct 2017 15:15:43 +0200 Subject: [PATCH 3/3] fixed pep8 warnings --- happybase/table.py | 16 ++++++++-------- tests/test_api.py | 7 ++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/happybase/table.py b/happybase/table.py index 9ab7c44..b9e46c6 100644 --- a/happybase/table.py +++ b/happybase/table.py @@ -445,23 +445,23 @@ def append(self, row, data): This method appends data in the `data` argument to existing data for the row specified by `row`. The `data argument is a - dictionary that maps columns to values. Column names must include a family and qualifier part, e.g. + 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:'``. If there is no data for the specified cell, append will act like put. + ``b'cf:'``. + If there is no data for the specified cell, append will act like put. :param row: the row key :param data: the data to store """ columns, values = map(list, zip(*data.items())) - append = TAppend(table = self.name, - row = row, - columns = columns, - values = values) + append = TAppend(table=self.name, + row=row, + columns=columns, + values=values) self.connection.client.append(append) - - def put(self, row, data, timestamp=None, wal=True): """Store data in the table. diff --git a/tests/test_api.py b/tests/test_api.py index 5aa72a6..368265a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -163,10 +163,11 @@ def test_put(): table.put(b'r1', {b'cf1:c4': b'v2'}, timestamp=2345678) table.put(b'r1', {b'cf1:c4': b'v2'}, timestamp=1369168852994) + def test_append(): - table.append(b'rAppend',{b'cf1:c1':b'test123'}) - table.append(b'rAppend', {b'cf1:c1':b'test123'}) - assert_equal((table.row(b'rAppend')[b'cf1:c1']),b'test123test123') + table.append(b'rAppend', {b'cf1:c1': b'test123'}) + table.append(b'rAppend', {b'cf1:c1': b'test123'}) + assert_equal((table.row(b'rAppend')[b'cf1:c1']), b'test123test123') def test_atomic_counters():