result_set.proto 8.5 KB

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