Python BigQuery API-获取表架构 [英] Python BigQuery API - get table schema
本文介绍了Python BigQuery API-获取表架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从bigquery表中获取架构.给定示例代码
I am trying to fetch schema form bigquery table. Given a sample code like
from google.cloud import bigquery
from google.cloud import storage
client = bigquery.Client.from_service_account_json('service_account.json')
def test_extract_schema(client):
project = 'bigquery-public-data'
dataset_id = 'samples'
table_id = 'shakespeare'
dataset_ref = client.dataset(dataset_id, project=project)
table_ref = dataset_ref.table(table_id)
table = client.get_table(table_ref) # API Request
# View table properties
print(table.schema)
if __name__ == '__main__':
test_extract_schema(client)
这是返回值,例如:
[SchemaField('word', 'STRING', 'REQUIRED', 'A single unique word (where whitespace is the delimiter) extracted from a corpus.', ()), SchemaField('word_count', 'INTEGER', 'REQUIRED', 'The number of times this word appears in this corpus.', ()), SchemaField('corpus', 'STRING', 'REQUIRED', 'The work from which this word was extracted.', ()), SchemaField('corpus_date', 'INTEGER', 'REQUIRED', 'The year in which this corpus was published.', ())]
我试图仅以类似格式捕获模式的地方
Where I am trying to capture schema only in the format like
'word' 'STRING','word_count' INTEGER'
是否可以使用API调用或其他任何方法来获取此信息?
Is there any way to get this using API call or any other method?
推荐答案
查看全文