Skip to content

Commit

Permalink
chore: use more verbose paths in hello snippets (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche authored Dec 6, 2024
1 parent 7ea3c23 commit 1193530
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion samples/beam/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==8.3.2
pytest
14 changes: 7 additions & 7 deletions samples/hello/async_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
# [START bigtable_async_hw_imports]
from google.cloud import bigtable
from google.cloud.bigtable.data import row_filters
from google.cloud.bigtable.data import RowMutationEntry
from google.cloud.bigtable.data import SetCell
from google.cloud.bigtable.data import ReadRowsQuery
# [END bigtable_async_hw_imports]

# use to ignore warnings
row_filters


async def main(project_id, instance_id, table_id):
# [START bigtable_async_hw_connect]
Expand Down Expand Up @@ -85,8 +85,8 @@ async def main(project_id, instance_id, table_id):
#
# https://cloud.google.com/bigtable/docs/schema-design
row_key = "greeting{}".format(i).encode()
row_mutation = RowMutationEntry(
row_key, SetCell(column_family_id, column, value)
row_mutation = bigtable.data.RowMutationEntry(
row_key, bigtable.data.SetCell(column_family_id, column, value)
)
mutations.append(row_mutation)
await table.bulk_mutate_rows(mutations)
Expand All @@ -95,7 +95,7 @@ async def main(project_id, instance_id, table_id):
# [START bigtable_async_hw_create_filter]
# Create a filter to only retrieve the most recent version of the cell
# for each column across entire row.
row_filter = row_filters.CellsColumnLimitFilter(1)
row_filter = bigtable.data.row_filters.CellsColumnLimitFilter(1)
# [END bigtable_async_hw_create_filter]

# [START bigtable_async_hw_get_with_filter]
Expand All @@ -112,7 +112,7 @@ async def main(project_id, instance_id, table_id):
# [START bigtable_async_hw_scan_with_filter]
# [START bigtable_async_hw_scan_all]
print("Scanning for all greetings:")
query = ReadRowsQuery(row_filter=row_filter)
query = bigtable.data.ReadRowsQuery(row_filter=row_filter)
async for row in await table.read_rows_stream(query):
cell = row.cells[0]
print(cell.value.decode("utf-8"))
Expand Down
8 changes: 6 additions & 2 deletions samples/hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

# [END bigtable_hw_imports]

# use to avoid warnings
row_filters
column_family


def main(project_id, instance_id, table_id):
# [START bigtable_hw_connect]
Expand All @@ -52,7 +56,7 @@ def main(project_id, instance_id, table_id):
print("Creating column family cf1 with Max Version GC rule...")
# Create a column family with GC policy : most recent N versions
# Define the GC policy to retain only the most recent 2 versions
max_versions_rule = column_family.MaxVersionsGCRule(2)
max_versions_rule = bigtable.column_family.MaxVersionsGCRule(2)
column_family_id = "cf1"
column_families = {column_family_id: max_versions_rule}
if not table.exists():
Expand Down Expand Up @@ -93,7 +97,7 @@ def main(project_id, instance_id, table_id):
# [START bigtable_hw_create_filter]
# Create a filter to only retrieve the most recent version of the cell
# for each column across entire row.
row_filter = row_filters.CellsColumnLimitFilter(1)
row_filter = bigtable.row_filters.CellsColumnLimitFilter(1)
# [END bigtable_hw_create_filter]

# [START bigtable_hw_get_with_filter]
Expand Down
2 changes: 1 addition & 1 deletion samples/hello/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==8.3.2
pytest
2 changes: 1 addition & 1 deletion samples/hello_happybase/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==8.3.2
pytest
2 changes: 1 addition & 1 deletion samples/instanceadmin/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==8.3.2
pytest
2 changes: 1 addition & 1 deletion samples/metricscaler/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest==8.3.2
pytest
mock==5.1.0
google-cloud-testutils
2 changes: 1 addition & 1 deletion samples/quickstart/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest==8.3.2
pytest
pytest-asyncio
2 changes: 1 addition & 1 deletion samples/quickstart_happybase/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==8.3.2
pytest
2 changes: 1 addition & 1 deletion samples/snippets/data_client/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest==8.3.2
pytest
pytest-asyncio
8 changes: 8 additions & 0 deletions samples/snippets/deletes/deletes_async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
TABLE_ID = f"mobile-time-series-deletes-async-{str(uuid.uuid4())[:16]}"


@pytest.fixture(scope="module")
def event_loop():
import asyncio
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()


@pytest_asyncio.fixture(scope="module", autouse=True)
async def table_id() -> AsyncGenerator[str, None]:
with create_table_cm(PROJECT, BIGTABLE_INSTANCE, TABLE_ID, {"stats_summary": None, "cell_plan": None}, verbose=False):
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/deletes/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest==8.3.2
pytest
pytest-asyncio
8 changes: 8 additions & 0 deletions samples/snippets/filters/filter_snippets_async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
TABLE_ID = f"mobile-time-series-filters-async-{str(uuid.uuid4())[:16]}"


@pytest.fixture(scope="module")
def event_loop():
import asyncio
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()


@pytest_asyncio.fixture(scope="module", autouse=True)
async def table_id() -> AsyncGenerator[str, None]:
with create_table_cm(PROJECT, BIGTABLE_INSTANCE, TABLE_ID, {"stats_summary": None, "cell_plan": None}):
Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/filters/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest==8.3.2
pytest
pytest-asyncio
2 changes: 1 addition & 1 deletion samples/snippets/reads/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==8.3.2
pytest
2 changes: 1 addition & 1 deletion samples/snippets/writes/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
backoff==2.2.1
pytest==8.3.2
pytest
2 changes: 1 addition & 1 deletion samples/tableadmin/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytest==8.3.2
pytest
google-cloud-testutils==1.4.0

0 comments on commit 1193530

Please sign in to comment.