我们可以从Google BigQuery中的特定表中获取列名吗?
让我知道对此活动的查询。
我尝试了这个但是没有结果......
SELECT column_name FROM publicdata:samples.shakespeare
OR
SELECT schema FROM publicdata:samples.shakespeare
答案 0 :(得分:3)
我使用Java得到了结果:
Tables tableRequest = bigquery.tables();
Table table = tableRequest.get(projectName,datasetName,tableName).execute();
List<TableFieldSchema> fields = table.getSchema().getFields();
答案 1 :(得分:2)
1.您可以使用命令行工具(https://developers.google.com/bigquery/bq-command-line-tool#gettable): bq show:。
$ bq show publicdata:samples.shakespeare
tableId Last modified Schema
------------- ----------------- ------------------------------------
shakespeare 01 Sep 13:46:28 |- word: string (required)
|- word_count: integer (required)
|- corpus: string (required)
|- corpus_date: integer (required)
2.BigQuery Browser Tool:https://developers.google.com/bigquery/bigquery-browser-tool#examineschema
3.或者使用BigQuery API:https://developers.google.com/bigquery/docs/reference/v2/tables/get
答案 2 :(得分:0)
如果我理解正确,你想做table.list或tables.get而不是jobs.query。
这是谷歌应用程序脚本中的工作原理:
var results = BigQuery.Tables.list(projectId, datasetId, optionalArgs);
或通过API:
GET https://www.googleapis.com/bigquery/v2/projects/projectId/datasets/datasetId/tables
https://developers.google.com/bigquery/docs/reference/v2/tables/list
GET https://www.googleapis.com/bigquery/v2/projects/projectId/datasets/datasetId/tables/tableId
https://developers.google.com/bigquery/docs/reference/v2/tables/get
否则,您可以查询此SELECT * FROM []限制1并编写一些查看列名称的过程。
答案 3 :(得分:0)
在Jupyter中使用python的示例:
SERVICE_ACCOUNT = 'sa_bq.json'
!pip install google-cloud
!pip install google-api-python-client
!pip install oauth2client
from google.cloud import bigquery
client_bq = bigquery.Client.from_service_account_json(SERVICE_ACCOUNT)
table = client_bq.get_table('bigquery-public-data.samples.shakespeare')
print(list(c.name for c in table.schema))
答案 4 :(得分:0)
在经典界面上,无需任何查询,您可以按照以下步骤操作:
publicdata:samples.shakespeare
,则项目为publicdata
)答案 5 :(得分:0)
使用INFORMATION_SCHEMA通过SQL获取列名:
SELECT column_name, data_type
FROM `bigquery-public-data.samples.INFORMATION_SCHEMA.COLUMNS`
WHERE table_name = 'shakespeare'
它给您:
+-------------+-----------+
| column_name | data_type |
+-------------+-----------+
| word | STRING |
| word_count | INT64 |
| corpus | STRING |
| corpus_date | INT64 |
+-------------+-----------+