有人尝试过通过Cloud Function执行存储在gs:// bucket中的BigQuery脚本吗?
我找不到任何文档。
谢谢。
答案 0 :(得分:0)
使用Python:
# Function dependencies, for example:
# package>=version
google-cloud-bigquery
google-cloud-storage
from google.cloud import bigquery
from google.cloud import storage
import base64
def execute-sql-scripts(request):
client = bigquery.Client(project='bigquery-project-id')
# Read query from GCS bucket.
gcs_client = storage.Client('storage-project-id')
query = read_sql(gcs_client,'bucket-name')
job = client.query(query)
result = job.result()
def read_sql(gcs_client, bucket_id):
bucket = gcs_client.get_bucket(bucket_id)
blob = bucket.get_blob("update-script.sql")
contents = blob.download_as_string()
return contents.decode('utf-8')