如何在 python 中打印 bigquery 的计数 table 查询?
How to print count table query of bigquery in python?
我正在尝试打印 python 中 bigquery table 中可用的行数,我编写了以下代码:
from google.cloud import bigquery def main():
myquery = "select count(*) from `myproject.mydataset.mytable`"
client = bigquery.Client()
job = client.query(myquery)
result = job.result()
print("Total rows available: ",result)
当我执行上面的代码时,它给我输出
"Total rows available: google.cloud.bigquery.table.RowIterator object
at 0x00000247B65F29E8>".
这意味着我正在获取对象值作为我的输出。
但是我想打印 table(query result) 中可用的实际行数。
RowIterator
has an attribute called total_rows
.
只需将您的最后一条语句更改为
print("Total rows available: ", result.total_rows)
尝试将您的查询更改为
myquery = "select count(*) size from `myproject.mydataset.mytable`"
client = bigquery.Client()
job = client.query(myquery)
result = job.result()
for row in results:
print("Total rows available: ",row.size)
我正在尝试打印 python 中 bigquery table 中可用的行数,我编写了以下代码:
from google.cloud import bigquery def main():
myquery = "select count(*) from `myproject.mydataset.mytable`"
client = bigquery.Client()
job = client.query(myquery)
result = job.result()
print("Total rows available: ",result)
当我执行上面的代码时,它给我输出
"Total rows available: google.cloud.bigquery.table.RowIterator object at 0x00000247B65F29E8>".
这意味着我正在获取对象值作为我的输出。 但是我想打印 table(query result) 中可用的实际行数。
RowIterator
has an attribute called total_rows
.
只需将您的最后一条语句更改为
print("Total rows available: ", result.total_rows)
尝试将您的查询更改为
myquery = "select count(*) size from `myproject.mydataset.mytable`"
client = bigquery.Client()
job = client.query(myquery)
result = job.result()
for row in results:
print("Total rows available: ",row.size)