简体   繁体   English

如何在app引擎和python上使用Bigquery流媒体插件

[英]How to use Bigquery streaming insertall on app engine & python

I would like to develop an app engine application that directly stream data into a BigQuery table. 我想开发一个直接将数据流传输到BigQuery表的应用程序引擎应用程序。

According to Google's documentation there is a simple way to stream data into bigquery: 根据谷歌的文档,有一种简单的方法可以将数据流式传输到bigquery:

Here is the sample code snippet on how streaming insert should be coded: 以下是有关如何编码流式插入的示例代码段:

body = {"rows":[
{"json": {"column_name":7.7,}}
]}

response = bigquery.tabledata().insertAll(
   projectId=PROJECT_ID,
   datasetId=DATASET_ID,
   tableId=TABLE_ID,
   body=body).execute()

Although I've downloaded the client api I didn't find any reference to a "bigquery" module/object referenced in the above Google's example. 虽然我已经下载了客户端api,但我没有找到任何对上述Google示例中引用的“bigquery”模块/对象的引用。

Where is the the bigquery object (from snippet) should be located? 应该找到bigquery对象(来自代码段)的位置?

Can anyone show a more complete way to use this snippet (with the right imports)? 任何人都可以展示更完整的方式来使用这个片段(使用正确的导入)?

I've Been searching for that a lot and found documentation confusing and partial. 我一直在寻找那么多,发现文档令人困惑和偏袒。

Minimal working (as long as you fill in the right ids for your project) example: 最小化工作(只要您为项目填写正确的ID)示例:

import httplib2
from apiclient import discovery
from oauth2client import appengine

_SCOPE = 'https://www.googleapis.com/auth/bigquery'

# Change the following 3 values:
PROJECT_ID = 'your_project'
DATASET_ID = 'your_dataset'
TABLE_ID = 'TestTable'


body = {"rows":[
    {"json": {"Col1":7,}}
]}

credentials = appengine.AppAssertionCredentials(scope=_SCOPE)
http = credentials.authorize(httplib2.Http())

bigquery = discovery.build('bigquery', 'v2', http=http)
response = bigquery.tabledata().insertAll(
   projectId=PROJECT_ID,
   datasetId=DATASET_ID,
   tableId=TABLE_ID,
   body=body).execute()

print response

As Jordan says: "Note that this uses the appengine robot to authenticate with BigQuery, so you'll to add the robot account to the ACL of the dataset. Note that if you also want to use the robot to run queries, not just stream, you need the robot to be a member of the project 'team' so that it is authorized to run jobs." 正如乔丹所说:“请注意,这会使用appengine机器人对BigQuery进行身份验证,因此您需要将机器人帐户添加到数据集的ACL中。请注意,如果您还想使用机器人运行查询,而不仅仅是流,您需要机器人成为项目“团队”的成员,以便授权他们运行工作。“

Here is a working code example from an appengine app that streams records to a BigQuery table. 这是一个将记录流式传输到BigQuery表的appengine应用程序的工作代码示例。 It is open source at code.google.com: 它是code.google.com上的开源代码:

http://code.google.com/p/bigquery-e2e/source/browse/sensors/cloud/src/main.py#124 http://code.google.com/p/bigquery-e2e/source/browse/sensors/cloud/src/main.py#124

To find out where the bigquery object comes from, see http://code.google.com/p/bigquery-e2e/source/browse/sensors/cloud/src/config.py 要查找bigquery对象的来源,请参阅http://code.google.com/p/bigquery-e2e/source/browse/sensors/cloud/src/config.py

Note that this uses the appengine robot to authenticate with BigQuery, so you'll to add the robot account to the ACL of the dataset. 请注意,这使用appengine机器人对BigQuery进行身份验证,因此您将把机器人帐户添加到数据集的ACL中。

Note that if you also want to use the robot to run queries, not just stream, you need to robot to be a member of the project 'team' so that it is authorized to run jobs. 请注意,如果您还想使用机器人来运行查询,而不仅仅是流,那么您需要让机器人成为项目“团队”的成员,以便它有权运行作业。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将Google App Engine中的insertAll用于BigQuery时出现HTTP 501错误 - HTTP 501 error when trying to use insertAll from Google App Engine to BigQuery BigQuery-时间戳偏移不能与insertAll /流一起使用? - BigQuery - timestamp offset not working with insertAll / Streaming? BigQuery流式insertIn似乎丢失了数据-为什么? - BigQuery streaming insertAll appears to lose data - why? 如何在Python中通过App Engine在Google BigQuery上创建架构? - How to create a schema on Google BigQuery from App Engine in Python? 如何在Google App Engine(Python)上获得对流URL的响应 - How to get a response for a streaming url on google app engine (python) 在Python中使用BigQuery接收器流式传输管道 - Streaming pipelines with BigQuery sinks in python 如何通过Google App Engine Python将OAuth用于用户名和密码 - How to use OAuth for username and password with Google App Engine Python Google App引擎-Python:如何使用命名空间和祖先? - Google app engine - Python: How to use Namespaces and Ancestors? 如何在Google App Engine的python中使用bdutil和gcloud? - How to use bdutil and gcloud in python on Google App Engine? 如何在Google App Engine Python中使用Google Cloud Vision? - How to use google cloud vision with Google App Engine Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM