Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion happybase/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ def test_put():
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'
column = 'cf1:counter'
Expand Down