【发布时间】:2020-11-19 05:52:44
【问题描述】:
我希望通过 GCP 中的 Cloud Function 向 BigQuery 创建 HTTP 请求,其中请求传递一个值,该值传递给查询,另一个值从连接表返回。 SQL 在 BQ 中工作,但在将其应用于 Cloud Function 时无法返回值。
这也是我正在使用的卷曲。
https://us-central1-something.cloudfunctions.net/something/something2?client_Id=823754783.2
提前致谢。
from flask import escape
from google.cloud import bigquery
def cors_enabled_function(request):
if request.method == 'OPTIONS':
headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600'
}
return ('', 204, headers)
client = bigquery.Client()
def something2(request):
request_json = request.get_json(silent=True)
request_args = request_args
table = ['`audience-cookie.ecommerce.traffic` as traffic JOIN `audience-cookie.ecommerce.cardholder` as cardholder ON traffic.customerId = cardholder.customerId']
QUERY = ('SELECT '+cardholder+' from `'+table+'` WHERE client_Id='+client_Id)
try:
query_job = client.query(QUERY)
rows = query_job.result()
row_list = []
for row in rows:
row_list.append(str(row[cardholder]))
return("<p>"+"</p><p>".join(row(row_list) + "</p>"))
except e:
return(e)
【问题讨论】:
标签: google-cloud-platform google-bigquery google-cloud-functions httprequest