【问题标题】:HTTPrequest to GCP BigQuery via Cloud Function with Multiple Tables通过具有多个表的 Cloud Function 向 GCP BigQuery 发出 HTTP 请求
【发布时间】: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


    【解决方案1】:

    我建议您打印您的查询。有几个错误

    • 为什么在table var 定义中使用 []?
    • 您在表中和在查询中插入表时使用反引号`。所以,最后,你有一个双反引号
    • client_Id 未在您的代码中定义

    【讨论】:

      猜你喜欢
      • 2018-09-13
      • 1970-01-01
      • 2018-11-09
      • 2019-08-21
      • 2020-11-30
      • 2021-07-13
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      相关资源
      最近更新 更多