python bigquery获取外部表元数据

时间:2018-11-09 10:08:23

标签: python google-bigquery

我想获取在bigquery中创建的表的外部元数据。该表是这样创建的:

table_ref = self._client.dataset('test').table('test')
table = bigquery.Table(table_ref)

self._extconfig = bigquery.ExternalConfig('AVRO')
self._extconfig.autodetect = True
self._extconfig.source_uris = ['gs://someproject/bucket/dir/file*.avro']
table.external_data_configuration = self._extconfig
self._client.create_table(table)

现在,我想像这样访问external_data_configuration'中存储的元数据:

dataset = self._client.dataset('test')
table_ref = dataset.table('test')
table = bigquery.Table(table_ref)
print(table.table_id)
print(table.path)
print(table.table_type)
print(table.external_data_configuration)

但是我所收到的只是table_type为None,我期望是'AVRO',而external_data_configuration也没有。

是否有一种方法来获取external_data_configuration,尤其是外部表的source_uris

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

dataset = self._client.dataset('test')
table_ref = dataset.table('test')
table = self._client.get_table(table_ref)
print(table.external_data_configuration.source_uris)

get_table将表的所有信息提取到table变量中。