从Python更新BigQuery表属性会使表消失

从Python更新BigQuery表属性会使表消失,python,google-bigquery,Python,Google Bigquery,主题几乎说明了一切。当我运行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文档中的代码来更改表属性(在本例中是它的过期日期)时,它似乎只是简单地删除了表。(在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小时,例如,看看问题是否仍然存在

您将在两小时内使表过期,因此可能与时区有关。为了验证这个“理论”,试着以24小时为例,看看这个问题是否仍然存在。你是非常正确的——很好!如果您想发布,很高兴将此指定为已接受的答案。当然。谢谢你的确认。转向回答除了正确之外,这也让我注意到了我忽略的时区控制功能://///////import pytz/////table.expires=datetime.datetime.now(pytz.utc)+datetime.timedelta(hours=2)