如何使用标准SQL定义BigQuery模式? [英] How to define BigQuery schema using Standard SQL?
本文介绍了如何使用标准SQL定义BigQuery模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一个新项目中使用BigQuery标准SQL,但是我无法找到关于如何定义模式的任何示例,而是指向Legacy SQL的所有内容。特别是,我想用 ARRAY
和 STRUCT
。
I'd like to use BigQuery Standard SQL in a new project, however I am not able to find any examples on how to define the schema, everything points at Legacy SQL. In particular, I want to use ARRAY
and STRUCT
.
推荐答案
在BigQuery中创建表的一种方法是使用API调用。没有CREATE表语法。
One way to create a table in BigQuery is by using the API calls. There is no CREATE table syntax.
创建表格
BigQuery提供了多种方式来创建新表格详细内容在这里:
BigQuery offers various ways to create a new table as detailed here:
- 您可以使用命令行工具的bq mk命令或使用BigQuery API tables.insert()方法创建空表。
- 您可以加载来自CSV或JSON数据文件(压缩或未压缩),Avro文件或云数据存储备份的表。
- 您可以从查询结果创建表。 li>
- 您可以复制表格
- 您可以在Cloud Storage中的文件上定义表格
- 标准的SQL类型,当你定义你的表模式时(参见Elliotts答案),还有一个关于在文档中更新的tichet。投票/星级此处。
- You can create an empty table by using the command line tool's bq mk command or by using the BigQuery API tables.insert() method.
- You can load a table from a CSV or JSON data file (compressed or uncompressed), from an Avro file, or from a Cloud Datastore backup.
- You can create a table from a query result.
- You can copy a table
- You can define a table over a file in Cloud Storage
- you can use Standard SQL types when you define your table schema (see Elliotts answer) and there is a tichet about to update in docs as well. Vote/star here.
很多 Python样本在GitHub上简单:
lots of Python samples are on GitHub simple as:
def create_table(dataset_name, table_name, project=None):
"""Creates a simple table in the given dataset.
If no project is specified, then the currently active project is used.
"""
bigquery_client = bigquery.Client(project=project)
dataset = bigquery_client.dataset(dataset_name)
if not dataset.exists():
print('Dataset {} does not exist.'.format(dataset_name))
return
table = dataset.table(table_name)
# Set the table schema
table.schema = (
bigquery.SchemaField('Name', 'STRING'),
bigquery.SchemaField('Age', 'INTEGER'),
bigquery.SchemaField('Weight', 'FLOAT'),
)
table.create()
print('Created table {} in dataset {}.'.format(table_name, dataset_name))
这篇关于如何使用标准SQL定义BigQuery模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文