有没有人在 Python 中使用 StreamedResultSet 查询过 Google Spanner
Has anyone queried Google Spanner using StreamedResultSet in Python
我想从扳手中提取一个巨大的 table,而不是常规的 execute_sql 函数,我希望流式传输数据。但是我没有看到很多关于它的文档。
我正在使用 google 云 python 库,但我也找不到解决方案
有人试过吗?
import os,sys
import subprocess
import glob
from os import path
from google.cloud.spanner_v1.streamed import StreamedResultSet
def run_quickstart():
# [START spanner_quickstart]
# Imports the Google Cloud Client Library.
from google.cloud import spanner
# Instantiate a client.
spanner_client = spanner.Client.from_service_account_json('<stripped Auth Key>')
# Your Cloud Spanner instance ID.
instance_id = 'spannereval'
# Get a Cloud Spanner instance by ID.
instance = spanner_client.instance(instance_id)
# Your Cloud Spanner database ID.
database_id = 'ias-ei-test'
# Get a Cloud Spanner database by ID.
database = instance.database(database_id)
# Execute a simple SQL statement.
with database.snapshot() as snapshot:
results = snapshot.execute_sql('SELECT * from product_inventory_status')
for row in results:
print(row)
# [END spanner_quickstart]
您拥有的代码正在后台流式传输。
在此处查看从 execute_sql 返回的 StreamedResultSet:https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/spanner/google/cloud/spanner_v1/snapshot.py#L144
我想从扳手中提取一个巨大的 table,而不是常规的 execute_sql 函数,我希望流式传输数据。但是我没有看到很多关于它的文档。
我正在使用 google 云 python 库,但我也找不到解决方案
有人试过吗?
import os,sys
import subprocess
import glob
from os import path
from google.cloud.spanner_v1.streamed import StreamedResultSet
def run_quickstart():
# [START spanner_quickstart]
# Imports the Google Cloud Client Library.
from google.cloud import spanner
# Instantiate a client.
spanner_client = spanner.Client.from_service_account_json('<stripped Auth Key>')
# Your Cloud Spanner instance ID.
instance_id = 'spannereval'
# Get a Cloud Spanner instance by ID.
instance = spanner_client.instance(instance_id)
# Your Cloud Spanner database ID.
database_id = 'ias-ei-test'
# Get a Cloud Spanner database by ID.
database = instance.database(database_id)
# Execute a simple SQL statement.
with database.snapshot() as snapshot:
results = snapshot.execute_sql('SELECT * from product_inventory_status')
for row in results:
print(row)
# [END spanner_quickstart]
您拥有的代码正在后台流式传输。 在此处查看从 execute_sql 返回的 StreamedResultSet:https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/spanner/google/cloud/spanner_v1/snapshot.py#L144