Skip to content

Decode metadata and values of PartialResultSet #1316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xxntti3n opened this issue Mar 2, 2025 · 1 comment
Closed

Decode metadata and values of PartialResultSet #1316

xxntti3n opened this issue Mar 2, 2025 · 1 comment
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner API.

Comments

@xxntti3n
Copy link

xxntti3n commented Mar 2, 2025

Hello everyone,
I am reading the change stream from Spanner using the Spanner client. I attempted to use StreamedResultSet, but I'm having trouble resolving it. Could someone please help me with mapping the metadata and values from the results when I run execute_streaming_sql? Thank you!
request = spanner_v1.ExecuteSqlRequest( session=session.name, sql=f"SELECT * FROM READ_spanner_all_change_stream( start_timestamp => '{current_time}', end_timestamp => NULL, partition_token => NULL, heartbeat_milliseconds => 10000)", ) result_set = spanner_client.execute_streaming_sql(request=request)

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner API. label Mar 2, 2025
@olavloite
Copy link
Contributor

@xxntti3n It is highly recommended that you just use the standard query functions in the client library. These already use the execute_streaming_sql RPC under the hood and hide the details of mapping the returned PartialResultSets and metadata into easy-to-consume objects. So just follow this example:

with database.snapshot() as snapshot:

Note that if you specifically want to access the underlying protobuf values instead of having them converted to Python types, then you can set the lazy_decoding argument like this:

  with database.snapshot() as snapshot:
      results = snapshot.execute_sql(
          "SELECT SingerId, AlbumId, AlbumTitle FROM Albums",
          lazy_decode=True
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner API.
Projects
None yet
Development

No branches or pull requests

3 participants