-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhbase_filter_data.py
More file actions
61 lines (43 loc) · 1.62 KB
/
Copy pathhbase_filter_data.py
File metadata and controls
61 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import happybase
from module_hbase.hbase_insert_data import new_table_name
connection = happybase.Connection(
"10.1.120.3", port=9090, transport="framed", protocol="compact"
)
connection.open()
tables = [item.decode() for item in connection.tables()]
assert new_table_name in tables
table = connection.table(new_table_name)
# get data by row key
print(table.row("row1"))
# get data by row key, specify columns
print(table.row("row1", columns=["cf1:col1"]))
print(table.row("row1", columns=["cf1:col2"]))
print(table.row("row1", columns=["cf1"]))
# get rows by keys
print(table.rows(["row1", "row2"]))
# get rows by keys, specify columns
print(table.rows(["row1", "row2"], columns=["cf1:col1"]))
print(table.rows(["row1", "row2"], columns=["cf1"]))
# retrieve multiple versions of a single cell from table
print(table.cells("row1", column="cf1:col1", include_timestamp=False))
print(table.cells("row1", column="cf1:col1", include_timestamp=True))
def test_filter(filter=None):
print("-" * 128, filter)
for key, data in table.scan(filter=filter):
print(key, data)
test_filter()
test_filter("PrefixFilter('x')")
test_filter("PageFilter (5)")
test_filter("FirstKeyOnlyFilter ()")
test_filter("KeyOnlyFilter ()")
test_filter("ColumnPrefixFilter ('c')") # ??????
test_filter("MultipleColumnPrefixFilter ('c')") # ??????
test_filter("ColumnCountGetFilter (2)") # ??????
test_filter("InclusiveStopFilter ('x1')")
test_filter("ColumnPaginationFilter (1, 1)")
print("*" * 128)
row_start = "0-100-"
row_stop = "0-100."
for key, data in table.scan(row_start=row_start, row_stop=row_stop):
print(key, data)
connection.close()