gpt4 book ai didi

google-bigquery - BigQuery-获取BigQuery表中的总列数

转载 作者:行者123 更新时间:2023-12-04 18:05:17 25 4
gpt4 key购买 nike

有没有办法查询BigQuery表中的列总数?我浏览了BigQuery文档,但没有找到任何相关内容。

提前致谢!

最佳答案

有两种方法可以做到这一点:

A.使用BQ命令行工具和JQ linux库来解析JSON。

bq --format=json show publicdata:samples.shakespeare | jq '.schema.fields | length'

这个出乎意料:
4

B.使用REST API进行 Tables:get调用
GET https://www.googleapis.com/bigquery/v2/projects/projectId/datasets/datasetId/tables/tableId

这将返回完整的JSON,您可以解析和查询schema.field的长度。
{
"kind":"bigquery#table",
"description":"This dataset is a word index of the works of Shakespeare, giving the number of times each word appears in each corpus.",
"creationTime":"1335916045099",
"tableReference":{
"projectId":"publicdata",
"tableId":"shakespeare",
"datasetId":"samples"
},
"numRows":"164656",
"numBytes":"6432064",
"etag":"\"E7ZNanj79wmDHI9DmeCWoYoUpAE/MTQxMzkyNjgyNzI1Nw\"",
"lastModifiedTime":"1413926827257",
"type":"TABLE",
"id":"publicdata:samples.shakespeare",
"selfLink":"https://www.googleapis.com/bigquery/v2/projects/publicdata/datasets/samples/tables/shakespeare",
"schema":{
"fields":[
{
"description":"A single unique word (where whitespace is the delimiter) extracted from a corpus.",
"type":"STRING",
"name":"word",
"mode":"REQUIRED"
},
{
"description":"The number of times this word appears in this corpus.",
"type":"INTEGER",
"name":"word_count",
"mode":"REQUIRED"
},
{
"description":"The work from which this word was extracted.",
"type":"STRING",
"name":"corpus",
"mode":"REQUIRED"
},
{
"description":"The year in which this corpus was published.",
"type":"INTEGER",
"name":"corpus_date",
"mode":"REQUIRED"
}
]
}
}

关于google-bigquery - BigQuery-获取BigQuery表中的总列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30361414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com