Updating BigQuery table properties from Python makes table disappear

孤街醉人 提交于 2020-11-29 09:49:13

问题


Subject pretty much says it all. When I run the code from the BigQuery docs to change the table property (in this case, its expiration date), it seems to just summarily delete the table instead. (Can't be found in the BQ GUI either.) Anyone know why? Thanks.

# Replace "dk" with your own initials before running this
s_table_id = 'hcwisdom.temp_tables.new_test_table'
from google.cloud import bigquery
client = bigquery.Client()
schema = [
    bigquery.SchemaField("full_name", "STRING", mode="REQUIRED"),
    bigquery.SchemaField("age", "INTEGER", mode="REQUIRED"),
]
try:
    client.get_table(s_table_id)  # Make an API request.
    print("Table {} exists.".format(s_table_id))
except:
    print("Creating table {}.".format(s_table_id))
    table = bigquery.Table(s_table_id, schema=schema)
    table = client.create_table(table)
# Verify
table = client.get_table(s_table_id)
print(
    "Found {} rows and {} columns in {}".format(
        table.num_rows, len(table.schema), s_table_id
    )
)
# Update table property
#   in the manner of https://cloud.google.com/bigquery/docs/samples/bigquery-update-table-expiration
import datetime
table = client.get_table(s_table_id)
table.expires = datetime.datetime.now() + datetime.timedelta(hours = 2)
client.update_table(table, ['expires'])
# Try to access the table -- you'll get a "not found" error
table = client.get_table(s_table_id)

回答1:


You are setting to expire table in two hours - so might be timezone related. to check this "theory" try to set 24 hours for example and see if issue still exists



来源:https://stackoverflow.com/questions/64447517/updating-bigquery-table-properties-from-python-makes-table-disappear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!