keys.proto 5.9 KB

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