python - 从 Python 更新 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.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 小时,看看问题是否仍然存在
推荐阅读
- java - Mule 3 java调用连接到unix
- python - 两个对数刻度 hist 轴
- php - 无论收到多少记录,如何循环一定次数(Laravel)
- wordpress - 更改 WP All Import 脚本以从 FTP 导入最新的 XML
- c++ - 多重继承模板的成员函数歧义
- python - 在 Mac OS 上运行 python 代码时出错
- c# - PgpCore 错误 - “未找到消息的密钥。”
- ios - ByteCountFormatter 以 MB 为单位,结果以逗号(,)而不是点(。)返回
- acumatica - 通用搜索 - 重定向到自定义屏幕
- python - 将两个链表中的公共元素插入到第三个链表中