keys.proto 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/api/annotations.proto";
  18. option csharp_namespace = "Google.Cloud.Spanner.V1";
  19. option go_package = "google.golang.org/genproto/googleapis/spanner/v1;spanner";
  20. option java_multiple_files = true;
  21. option java_outer_classname = "KeysProto";
  22. option java_package = "com.google.spanner.v1";
  23. option php_namespace = "Google\\Cloud\\Spanner\\V1";
  24. option ruby_package = "Google::Cloud::Spanner::V1";
  25. // KeyRange represents a range of rows in a table or index.
  26. //
  27. // A range has a start key and an end key. These keys can be open or
  28. // closed, indicating if the range includes rows with that key.
  29. //
  30. // Keys are represented by lists, where the ith value in the list
  31. // corresponds to the ith component of the table or index primary key.
  32. // Individual values are encoded as described
  33. // [here][google.spanner.v1.TypeCode].
  34. //
  35. // For example, consider the following table definition:
  36. //
  37. // CREATE TABLE UserEvents (
  38. // UserName STRING(MAX),
  39. // EventDate STRING(10)
  40. // ) PRIMARY KEY(UserName, EventDate);
  41. //
  42. // The following keys name rows in this table:
  43. //
  44. // ["Bob", "2014-09-23"]
  45. // ["Alfred", "2015-06-12"]
  46. //
  47. // Since the `UserEvents` table's `PRIMARY KEY` clause names two
  48. // columns, each `UserEvents` key has two elements; the first is the
  49. // `UserName`, and the second is the `EventDate`.
  50. //
  51. // Key ranges with multiple components are interpreted
  52. // lexicographically by component using the table or index key's declared
  53. // sort order. For example, the following range returns all events for
  54. // user `"Bob"` that occurred in the year 2015:
  55. //
  56. // "start_closed": ["Bob", "2015-01-01"]
  57. // "end_closed": ["Bob", "2015-12-31"]
  58. //
  59. // Start and end keys can omit trailing key components. This affects the
  60. // inclusion and exclusion of rows that exactly match the provided key
  61. // components: if the key is closed, then rows that exactly match the
  62. // provided components are included; if the key is open, then rows
  63. // that exactly match are not included.
  64. //
  65. // For example, the following range includes all events for `"Bob"` that
  66. // occurred during and after the year 2000:
  67. //
  68. // "start_closed": ["Bob", "2000-01-01"]
  69. // "end_closed": ["Bob"]
  70. //
  71. // The next example retrieves all events for `"Bob"`:
  72. //
  73. // "start_closed": ["Bob"]
  74. // "end_closed": ["Bob"]
  75. //
  76. // To retrieve events before the year 2000:
  77. //
  78. // "start_closed": ["Bob"]
  79. // "end_open": ["Bob", "2000-01-01"]
  80. //
  81. // The following range includes all rows in the table:
  82. //
  83. // "start_closed": []
  84. // "end_closed": []
  85. //
  86. // This range returns all users whose `UserName` begins with any
  87. // character from A to C:
  88. //
  89. // "start_closed": ["A"]
  90. // "end_open": ["D"]
  91. //
  92. // This range returns all users whose `UserName` begins with B:
  93. //
  94. // "start_closed": ["B"]
  95. // "end_open": ["C"]
  96. //
  97. // Key ranges honor column sort order. For example, suppose a table is
  98. // defined as follows:
  99. //
  100. // CREATE TABLE DescendingSortedTable {
  101. // Key INT64,
  102. // ...
  103. // ) PRIMARY KEY(Key DESC);
  104. //
  105. // The following range retrieves all rows with key values between 1
  106. // and 100 inclusive:
  107. //
  108. // "start_closed": ["100"]
  109. // "end_closed": ["1"]
  110. //
  111. // Note that 100 is passed as the start, and 1 is passed as the end,
  112. // because `Key` is a descending column in the schema.
  113. message KeyRange {
  114. // The start key must be provided. It can be either closed or open.
  115. oneof start_key_type {
  116. // If the start is closed, then the range includes all rows whose
  117. // first `len(start_closed)` key columns exactly match `start_closed`.
  118. google.protobuf.ListValue start_closed = 1;
  119. // If the start is open, then the range excludes rows whose first
  120. // `len(start_open)` key columns exactly match `start_open`.
  121. google.protobuf.ListValue start_open = 2;
  122. }
  123. // The end key must be provided. It can be either closed or open.
  124. oneof end_key_type {
  125. // If the end is closed, then the range includes all rows whose
  126. // first `len(end_closed)` key columns exactly match `end_closed`.
  127. google.protobuf.ListValue end_closed = 3;
  128. // If the end is open, then the range excludes rows whose first
  129. // `len(end_open)` key columns exactly match `end_open`.
  130. google.protobuf.ListValue end_open = 4;
  131. }
  132. }
  133. // `KeySet` defines a collection of Cloud Spanner keys and/or key ranges. All
  134. // the keys are expected to be in the same table or index. The keys need
  135. // not be sorted in any particular way.
  136. //
  137. // If the same key is specified multiple times in the set (for example
  138. // if two ranges, two keys, or a key and a range overlap), Cloud Spanner
  139. // behaves as if the key were only specified once.
  140. message KeySet {
  141. // A list of specific keys. Entries in `keys` should have exactly as
  142. // many elements as there are columns in the primary or index key
  143. // with which this `KeySet` is used. Individual key values are
  144. // encoded as described [here][google.spanner.v1.TypeCode].
  145. repeated google.protobuf.ListValue keys = 1;
  146. // A list of key ranges. See [KeyRange][google.spanner.v1.KeyRange] for more information about
  147. // key range specifications.
  148. repeated KeyRange ranges = 2;
  149. // For convenience `all` can be set to `true` to indicate that this
  150. // `KeySet` matches all keys in the table or index. Note that any keys
  151. // specified in `keys` or `ranges` are only yielded once.
  152. bool all = 3;
  153. }