BigQuery - 获取BigQuery表中的总列数 [英] BigQuery - Get the total number of columns in a BigQuery table
本文介绍了BigQuery - 获取BigQuery表中的总列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有几种方法可以做到这一点:
A。使用 BQ 命令行工具以及 JQ linux库来解析JSON。
bq --format = json show publicdata:samples.shakespeare | jq'.schema.fields |长度'
这一点:
<$ p $ B> 4
B。使用REST API执行表格:获取电话
p> GET https://www.googleapis.com/bigquery/v2/projects/projectId/datasets/datasetId/tables/tableId
这将返回一个完整的JSON,您可以解析和查询schema.field的长度。
{
kind:bigquery#table,
description:这个数据集是,
creationTime:1335916045099,
tableReference:{
projectId:publicdata ,
tableId:shakespeare,
datasetId:samples
},
numRows:164656,
numBytes :6432064,
etag:\E7ZNanj79wmDHI9DmeCWoYoUpAE / MTQxMzkyNjgyNzI1Nw\,
lastModifiedTime:1413926827257,
type:TABLE,
id:publicdata:samples。莎士比亚,
selfLink:https://www.googleapis.com/bigquery/v2/projects/publicdata/datasets/samples/tables/shakespeare,
schema:{
字段:[
{
description:从语料库中提取的一个唯一的单词(其中空格是分隔符)。,
type:STRING ,
name:word,
mode:REQUIRED
},
{
description: ,
type:INTEGER,
name:word_count,
mode:REQUIRED
},
$ bdescription:从中抽取这个单词的工作,
type:STRING,
name:语料库,
mode:REQUIRED
},
{
description:此语料库发布的年份。,
type:INTEGER ,
name:corpus_date,
mode:必需
}
]
}
}
Is there a way to query the total number of columns in a BigQuery table? I went through the BigQuery documentation but did not find anything relevant.
Thanks in advance!
解决方案
There are a couple of ways to do this:
A. Using the BQ command line tool, and the JQ linux library to parse JSON.
bq --format=json show publicdata:samples.shakespeare | jq '.schema.fields | length'
This outpus:
4
B. Using the REST api to do a Tables:get call
GET https://www.googleapis.com/bigquery/v2/projects/projectId/datasets/datasetId/tables/tableId
this returns a full JSON, that you can parse and query for schema.field length.
{
"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"
}
]
}
}
这篇关于BigQuery - 获取BigQuery表中的总列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文