相关疑难解决方法(0)

Python BigQuery API-获取表架构

我试图获取架构形式的bigquery表。给定一个示例代码,例如

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)
Run Code Online (Sandbox Code Playgroud)

这是返回值,例如:

[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', …

python-3.x google-bigquery google-cloud-datastore google-cloud-platform

4
推荐指数
1
解决办法
3740
查看次数