从Python更新BigQuery表属性会使表消失 [英] Updating BigQuery table properties from Python makes table disappear

查看:81
本文介绍了从Python更新BigQuery表属性会使表消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主题几乎说明了一切.当我从BigQuery文档中运行代码以更改表属性(在本例中为它的到期日期)时,似乎只是立即删除了表. (在BQ GUI中也找不到.)有人知道为什么吗?谢谢.

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)

推荐答案

您正在设置要在两个小时后过期的表-可能与时区有关.检查这个理论"尝试设置24小时为例,看看问题是否仍然存在

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

这篇关于从Python更新BigQuery表属性会使表消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆