query.proto 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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.datastore.v1;
  16. import "google/api/field_behavior.proto";
  17. import "google/datastore/v1/entity.proto";
  18. import "google/protobuf/timestamp.proto";
  19. import "google/protobuf/wrappers.proto";
  20. option csharp_namespace = "Google.Cloud.Datastore.V1";
  21. option go_package = "google.golang.org/genproto/googleapis/datastore/v1;datastore";
  22. option java_multiple_files = true;
  23. option java_outer_classname = "QueryProto";
  24. option java_package = "com.google.datastore.v1";
  25. option php_namespace = "Google\\Cloud\\Datastore\\V1";
  26. option ruby_package = "Google::Cloud::Datastore::V1";
  27. // The result of fetching an entity from Datastore.
  28. message EntityResult {
  29. // Specifies what data the 'entity' field contains.
  30. // A `ResultType` is either implied (for example, in `LookupResponse.missing`
  31. // from `datastore.proto`, it is always `KEY_ONLY`) or specified by context
  32. // (for example, in message `QueryResultBatch`, field `entity_result_type`
  33. // specifies a `ResultType` for all the values in field `entity_results`).
  34. enum ResultType {
  35. // Unspecified. This value is never used.
  36. RESULT_TYPE_UNSPECIFIED = 0;
  37. // The key and properties.
  38. FULL = 1;
  39. // A projected subset of properties. The entity may have no key.
  40. PROJECTION = 2;
  41. // Only the key.
  42. KEY_ONLY = 3;
  43. }
  44. // The resulting entity.
  45. Entity entity = 1;
  46. // The version of the entity, a strictly positive number that monotonically
  47. // increases with changes to the entity.
  48. //
  49. // This field is set for [`FULL`][google.datastore.v1.EntityResult.ResultType.FULL] entity
  50. // results.
  51. //
  52. // For [missing][google.datastore.v1.LookupResponse.missing] entities in `LookupResponse`, this
  53. // is the version of the snapshot that was used to look up the entity, and it
  54. // is always set except for eventually consistent reads.
  55. int64 version = 4;
  56. // The time at which the entity was last changed.
  57. // This field is set for [`FULL`][google.datastore.v1.EntityResult.ResultType.FULL] entity
  58. // results.
  59. // If this entity is missing, this field will not be set.
  60. google.protobuf.Timestamp update_time = 5;
  61. // A cursor that points to the position after the result entity.
  62. // Set only when the `EntityResult` is part of a `QueryResultBatch` message.
  63. bytes cursor = 3;
  64. }
  65. // A query for entities.
  66. message Query {
  67. // The projection to return. Defaults to returning all properties.
  68. repeated Projection projection = 2;
  69. // The kinds to query (if empty, returns entities of all kinds).
  70. // Currently at most 1 kind may be specified.
  71. repeated KindExpression kind = 3;
  72. // The filter to apply.
  73. Filter filter = 4;
  74. // The order to apply to the query results (if empty, order is unspecified).
  75. repeated PropertyOrder order = 5;
  76. // The properties to make distinct. The query results will contain the first
  77. // result for each distinct combination of values for the given properties
  78. // (if empty, all results are returned).
  79. repeated PropertyReference distinct_on = 6;
  80. // A starting point for the query results. Query cursors are
  81. // returned in query result batches and
  82. // [can only be used to continue the same
  83. // query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
  84. bytes start_cursor = 7;
  85. // An ending point for the query results. Query cursors are
  86. // returned in query result batches and
  87. // [can only be used to limit the same
  88. // query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
  89. bytes end_cursor = 8;
  90. // The number of results to skip. Applies before limit, but after all other
  91. // constraints. Optional. Must be >= 0 if specified.
  92. int32 offset = 10;
  93. // The maximum number of results to return. Applies after all other
  94. // constraints. Optional.
  95. // Unspecified is interpreted as no limit.
  96. // Must be >= 0 if specified.
  97. google.protobuf.Int32Value limit = 12;
  98. }
  99. // Datastore query for running an aggregation over a [Query][google.datastore.v1.Query].
  100. message AggregationQuery {
  101. // Defines a aggregation that produces a single result.
  102. message Aggregation {
  103. // Count of entities that match the query.
  104. //
  105. // The `COUNT(*)` aggregation function operates on the entire entity
  106. // so it does not require a field reference.
  107. message Count {
  108. // Optional. Optional constraint on the maximum number of entities to count.
  109. //
  110. // This provides a way to set an upper bound on the number of entities
  111. // to scan, limiting latency and cost.
  112. //
  113. // Unspecified is interpreted as no bound.
  114. //
  115. // If a zero value is provided, a count result of zero should always be
  116. // expected.
  117. //
  118. // High-Level Example:
  119. //
  120. // ```
  121. // AGGREGATE COUNT_UP_TO(1000) OVER ( SELECT * FROM k );
  122. // ```
  123. //
  124. // Requires:
  125. //
  126. // * Must be non-negative when present.
  127. google.protobuf.Int64Value up_to = 1 [(google.api.field_behavior) = OPTIONAL];
  128. }
  129. // The type of aggregation to perform, required.
  130. oneof operator {
  131. // Count aggregator.
  132. Count count = 1;
  133. }
  134. // Optional. Optional name of the property to store the result of the aggregation.
  135. //
  136. // If not provided, Datastore will pick a default name following the format
  137. // `property_<incremental_id++>`. For example:
  138. //
  139. // ```
  140. // AGGREGATE
  141. // COUNT_UP_TO(1) AS count_up_to_1,
  142. // COUNT_UP_TO(2),
  143. // COUNT_UP_TO(3) AS count_up_to_3,
  144. // COUNT_UP_TO(4)
  145. // OVER (
  146. // ...
  147. // );
  148. // ```
  149. //
  150. // becomes:
  151. //
  152. // ```
  153. // AGGREGATE
  154. // COUNT_UP_TO(1) AS count_up_to_1,
  155. // COUNT_UP_TO(2) AS property_1,
  156. // COUNT_UP_TO(3) AS count_up_to_3,
  157. // COUNT_UP_TO(4) AS property_2
  158. // OVER (
  159. // ...
  160. // );
  161. // ```
  162. //
  163. // Requires:
  164. //
  165. // * Must be unique across all aggregation aliases.
  166. // * Conform to [entity property name][google.datastore.v1.Entity.properties] limitations.
  167. string alias = 7 [(google.api.field_behavior) = OPTIONAL];
  168. }
  169. // The base query to aggregate over.
  170. oneof query_type {
  171. // Nested query for aggregation
  172. Query nested_query = 1;
  173. }
  174. // Optional. Series of aggregations to apply over the results of the `nested_query`.
  175. //
  176. // Requires:
  177. //
  178. // * A minimum of one and maximum of five aggregations per query.
  179. repeated Aggregation aggregations = 3 [(google.api.field_behavior) = OPTIONAL];
  180. }
  181. // A representation of a kind.
  182. message KindExpression {
  183. // The name of the kind.
  184. string name = 1;
  185. }
  186. // A reference to a property relative to the kind expressions.
  187. message PropertyReference {
  188. // The name of the property.
  189. // If name includes "."s, it may be interpreted as a property name path.
  190. string name = 2;
  191. }
  192. // A representation of a property in a projection.
  193. message Projection {
  194. // The property to project.
  195. PropertyReference property = 1;
  196. }
  197. // The desired order for a specific property.
  198. message PropertyOrder {
  199. // The sort direction.
  200. enum Direction {
  201. // Unspecified. This value must not be used.
  202. DIRECTION_UNSPECIFIED = 0;
  203. // Ascending.
  204. ASCENDING = 1;
  205. // Descending.
  206. DESCENDING = 2;
  207. }
  208. // The property to order by.
  209. PropertyReference property = 1;
  210. // The direction to order by. Defaults to `ASCENDING`.
  211. Direction direction = 2;
  212. }
  213. // A holder for any type of filter.
  214. message Filter {
  215. // The type of filter.
  216. oneof filter_type {
  217. // A composite filter.
  218. CompositeFilter composite_filter = 1;
  219. // A filter on a property.
  220. PropertyFilter property_filter = 2;
  221. }
  222. }
  223. // A filter that merges multiple other filters using the given operator.
  224. message CompositeFilter {
  225. // A composite filter operator.
  226. enum Operator {
  227. // Unspecified. This value must not be used.
  228. OPERATOR_UNSPECIFIED = 0;
  229. // The results are required to satisfy each of the combined filters.
  230. AND = 1;
  231. }
  232. // The operator for combining multiple filters.
  233. Operator op = 1;
  234. // The list of filters to combine.
  235. //
  236. // Requires:
  237. //
  238. // * At least one filter is present.
  239. repeated Filter filters = 2;
  240. }
  241. // A filter on a specific property.
  242. message PropertyFilter {
  243. // A property filter operator.
  244. enum Operator {
  245. // Unspecified. This value must not be used.
  246. OPERATOR_UNSPECIFIED = 0;
  247. // The given `property` is less than the given `value`.
  248. //
  249. // Requires:
  250. //
  251. // * That `property` comes first in `order_by`.
  252. LESS_THAN = 1;
  253. // The given `property` is less than or equal to the given `value`.
  254. //
  255. // Requires:
  256. //
  257. // * That `property` comes first in `order_by`.
  258. LESS_THAN_OR_EQUAL = 2;
  259. // The given `property` is greater than the given `value`.
  260. //
  261. // Requires:
  262. //
  263. // * That `property` comes first in `order_by`.
  264. GREATER_THAN = 3;
  265. // The given `property` is greater than or equal to the given `value`.
  266. //
  267. // Requires:
  268. //
  269. // * That `property` comes first in `order_by`.
  270. GREATER_THAN_OR_EQUAL = 4;
  271. // The given `property` is equal to the given `value`.
  272. EQUAL = 5;
  273. // The given `property` is equal to at least one value in the given array.
  274. //
  275. // Requires:
  276. //
  277. // * That `value` is a non-empty `ArrayValue` with at most 10 values.
  278. // * No other `IN` or `NOT_IN` is in the same query.
  279. IN = 6;
  280. // The given `property` is not equal to the given `value`.
  281. //
  282. // Requires:
  283. //
  284. // * No other `NOT_EQUAL` or `NOT_IN` is in the same query.
  285. // * That `property` comes first in the `order_by`.
  286. NOT_EQUAL = 9;
  287. // Limit the result set to the given entity and its descendants.
  288. //
  289. // Requires:
  290. //
  291. // * That `value` is an entity key.
  292. HAS_ANCESTOR = 11;
  293. // The value of the `property` is not in the given array.
  294. //
  295. // Requires:
  296. //
  297. // * That `value` is a non-empty `ArrayValue` with at most 10 values.
  298. // * No other `IN`, `NOT_IN`, `NOT_EQUAL` is in the same query.
  299. // * That `field` comes first in the `order_by`.
  300. NOT_IN = 13;
  301. }
  302. // The property to filter by.
  303. PropertyReference property = 1;
  304. // The operator to filter by.
  305. Operator op = 2;
  306. // The value to compare the property to.
  307. Value value = 3;
  308. }
  309. // A [GQL
  310. // query](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
  311. message GqlQuery {
  312. // A string of the format described
  313. // [here](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
  314. string query_string = 1;
  315. // When false, the query string must not contain any literals and instead must
  316. // bind all values. For example,
  317. // `SELECT * FROM Kind WHERE a = 'string literal'` is not allowed, while
  318. // `SELECT * FROM Kind WHERE a = @value` is.
  319. bool allow_literals = 2;
  320. // For each non-reserved named binding site in the query string, there must be
  321. // a named parameter with that name, but not necessarily the inverse.
  322. //
  323. // Key must match regex `[A-Za-z_$][A-Za-z_$0-9]*`, must not match regex
  324. // `__.*__`, and must not be `""`.
  325. map<string, GqlQueryParameter> named_bindings = 5;
  326. // Numbered binding site @1 references the first numbered parameter,
  327. // effectively using 1-based indexing, rather than the usual 0.
  328. //
  329. // For each binding site numbered i in `query_string`, there must be an i-th
  330. // numbered parameter. The inverse must also be true.
  331. repeated GqlQueryParameter positional_bindings = 4;
  332. }
  333. // A binding parameter for a GQL query.
  334. message GqlQueryParameter {
  335. // The type of parameter.
  336. oneof parameter_type {
  337. // A value parameter.
  338. Value value = 2;
  339. // A query cursor. Query cursors are returned in query
  340. // result batches.
  341. bytes cursor = 3;
  342. }
  343. }
  344. // A batch of results produced by a query.
  345. message QueryResultBatch {
  346. // The possible values for the `more_results` field.
  347. enum MoreResultsType {
  348. // Unspecified. This value is never used.
  349. MORE_RESULTS_TYPE_UNSPECIFIED = 0;
  350. // There may be additional batches to fetch from this query.
  351. NOT_FINISHED = 1;
  352. // The query is finished, but there may be more results after the limit.
  353. MORE_RESULTS_AFTER_LIMIT = 2;
  354. // The query is finished, but there may be more results after the end
  355. // cursor.
  356. MORE_RESULTS_AFTER_CURSOR = 4;
  357. // The query is finished, and there are no more results.
  358. NO_MORE_RESULTS = 3;
  359. }
  360. // The number of results skipped, typically because of an offset.
  361. int32 skipped_results = 6;
  362. // A cursor that points to the position after the last skipped result.
  363. // Will be set when `skipped_results` != 0.
  364. bytes skipped_cursor = 3;
  365. // The result type for every entity in `entity_results`.
  366. EntityResult.ResultType entity_result_type = 1;
  367. // The results for this batch.
  368. repeated EntityResult entity_results = 2;
  369. // A cursor that points to the position after the last result in the batch.
  370. bytes end_cursor = 4;
  371. // The state of the query after the current batch.
  372. MoreResultsType more_results = 5;
  373. // The version number of the snapshot this batch was returned from.
  374. // This applies to the range of results from the query's `start_cursor` (or
  375. // the beginning of the query if no cursor was given) to this batch's
  376. // `end_cursor` (not the query's `end_cursor`).
  377. //
  378. // In a single transaction, subsequent query result batches for the same query
  379. // can have a greater snapshot version number. Each batch's snapshot version
  380. // is valid for all preceding batches.
  381. // The value will be zero for eventually consistent queries.
  382. int64 snapshot_version = 7;
  383. // Read timestamp this batch was returned from.
  384. // This applies to the range of results from the query's `start_cursor` (or
  385. // the beginning of the query if no cursor was given) to this batch's
  386. // `end_cursor` (not the query's `end_cursor`).
  387. //
  388. // In a single transaction, subsequent query result batches for the same query
  389. // can have a greater timestamp. Each batch's read timestamp
  390. // is valid for all preceding batches.
  391. // This value will not be set for eventually consistent queries in Cloud
  392. // Datastore.
  393. google.protobuf.Timestamp read_time = 8;
  394. }