【发布时间】:2020-10-20 14:40:13
【问题描述】:
主题几乎说明了一切。当我从 BigQuery 文档运行代码以更改表属性(在本例中为过期日期)时,它似乎只是简单地删除了表。 (在 BQ GUI 中也找不到。)有人知道为什么吗?谢谢。
# 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)
【问题讨论】:
-
您设置为在两小时内过期表 - 所以可能与时区有关。要检查这个“理论”,例如尝试设置 24 小时,看看问题是否仍然存在
-
你说的很对——很好!如果您想发布它,很高兴将其指定为已接受的答案。
-
当然。谢谢你的确认。移动回答