如何使用python API在bigquery中创建新视图? [英] How can I create a new view in bigquery using the python API?

查看:95
本文介绍了如何使用python API在bigquery中创建新视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码会自动生成一堆不同的SQL查询,我想插入到bigquery中来生成视图,但我的问题之一是这些视图需要每天晚上动态生成,因为数据性质的变化。所以我想能够做的就是使用谷歌bigquery api for python来制作视图。我知道如何使用'bq'命令行工具来做到这一点,但我希望能够直接将其内置到代码中,而不是使用shell来运行bq。我使用了
$ b

https://cloud.google.com/bigquery/bigquery-api-quickstart



我不明白如何使用这一段代码创建一个视图,而不是仅返回SELECT语句的结果。我可以在这里看到有关执行表插入的文档。



https://cloud.google.com/bigquery/docs/reference/v2/tables/insert



但那指的是使用REST API生成新表,而不是上面提供的示例。



这难道不可能吗?我应该放弃并使用bq吗?



谢谢

***对Felipe's注释。

表格资源文档指出有很多必填字段,其中一些字段是有意义的,即使我没有完全理解他们要求的内容,其他人没有。例如,externalDataConfiguration.schema。这是否涉及我连接到的数据库的模式(我假设它)或用于存储数据的模式?



externalDataConfiguration.sourceFormat怎么样?由于我试图查看预先存在的数据库,因此我不确定我是否了解源格式的相关性。它是我正在制作视图的数据库的源格式吗?我如何识别?



和externalDataConfiguration.sourceUris [],我没有导入新的数据到数据库,所以我不明白这是如何(或以前的元素)是必需的。

模式怎么样?

tableReference.datasetId,tableReference.projectId和tableReference.tableId是不言自明的。

类型应该是view,而view.query将是用于制作视图的实际sql查询。所以我明白为什么这些都是制作视图所必需的,但我不了解其他部分。



你能帮我理解这些细节吗?



感谢,
Brad

解决方案

所有Web UI或bq工具)是通过BigQuery API完成的,所以不要放弃:)。

创建一个视图类似于创建一个表,只要确保有一个表当您调用 tables.insert()时包含视图属性的资源。




I have some code that automatically generates a bunch of different SQL queries that I would like to insert into the bigquery to generate views, though one of the issues that I have is that these views need to be generated dynamically every night because of the changing nature of the data. So what I would like to be able to do is use the google bigquery api for python to be able to make a view. I understand how to do it using the 'bq' command line tool, but I'd like to be able to have this built directly into the code as opposed to using a shell to run bq. I have played with the code provided at

https://cloud.google.com/bigquery/bigquery-api-quickstart

I don't understand how to use this bit of code to create a view instead of just returning the results of a SELECT statement. I can see the documentation about doing table inserts here

https://cloud.google.com/bigquery/docs/reference/v2/tables/insert

but that refers to using the REST API to generate new tables as opposed to the example provided above.

Is it just not possible? Should I just give in and use bq?

Thanks

*** Some additional questions in response to Felipe's comments.

The table resource document indicates that there are a number of required fields, some of which make sense even if I don't fully understand what they're asking for, others do not. For example, externalDataConfiguration.schema. Does this refer to the schema for the database that I'm connecting to (I assume it does), or the schema for storing the data?

What about externalDataConfiguration.sourceFormat? Since I'm trying to make a view of a pre-existing database, I'm not sure I understand how the source format is relevant. Is it the source format of the database I'm making a view from? How would I identify that?

ANd externalDataConfiguration.sourceUris[], I'm not importing new data into the database, so I don't understand how this (or the previous element) are required.

What about schema?

tableReference.datasetId, tableReference.projectId, and tableReference.tableId are self explanatory.

Type would be view, and view.query would be the actual sql query used to make the view. So I get why those are required for making a view, but I don't understand the other parts.

Can you help me understand these details?

Thanks, Brad

解决方案

Everything that web UI or the bq tool does is made through the BigQuery API, so don't give up yet :).

Creating a view is akin to creating a table, just be sure to have a table resource that contains a view property when you call tables.insert().

这篇关于如何使用python API在bigquery中创建新视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆