result_set.proto 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // Copyright 2022 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.spanner.v1;
  16. import "google/protobuf/struct.proto";
  17. import "google/spanner/v1/query_plan.proto";
  18. import "google/spanner/v1/transaction.proto";
  19. import "google/spanner/v1/type.proto";
  20. option cc_enable_arenas = true;
  21. option csharp_namespace = "Google.Cloud.Spanner.V1";
  22. option go_package = "google.golang.org/genproto/googleapis/spanner/v1;spanner";
  23. option java_multiple_files = true;
  24. option java_outer_classname = "ResultSetProto";
  25. option java_package = "com.google.spanner.v1";
  26. option php_namespace = "Google\\Cloud\\Spanner\\V1";
  27. option ruby_package = "Google::Cloud::Spanner::V1";
  28. // Results from [Read][google.spanner.v1.Spanner.Read] or
  29. // [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql].
  30. message ResultSet {
  31. // Metadata about the result set, such as row type information.
  32. ResultSetMetadata metadata = 1;
  33. // Each element in `rows` is a row whose format is defined by
  34. // [metadata.row_type][google.spanner.v1.ResultSetMetadata.row_type]. The ith element
  35. // in each row matches the ith field in
  36. // [metadata.row_type][google.spanner.v1.ResultSetMetadata.row_type]. Elements are
  37. // encoded based on type as described
  38. // [here][google.spanner.v1.TypeCode].
  39. repeated google.protobuf.ListValue rows = 2;
  40. // Query plan and execution statistics for the SQL statement that
  41. // produced this result set. These can be requested by setting
  42. // [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode].
  43. // DML statements always produce stats containing the number of rows
  44. // modified, unless executed using the
  45. // [ExecuteSqlRequest.QueryMode.PLAN][google.spanner.v1.ExecuteSqlRequest.QueryMode.PLAN] [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode].
  46. // Other fields may or may not be populated, based on the
  47. // [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode].
  48. ResultSetStats stats = 3;
  49. }
  50. // Partial results from a streaming read or SQL query. Streaming reads and
  51. // SQL queries better tolerate large result sets, large rows, and large
  52. // values, but are a little trickier to consume.
  53. message PartialResultSet {
  54. // Metadata about the result set, such as row type information.
  55. // Only present in the first response.
  56. ResultSetMetadata metadata = 1;
  57. // A streamed result set consists of a stream of values, which might
  58. // be split into many `PartialResultSet` messages to accommodate
  59. // large rows and/or large values. Every N complete values defines a
  60. // row, where N is equal to the number of entries in
  61. // [metadata.row_type.fields][google.spanner.v1.StructType.fields].
  62. //
  63. // Most values are encoded based on type as described
  64. // [here][google.spanner.v1.TypeCode].
  65. //
  66. // It is possible that the last value in values is "chunked",
  67. // meaning that the rest of the value is sent in subsequent
  68. // `PartialResultSet`(s). This is denoted by the [chunked_value][google.spanner.v1.PartialResultSet.chunked_value]
  69. // field. Two or more chunked values can be merged to form a
  70. // complete value as follows:
  71. //
  72. // * `bool/number/null`: cannot be chunked
  73. // * `string`: concatenate the strings
  74. // * `list`: concatenate the lists. If the last element in a list is a
  75. // `string`, `list`, or `object`, merge it with the first element in
  76. // the next list by applying these rules recursively.
  77. // * `object`: concatenate the (field name, field value) pairs. If a
  78. // field name is duplicated, then apply these rules recursively
  79. // to merge the field values.
  80. //
  81. // Some examples of merging:
  82. //
  83. // # Strings are concatenated.
  84. // "foo", "bar" => "foobar"
  85. //
  86. // # Lists of non-strings are concatenated.
  87. // [2, 3], [4] => [2, 3, 4]
  88. //
  89. // # Lists are concatenated, but the last and first elements are merged
  90. // # because they are strings.
  91. // ["a", "b"], ["c", "d"] => ["a", "bc", "d"]
  92. //
  93. // # Lists are concatenated, but the last and first elements are merged
  94. // # because they are lists. Recursively, the last and first elements
  95. // # of the inner lists are merged because they are strings.
  96. // ["a", ["b", "c"]], [["d"], "e"] => ["a", ["b", "cd"], "e"]
  97. //
  98. // # Non-overlapping object fields are combined.
  99. // {"a": "1"}, {"b": "2"} => {"a": "1", "b": 2"}
  100. //
  101. // # Overlapping object fields are merged.
  102. // {"a": "1"}, {"a": "2"} => {"a": "12"}
  103. //
  104. // # Examples of merging objects containing lists of strings.
  105. // {"a": ["1"]}, {"a": ["2"]} => {"a": ["12"]}
  106. //
  107. // For a more complete example, suppose a streaming SQL query is
  108. // yielding a result set whose rows contain a single string
  109. // field. The following `PartialResultSet`s might be yielded:
  110. //
  111. // {
  112. // "metadata": { ... }
  113. // "values": ["Hello", "W"]
  114. // "chunked_value": true
  115. // "resume_token": "Af65..."
  116. // }
  117. // {
  118. // "values": ["orl"]
  119. // "chunked_value": true
  120. // "resume_token": "Bqp2..."
  121. // }
  122. // {
  123. // "values": ["d"]
  124. // "resume_token": "Zx1B..."
  125. // }
  126. //
  127. // This sequence of `PartialResultSet`s encodes two rows, one
  128. // containing the field value `"Hello"`, and a second containing the
  129. // field value `"World" = "W" + "orl" + "d"`.
  130. repeated google.protobuf.Value values = 2;
  131. // If true, then the final value in [values][google.spanner.v1.PartialResultSet.values] is chunked, and must
  132. // be combined with more values from subsequent `PartialResultSet`s
  133. // to obtain a complete field value.
  134. bool chunked_value = 3;
  135. // Streaming calls might be interrupted for a variety of reasons, such
  136. // as TCP connection loss. If this occurs, the stream of results can
  137. // be resumed by re-sending the original request and including
  138. // `resume_token`. Note that executing any other transaction in the
  139. // same session invalidates the token.
  140. bytes resume_token = 4;
  141. // Query plan and execution statistics for the statement that produced this
  142. // streaming result set. These can be requested by setting
  143. // [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode] and are sent
  144. // only once with the last response in the stream.
  145. // This field will also be present in the last response for DML
  146. // statements.
  147. ResultSetStats stats = 5;
  148. }
  149. // Metadata about a [ResultSet][google.spanner.v1.ResultSet] or [PartialResultSet][google.spanner.v1.PartialResultSet].
  150. message ResultSetMetadata {
  151. // Indicates the field names and types for the rows in the result
  152. // set. For example, a SQL query like `"SELECT UserId, UserName FROM
  153. // Users"` could return a `row_type` value like:
  154. //
  155. // "fields": [
  156. // { "name": "UserId", "type": { "code": "INT64" } },
  157. // { "name": "UserName", "type": { "code": "STRING" } },
  158. // ]
  159. StructType row_type = 1;
  160. // If the read or SQL query began a transaction as a side-effect, the
  161. // information about the new transaction is yielded here.
  162. Transaction transaction = 2;
  163. // A SQL query can be parameterized. In PLAN mode, these parameters can be
  164. // undeclared. This indicates the field names and types for those undeclared
  165. // parameters in the SQL query. For example, a SQL query like `"SELECT * FROM
  166. // Users where UserId = @userId and UserName = @userName "` could return a
  167. // `undeclared_parameters` value like:
  168. //
  169. // "fields": [
  170. // { "name": "UserId", "type": { "code": "INT64" } },
  171. // { "name": "UserName", "type": { "code": "STRING" } },
  172. // ]
  173. StructType undeclared_parameters = 3;
  174. }
  175. // Additional statistics about a [ResultSet][google.spanner.v1.ResultSet] or [PartialResultSet][google.spanner.v1.PartialResultSet].
  176. message ResultSetStats {
  177. // [QueryPlan][google.spanner.v1.QueryPlan] for the query associated with this result.
  178. QueryPlan query_plan = 1;
  179. // Aggregated statistics from the execution of the query. Only present when
  180. // the query is profiled. For example, a query could return the statistics as
  181. // follows:
  182. //
  183. // {
  184. // "rows_returned": "3",
  185. // "elapsed_time": "1.22 secs",
  186. // "cpu_time": "1.19 secs"
  187. // }
  188. google.protobuf.Struct query_stats = 2;
  189. // The number of rows modified by the DML statement.
  190. oneof row_count {
  191. // Standard DML returns an exact count of rows that were modified.
  192. int64 row_count_exact = 3;
  193. // Partitioned DML does not offer exactly-once semantics, so it
  194. // returns a lower bound of the rows modified.
  195. int64 row_count_lower_bound = 4;
  196. }
  197. }