@@ -5,7 +5,7 @@ use prost_types::{value::Kind, Value};
55
66use google_cloud_gax:: grpc:: { Code , Response , Status , Streaming } ;
77use google_cloud_googleapis:: spanner:: v1:: struct_type:: Field ;
8- use google_cloud_googleapis:: spanner:: v1:: { ExecuteSqlRequest , PartialResultSet , ReadRequest , ResultSetMetadata } ;
8+ use google_cloud_googleapis:: spanner:: v1:: { ExecuteSqlRequest , PartialResultSet , ReadRequest , ResultSetMetadata , ResultSetStats } ;
99
1010use crate :: row:: Row ;
1111use crate :: session:: SessionHandle ;
@@ -186,6 +186,7 @@ where
186186 reader : T ,
187187 rs : ResultSet ,
188188 reader_option : Option < CallOptions > ,
189+ stats : Option < ResultSetStats > ,
189190}
190191
191192impl < ' a , T > RowIterator < ' a , T >
@@ -210,6 +211,7 @@ where
210211 reader,
211212 rs,
212213 reader_option : None ,
214+ stats : None ,
213215 } )
214216 }
215217
@@ -241,6 +243,10 @@ where
241243 if !result_set. resume_token . is_empty ( ) {
242244 self . reader . update_token ( result_set. resume_token ) ;
243245 }
246+ // Capture stats if present (only sent with the last response)
247+ if result_set. stats . is_some ( ) {
248+ self . stats = result_set. stats ;
249+ }
244250 self . rs
245251 . add ( result_set. metadata , result_set. values , result_set. chunked_value )
246252 }
@@ -262,6 +268,13 @@ where
262268 None
263269 }
264270
271+ /// Returns query execution statistics if available.
272+ /// Stats are only available after all rows have been consumed and only when
273+ /// the query was executed with a QueryMode that includes stats (Profile, WithStats, or WithPlanAndStats).
274+ pub fn stats ( & self ) -> Option < & ResultSetStats > {
275+ self . stats . as_ref ( )
276+ }
277+
265278 /// next returns the next result.
266279 /// Its second return value is None if there are no more results.
267280 pub async fn next ( & mut self ) -> Result < Option < Row > , Status > {
0 commit comments