Skip to content

fix(spannerdriver): populate QueryStats in ResultSetStats - #778

Merged
olavloite merged 4 commits into
googleapis:mainfrom
apstndb:forward-resultset-querystats
Apr 13, 2026
Merged

fix(spannerdriver): populate QueryStats in ResultSetStats#778
olavloite merged 4 commits into
googleapis:mainfrom
apstndb:forward-resultset-querystats

Conversation

@apstndb

@apstndb apstndb commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Populate ResultSetStats.QueryStats in createResultSetStats (transaction.go) from spanner.RowIterator.QueryStats, which is already filled from the last PartialResultSet in the stream. This lets database/sql callers surface execution stats (e.g. elapsed_time) like the native client.

Issue

Fixes #779

@apstndb
apstndb requested a review from a team as a code owner March 30, 2026 16:15
The last PartialResultSet carries Stats.QueryStats; RowIterator already
exposes it as QueryStats. Populate ResultSetStats.QueryStats from that map
so database/sql callers receive query_stats (e.g. elapsed_time).
@apstndb
apstndb force-pushed the forward-resultset-querystats branch from 09ab721 to 47245ca Compare March 30, 2026 16:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates transaction.go to populate ResultSetStats.QueryStats from the RowIterator's QueryStats map using structpb.NewStruct. The feedback suggests logging a warning when the conversion to structpb.Struct fails, rather than silently ignoring the error, to ensure visibility into potential data issues.

Comment thread transaction.go Outdated
Comment on lines +100 to +102
if s, err := structpb.NewStruct(it.QueryStats); err == nil {
stats.QueryStats = s
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error from structpb.NewStruct is silently ignored. This could hide issues with query stats conversion, leading to incomplete statistics without any indication of a problem. It would be better to log this error for debugging purposes.

Suggested change
if s, err := structpb.NewStruct(it.QueryStats); err == nil {
stats.QueryStats = s
}
if s, err := structpb.NewStruct(it.QueryStats); err != nil {
slog.Warn("Failed to convert QueryStats to structpb.Struct", "error", err)
} else {
stats.QueryStats = s
}

@apstndb apstndb changed the title Forward RowIterator QueryStats into ResultSetStats fix(spannerdriver): populate QueryStats in ResultSetStats Mar 30, 2026
Log a slog warning if structpb.NewStruct cannot represent the map from
RowIterator.QueryStats, per review feedback.
@apstndb

apstndb commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

Addressed @gemini-code-assist review: on structpb.NewStruct failure we now emit slog.Warn with the error instead of silently skipping QueryStats (see follow-up commit).

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Thank you for the update, @apstndb. Using slog.Warn to log the conversion error is a good approach to ensure visibility into potential issues without failing the entire operation. This looks correct.

@olavloite
olavloite merged commit 7e8b1fe into googleapis:main Apr 13, 2026
38 of 40 checks passed
@apstndb
apstndb deleted the forward-resultset-querystats branch April 13, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Populate QueryStats in ResultSetStats

3 participants