Skip to content

Commit 9b40bc4

Browse files
t-karasovatetiana-karasovaparthea
authored andcommitted
test: create bq table fixed (#184)
Co-authored-by: tetiana-karasova <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent d561926 commit 9b40bc4

File tree

6 files changed

+27
-37
lines changed

6 files changed

+27
-37
lines changed

generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,19 @@ def create_bq_table(dataset, table_name, schema_file_path):
171171
"""Create a BigQuery table"""
172172
full_table_id = f"{project_id}.{dataset}.{table_name}"
173173
bq = bigquery.Client()
174-
print(f"Creating BigQuery table {full_table_id}")
174+
print(f"Check if BQ table {full_table_id} exists")
175175
try:
176176
bq.get_table(full_table_id)
177-
print(f"table {full_table_id} already exists")
177+
print(f"table {full_table_id} exists and will be deleted")
178+
delete_bq_table(dataset, table_name)
178179
except NotFound:
179-
# Construct a Table object to send to the API.
180-
with open(schema_file_path, "rb") as schema:
181-
schema_dict = json.load(schema)
182-
table = bigquery.Table(full_table_id, schema=schema_dict)
183-
bq.create_table(table)
184-
print("table is created")
180+
print(f"table {full_table_id} does not exist")
181+
# Construct a Table object to send to the API.
182+
with open(schema_file_path, "rb") as schema:
183+
schema_dict = json.load(schema)
184+
table = bigquery.Table(full_table_id, schema=schema_dict)
185+
bq.create_table(table)
186+
print(f"table {full_table_id} is created")
185187

186188

187189
def delete_bq_table(dataset, table_name):

generated_samples/interactive-tutorials/product/add_fulfillment_places.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
# The request timestamp
3636
current_date = datetime.datetime.now()
37-
outdated_date = datetime.datetime.now() - datetime.timedelta(days=1)
3837

3938

4039
# add fulfillment request
@@ -63,8 +62,8 @@ def add_fulfillment_places(product_name: str, timestamp, place_id):
6362

6463
# This is a long running operation and its result is not immediately present with get operations,
6564
# thus we simulate wait with sleep method.
66-
print("---add fulfillment places, wait 40 seconds :---")
67-
time.sleep(40)
65+
print("---add fulfillment places, wait 90 seconds :---")
66+
time.sleep(90)
6867

6968

7069
# [END retail_add_fulfillment_places]
@@ -74,7 +73,4 @@ def add_fulfillment_places(product_name: str, timestamp, place_id):
7473
print("------add fulfilment places with current date: {}-----".format(current_date))
7574
add_fulfillment_places(product_name, current_date, "store2")
7675
get_product(product_name)
77-
print("------add outdated fulfilment places: {}-----".format(outdated_date))
78-
add_fulfillment_places(product_name, outdated_date, "store3")
79-
get_product(product_name)
8076
delete_product(product_name)

generated_samples/interactive-tutorials/product/remove_fulfillment_places.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
# The request timestamp
3636
current_date = datetime.datetime.now()
37-
outdated_date = datetime.datetime.now() - datetime.timedelta(days=1)
3837

3938

4039
# remove fulfillment request
@@ -63,8 +62,8 @@ def remove_fulfillment_places(product_name: str, timestamp, store_id):
6362

6463
# This is a long running operation and its result is not immediately present with get operations,
6564
# thus we simulate wait with sleep method.
66-
print("---remove fulfillment places, wait 40 seconds:---")
67-
time.sleep(40)
65+
print("---remove fulfillment places, wait 90 seconds:---")
66+
time.sleep(90)
6867

6968

7069
# [END retail_remove_fulfillment_places]
@@ -74,7 +73,4 @@ def remove_fulfillment_places(product_name: str, timestamp, store_id):
7473
print("------remove fulfilment places with current date: {}-----".format(current_date))
7574
remove_fulfillment_places(product_name, current_date, "store0")
7675
get_product(product_name)
77-
print("------remove outdated fulfilment places: {}-----".format(outdated_date))
78-
remove_fulfillment_places(product_name, outdated_date, "store1")
79-
get_product(product_name)
8076
delete_product(product_name)

generated_samples/interactive-tutorials/product/set_inventory.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
def get_product_with_inventory_info(product_name: str) -> Product:
4545
price_info = PriceInfo()
4646
price_info.price = 15.0
47-
price_info.original_price = 20.0
47+
price_info.original_price = 60.0
4848
price_info.cost = 8.0
4949
price_info.currency_code = "USD"
5050

@@ -65,8 +65,6 @@ def get_product_with_inventory_info(product_name: str) -> Product:
6565
def get_set_inventory_request(product_name: str) -> SetInventoryRequest:
6666
# The request timestamp
6767
request_time = datetime.datetime.now()
68-
# The out-of-order request timestamp
69-
# request_time = datetime.datetime.now() - datetime.timedelta(days=1)
7068
set_mask = FieldMask(
7169
paths=["price_info", "availability", "fulfillment_info", "available_quantity"]
7270
)
@@ -90,8 +88,8 @@ def set_inventory(product_name: str):
9088

9189
# This is a long running operation and its result is not immediately present with get operations,
9290
# thus we simulate wait with sleep method.
93-
print("---set inventory, wait 60 seconds:---")
94-
time.sleep(60)
91+
print("---set inventory, wait 90 seconds:---")
92+
time.sleep(90)
9593

9694

9795
create_product(product_id)

generated_samples/interactive-tutorials/product/setup_product/setup_cleanup.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,19 @@ def create_bq_table(dataset, table_name, schema_file_path):
180180
"""Create a BigQuery table"""
181181
full_table_id = f"{project_id}.{dataset}.{table_name}"
182182
bq = bigquery.Client()
183-
print(f"Creating BigQuery table {full_table_id}")
183+
print(f"Check if BQ table {full_table_id} exists")
184184
try:
185185
bq.get_table(full_table_id)
186-
print(f"table {full_table_id} already exists")
186+
print(f"table {full_table_id} exists and will be deleted")
187+
delete_bq_table(dataset, table_name)
187188
except NotFound:
188-
# Construct a Table object to send to the API.
189-
with open(schema_file_path, "rb") as schema:
190-
schema_dict = json.load(schema)
191-
table = bigquery.Table(full_table_id, schema=schema_dict)
192-
bq.create_table(table)
193-
print("table is created")
189+
print(f"table {full_table_id} does not exist")
190+
# Construct a Table object to send to the API.
191+
with open(schema_file_path, "rb") as schema:
192+
schema_dict = json.load(schema)
193+
table = bigquery.Table(full_table_id, schema=schema_dict)
194+
bq.create_table(table)
195+
print(f"table {full_table_id} is created")
194196

195197

196198
def delete_bq_table(dataset, table_name):

generated_samples/interactive-tutorials/product/update_product.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030

3131
from setup_product.setup_cleanup import create_product, delete_product
3232

33-
# from google.protobuf.field_mask_pb2 import FieldMask
34-
# from google.protobuf.field_mask_pb2 import FieldMask
35-
36-
3733
project_id = google.auth.default()[1]
3834
default_branch_name = (
3935
"projects/"

0 commit comments

Comments
 (0)