【发布时间】:2019-12-08 21:13:33
【问题描述】:
我修改了“Google Cloud 函数”服务的默认 hello_pubsub (Python3.7) 函数,用于连接到我在“Google Cloud BigQuery”服务中创建的数据集表。但是,经过许多不同的方法,我对如何使这个函数连接到我在 BigQuery 中创建的数据集一无所知。我确信只有函数的 SQLite 代码有错误。有人,请帮助我
我的代码是:
import sqlite3
import base64
def hello_pubsub(event, context):
"""Triggered from a message on a Cloud Pub/Sub topic.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
connection = sqlite3.connect("<BigQueryDataset>")
crsr = connection.cursor()
crsr.execute("SELECT * FROM `iotcoretutorial-xxxxxx.DHT11.DHT11Data` WHERE temperature > 24")
ans= crsr.fetchall()
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
print("Hello "+pubsub_message)
print(ans)
PS:这里iotcoretutorial-xxxxxx指的是项目ID。我使用 xxxxxx 来隐藏我的项目的身份(请多多包涵!)
简而言之,iotcoretutorial-xxxxxx.DHT11.DHT11Data 是我在“Google Cloud BigQuery”上创建的带有温度和湿度值的表,我想使用 hello_pubsub打印它> 如果温度值 > 24 则运行并执行一些操作
【问题讨论】:
-
您为什么要尝试使用
sqlite3库连接到bigquery数据集?你应该看看BigQuery Client Libraries -
我建议您更改标题。这对您现在没有帮助,将来也不会帮助其他任何人。
标签: python-3.x google-cloud-platform google-bigquery google-cloud-functions google-cloud-iot