-
Notifications
You must be signed in to change notification settings - Fork 163
counter_incs by incrementRows #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
d455db0
c7dd562
6c9a2e6
209ce27
c5761f6
3ab00d2
ff5c525
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
""" | ||
|
||
import logging | ||
from itertools import izip | ||
from numbers import Integral | ||
from operator import attrgetter | ||
from struct import Struct | ||
|
||
from .hbase.ttypes import TScan | ||
from .hbase.ttypes import TScan, TIncrement | ||
from .util import thrift_type_to_dict, str_increment, OrderedDict | ||
from .batch import Batch | ||
|
||
|
@@ -558,6 +559,25 @@ def counter_inc(self, row, column, value=1): | |
return self.connection.client.atomicIncrement( | ||
self.name, row, column, value) | ||
|
||
def counter_incs(self, row, data): | ||
""" | ||
|
||
This method increments of decrements the counter columns in the row | ||
specified by `row`. The `data` argument is iteratble data type that | ||
contains tuple of column and value, e.g. [(`cf:col`, 1), (`cf:col2`, 2)]. | ||
|
||
Note that unlike `counter_inc`, does not return value after incrementing. | ||
|
||
:param str row: the row key | ||
:param list data: list of tuple for columns and values | ||
""" | ||
if data is not None and not isinstance(data, (list, tuple, izip)): | ||
raise TypeError("'data' must be a iterable data types of tuple") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply require a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any numbers to back up this claim? In the end everything will be pulled into memory anyway when constructing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see.. yes you're right. At the end the data will be wrapped as '''TIncrement''' anyway. ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though you're right that passing a dict will result in stuff in memory twice, but I think it's not a problem. |
||
|
||
self.connection.client.incrementRows( | ||
[TIncrement(table=self.name, row=row, column=column, ammount=value) | ||
for column, value in data]) | ||
|
||
def counter_dec(self, row, column, value=1): | ||
"""Atomically decrement (or increments) a counter column. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps
counters_inc
is a better name? And can you move it belowcounter_dec
for clarity?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree and I will move it below counter_dec.