BigQuery更新如何获取更新的行数 [英] BigQuery update how to get number of updated rows

查看:50
本文介绍了BigQuery更新如何获取更新的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Cloud Functions连接到Google Bigquery数据库并更新一些行.cloud函数是使用Python 3编写的.

I am using Google Cloud Functions to connect to a Google Bigquery database and update some rows. The cloud function is written using Python 3.

每当我通过该函数运行update dml时,我都需要帮助弄清楚如何获取结果消息或更新/更改的行数.有任何想法吗?

I need help figuring out how to get the result message or the number of updated/changed rows whenever I run an update dml through the function. Any ideas?

from google.cloud import bigquery

def my_update_function(context,data):

    BQ = bigquery.Client()
    query_job = BQ.query("Update table set etc...")
    rows = query_job.result()
    return (rows)

我知道行总是作为_emptyrowiterator对象返回.我可以得到结果或结果消息的任何方式吗?文档说我必须从bigquery作业方法中获取它.但似乎无法弄清楚.

I understand that rows always come back as _emptyrowiterator object. Any way i can get result or result message? Documentation says I have to get it from a bigquery job method. But can't seem to figure it out.

推荐答案

我认为您正在搜索 QueryJob.num_dml_affected_rows .它包含受update或任何其他DML语句影响的行数.如果只是将其粘贴到代码中,而不是在 return 语句中将其粘贴到代码中,则将获得数字int或创建类似以下内容的消息:

I think that you are searching for QueryJob.num_dml_affected_rows. It contain number of rows affected by update or any other DML statement. If you just paste it to your code instead of rows in return statement you will get number as int or you can create some massage like :

return("Number of updated rows: " + str(job_query.num_dml_affected_rows))

我希望它会有所帮助:)

I hope it will help :)

这篇关于BigQuery更新如何获取更新的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆