Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 41a57e6

Browse files
committed
decode instead of encode
1 parent 03a919c commit 41a57e6

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

samples/hello/main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def main(project_id, instance_id, table_id):
5757
# Create a column family with GC policy : most recent N versions
5858
# Define the GC policy to retain only the most recent 2 versions
5959
max_versions_rule = bigtable.column_family.MaxVersionsGCRule(2)
60-
column_family_id = "cf1"
60+
column_family_id = b"cf1"
6161
column_families = {column_family_id: max_versions_rule}
6262
if not table.exists():
6363
table.create(column_families=column_families)
@@ -88,7 +88,7 @@ def main(project_id, instance_id, table_id):
8888
row_key = f"greeting{i}".encode()
8989
row = table.direct_row(row_key)
9090
row.set_cell(
91-
column_family_id.encode(), column, value, timestamp=datetime.datetime.utcnow(),
91+
column_family_id, column, value, timestamp=datetime.datetime.utcnow(),
9292
)
9393
rows.append(row)
9494
table.mutate_rows(rows)
@@ -106,7 +106,7 @@ def main(project_id, instance_id, table_id):
106106
key = b"greeting0"
107107

108108
row = table.read_row(key, row_filter)
109-
cell = row.cells[column_family_id][column][0]
109+
cell = row.cells[column_family_id.decode("utf-8")][column][0]
110110
print(cell.value.decode("utf-8"))
111111
# [END bigtable_hw_get_by_key]
112112
# [END bigtable_hw_get_with_filter]
@@ -117,7 +117,8 @@ def main(project_id, instance_id, table_id):
117117
partial_rows = table.read_rows(filter_=row_filter)
118118

119119
for row in partial_rows:
120-
cell = row.cells[column_family_id][column][0]
120+
column_family_id_str = column_family_id.decode("utf-8")
121+
cell = row.cells[column_family_id_str][column][0]
121122
print(cell.value.decode("utf-8"))
122123
# [END bigtable_hw_scan_all]
123124
# [END bigtable_hw_scan_with_filter]

0 commit comments

Comments
 (0)