【发布时间】:2019-07-26 21:50:04
【问题描述】:
编辑:我已经安装了 BigQuery-Python、bigQueryExporter 和 google-cloud-bigquery,所以这不是问题。
我正在尝试导出现有 BQ 表的架构,包括所有嵌套字段。为此,我试图导入 BQ 的“get_client”包,但它似乎不存在于 python3 中(或者它可能已经改变)。
我第一次尝试创建架构是成功的,但没有处理我需要的嵌套字段(见下文):
from google.cloud import bigquery
def test_extract_schema():
client = bigquery.Client.from_service_account_json('file')
project = 'project_id'
dataset_id = 'test1'
table_id = 'testc'
dataset_ref = client.dataset(dataset_id, project=project)
table_ref = dataset_ref.table(table_id)
table = client.get_table(table_ref) # API Request
result = {schema.name: schema.field_type for schema in table.schema}
listresult = [result]
print(listresult)
if __name__ == '__main__':
test_extract_schema()
我当前的版本,即使我让包运行,我也不确定它是否会工作,看起来像这样:
import web
from google.cloud import bigquery
from bigquery import get_client
urls = ('/GetFields(.*)', 'get_Fields')
app = web.application(urls, globals())
def get():
project_id = 'project_id'
dataset_id = 'test1'
table_id = 'testc'
client = bigquery.Client.from_service_account_json('file')
results = client.get_table_schema(dataset_id, table_id)
return results
if __name__ == "__main__":
get()
“get_table_schema”无法识别,因为无法安装 get_client 包。这不适用于 Python 3,还是有其他问题?提前致谢。
【问题讨论】:
标签: python google-bigquery schema