是否可以在python客户端中调用BigQuery过程?

问题描述 投票:0回答:1

BigQuery的脚本/过程刚刚在beta中发布-是否可以使用BigQuery python客户端来调用过程?

我尝试过:

query = """CALL `myproject.dataset.procedure`()...."""
job = client.query(query, location="US",)
print(job.results())
print(job.ddl_operation_performed)

print(job._properties) but that didn't give me the result set from the procedure. Is it possible to get the results?

谢谢!

google-bigquery google-api-python-client
1个回答
0
投票

如果过程中包含SELECT,则该过程有效:

create or replace procedure dataset.proc_output() BEGIN
  SELECT t FROM UNNEST(['1','2','3']) t;
END;

代码:

from google.cloud import bigquery
client = bigquery.Client()
query = """CALL dataset.proc_output()"""
job = client.query(query, location="US")
for result in job.result():
        print result

将输出:

Row((u'1',), {u't': 0})
Row((u'2',), {u't': 0})
Row((u'3',), {u't': 0})

但是,如果过程中有多个SELECT,则只能以这种方式获取最后一个结果集。

© www.soinside.com 2019 - 2024. All rights reserved.