query.proto 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // Copyright 2016 Google Inc.
  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.datastore.v1beta3;
  16. import "google/api/annotations.proto";
  17. import "google/datastore/v1beta3/entity.proto";
  18. import "google/protobuf/wrappers.proto";
  19. import "google/type/latlng.proto";
  20. option java_multiple_files = true;
  21. option java_outer_classname = "QueryProto";
  22. option java_package = "com.google.datastore.v1beta3";
  23. // The result of fetching an entity from Datastore.
  24. message EntityResult {
  25. // Specifies what data the 'entity' field contains.
  26. // A `ResultType` is either implied (for example, in `LookupResponse.missing`
  27. // from `datastore.proto`, it is always `KEY_ONLY`) or specified by context
  28. // (for example, in message `QueryResultBatch`, field `entity_result_type`
  29. // specifies a `ResultType` for all the values in field `entity_results`).
  30. enum ResultType {
  31. // Unspecified. This value is never used.
  32. RESULT_TYPE_UNSPECIFIED = 0;
  33. // The key and properties.
  34. FULL = 1;
  35. // A projected subset of properties. The entity may have no key.
  36. PROJECTION = 2;
  37. // Only the key.
  38. KEY_ONLY = 3;
  39. }
  40. // The resulting entity.
  41. Entity entity = 1;
  42. // The version of the entity, a strictly positive number that monotonically
  43. // increases with changes to the entity.
  44. //
  45. // This field is set for [`FULL`][google.datastore.v1beta3.EntityResult.ResultType.FULL] entity
  46. // results.
  47. //
  48. // For [missing][google.datastore.v1beta3.LookupResponse.missing] entities in `LookupResponse`, this
  49. // is the version of the snapshot that was used to look up the entity, and it
  50. // is always set except for eventually consistent reads.
  51. int64 version = 4;
  52. // A cursor that points to the position after the result entity.
  53. // Set only when the `EntityResult` is part of a `QueryResultBatch` message.
  54. bytes cursor = 3;
  55. }
  56. // A query for entities.
  57. message Query {
  58. // The projection to return. Defaults to returning all properties.
  59. repeated Projection projection = 2;
  60. // The kinds to query (if empty, returns entities of all kinds).
  61. // Currently at most 1 kind may be specified.
  62. repeated KindExpression kind = 3;
  63. // The filter to apply.
  64. Filter filter = 4;
  65. // The order to apply to the query results (if empty, order is unspecified).
  66. repeated PropertyOrder order = 5;
  67. // The properties to make distinct. The query results will contain the first
  68. // result for each distinct combination of values for the given properties
  69. // (if empty, all results are returned).
  70. repeated PropertyReference distinct_on = 6;
  71. // A starting point for the query results. Query cursors are
  72. // returned in query result batches and
  73. // [can only be used to continue the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
  74. bytes start_cursor = 7;
  75. // An ending point for the query results. Query cursors are
  76. // returned in query result batches and
  77. // [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
  78. bytes end_cursor = 8;
  79. // The number of results to skip. Applies before limit, but after all other
  80. // constraints. Optional. Must be >= 0 if specified.
  81. int32 offset = 10;
  82. // The maximum number of results to return. Applies after all other
  83. // constraints. Optional.
  84. // Unspecified is interpreted as no limit.
  85. // Must be >= 0 if specified.
  86. google.protobuf.Int32Value limit = 12;
  87. }
  88. // A representation of a kind.
  89. message KindExpression {
  90. // The name of the kind.
  91. string name = 1;
  92. }
  93. // A reference to a property relative to the kind expressions.
  94. message PropertyReference {
  95. // The name of the property.
  96. // If name includes "."s, it may be interpreted as a property name path.
  97. string name = 2;
  98. }
  99. // A representation of a property in a projection.
  100. message Projection {
  101. // The property to project.
  102. PropertyReference property = 1;
  103. }
  104. // The desired order for a specific property.
  105. message PropertyOrder {
  106. // The sort direction.
  107. enum Direction {
  108. // Unspecified. This value must not be used.
  109. DIRECTION_UNSPECIFIED = 0;
  110. // Ascending.
  111. ASCENDING = 1;
  112. // Descending.
  113. DESCENDING = 2;
  114. }
  115. // The property to order by.
  116. PropertyReference property = 1;
  117. // The direction to order by. Defaults to `ASCENDING`.
  118. Direction direction = 2;
  119. }
  120. // A holder for any type of filter.
  121. message Filter {
  122. // The type of filter.
  123. oneof filter_type {
  124. // A composite filter.
  125. CompositeFilter composite_filter = 1;
  126. // A filter on a property.
  127. PropertyFilter property_filter = 2;
  128. }
  129. }
  130. // A filter that merges multiple other filters using the given operator.
  131. message CompositeFilter {
  132. // A composite filter operator.
  133. enum Operator {
  134. // Unspecified. This value must not be used.
  135. OPERATOR_UNSPECIFIED = 0;
  136. // The results are required to satisfy each of the combined filters.
  137. AND = 1;
  138. }
  139. // The operator for combining multiple filters.
  140. Operator op = 1;
  141. // The list of filters to combine.
  142. // Must contain at least one filter.
  143. repeated Filter filters = 2;
  144. }
  145. // A filter on a specific property.
  146. message PropertyFilter {
  147. // A property filter operator.
  148. enum Operator {
  149. // Unspecified. This value must not be used.
  150. OPERATOR_UNSPECIFIED = 0;
  151. // Less than.
  152. LESS_THAN = 1;
  153. // Less than or equal.
  154. LESS_THAN_OR_EQUAL = 2;
  155. // Greater than.
  156. GREATER_THAN = 3;
  157. // Greater than or equal.
  158. GREATER_THAN_OR_EQUAL = 4;
  159. // Equal.
  160. EQUAL = 5;
  161. // Has ancestor.
  162. HAS_ANCESTOR = 11;
  163. }
  164. // The property to filter by.
  165. PropertyReference property = 1;
  166. // The operator to filter by.
  167. Operator op = 2;
  168. // The value to compare the property to.
  169. Value value = 3;
  170. }
  171. // A [GQL query](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
  172. message GqlQuery {
  173. // A string of the format described
  174. // [here](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
  175. string query_string = 1;
  176. // When false, the query string must not contain any literals and instead must
  177. // bind all values. For example,
  178. // `SELECT * FROM Kind WHERE a = 'string literal'` is not allowed, while
  179. // `SELECT * FROM Kind WHERE a = @value` is.
  180. bool allow_literals = 2;
  181. // For each non-reserved named binding site in the query string, there must be
  182. // a named parameter with that name, but not necessarily the inverse.
  183. //
  184. // Key must match regex `[A-Za-z_$][A-Za-z_$0-9]*`, must not match regex
  185. // `__.*__`, and must not be `""`.
  186. map<string, GqlQueryParameter> named_bindings = 5;
  187. // Numbered binding site @1 references the first numbered parameter,
  188. // effectively using 1-based indexing, rather than the usual 0.
  189. //
  190. // For each binding site numbered i in `query_string`, there must be an i-th
  191. // numbered parameter. The inverse must also be true.
  192. repeated GqlQueryParameter positional_bindings = 4;
  193. }
  194. // A binding parameter for a GQL query.
  195. message GqlQueryParameter {
  196. // The type of parameter.
  197. oneof parameter_type {
  198. // A value parameter.
  199. Value value = 2;
  200. // A query cursor. Query cursors are returned in query
  201. // result batches.
  202. bytes cursor = 3;
  203. }
  204. }
  205. // A batch of results produced by a query.
  206. message QueryResultBatch {
  207. // The possible values for the `more_results` field.
  208. enum MoreResultsType {
  209. // Unspecified. This value is never used.
  210. MORE_RESULTS_TYPE_UNSPECIFIED = 0;
  211. // There may be additional batches to fetch from this query.
  212. NOT_FINISHED = 1;
  213. // The query is finished, but there may be more results after the limit.
  214. MORE_RESULTS_AFTER_LIMIT = 2;
  215. // The query is finished, but there may be more results after the end
  216. // cursor.
  217. MORE_RESULTS_AFTER_CURSOR = 4;
  218. // The query has been exhausted.
  219. NO_MORE_RESULTS = 3;
  220. }
  221. // The number of results skipped, typically because of an offset.
  222. int32 skipped_results = 6;
  223. // A cursor that points to the position after the last skipped result.
  224. // Will be set when `skipped_results` != 0.
  225. bytes skipped_cursor = 3;
  226. // The result type for every entity in `entity_results`.
  227. EntityResult.ResultType entity_result_type = 1;
  228. // The results for this batch.
  229. repeated EntityResult entity_results = 2;
  230. // A cursor that points to the position after the last result in the batch.
  231. bytes end_cursor = 4;
  232. // The state of the query after the current batch.
  233. MoreResultsType more_results = 5;
  234. // The version number of the snapshot this batch was returned from.
  235. // This applies to the range of results from the query's `start_cursor` (or
  236. // the beginning of the query if no cursor was given) to this batch's
  237. // `end_cursor` (not the query's `end_cursor`).
  238. //
  239. // In a single transaction, subsequent query result batches for the same query
  240. // can have a greater snapshot version number. Each batch's snapshot version
  241. // is valid for all preceding batches.
  242. int64 snapshot_version = 7;
  243. }