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