- 6.102.0 (latest)
- 6.101.1
- 6.100.0
- 6.99.0
- 6.98.1
- 6.97.1
- 6.96.1
- 6.95.1
- 6.94.0
- 6.93.0
- 6.89.0
- 6.88.0
- 6.87.0
- 6.86.0
- 6.85.0
- 6.83.0
- 6.82.0
- 6.80.1
- 6.79.0
- 6.77.0
- 6.74.1
- 6.72.0
- 6.71.0
- 6.69.0
- 6.68.0
- 6.66.0
- 6.65.1
- 6.62.0
- 6.60.0
- 6.58.0
- 6.57.0
- 6.56.0
- 6.55.0
- 6.54.0
- 6.53.0
- 6.52.1
- 6.51.0
- 6.50.1
- 6.49.0
- 6.25.1
- 6.24.0
- 6.23.4
- 6.22.0
- 6.21.2
- 6.20.0
- 6.19.1
- 6.18.0
- 6.17.4
- 6.14.1
public final class KeyRange implements SerializableRepresents a range of rows in a table or index.
A range has a start key and an end key. These keys can be open or closed, indicating if the range includes rows with that key.
For example, consider the following table definition:
CREATE TABLE UserEvents (
UserName STRING(MAX),
EventDate STRING(10),
) PRIMARY KEY(UserName, EventDate);
The following keys name rows in this table:
Key.of("Bob", "2014-09-23")Key.of("Alfred", "2015-06-12")
Since the UserEvents table's PRIMARY KEY clause names two columns, each
UserEvents key has two elements; the first is the UserName, and the second is the
EventDate.
Key ranges with multiple components are interpreted lexicographically by component using the table or index key's declared sort order. For example, the following range returns all events for user "Bob" that occurred in the year 2015:
KeyRange.closedClosed(
Key.of("Bob", "2015-01-01"),
Key.of("Bob", "2015-12-31"))
Start and end keys can omit trailing key components. This affects the inclusion and exclusion of rows that exactly match the provided key components: if the key is closed, then rows that exactly match the provided components are included; if the key is open, then rows that exactly match are not included.
For example, the following range includes all events for "Bob" that occurred during and after the year 2000:
KeyRange.closedClosed(
Key.of("Bob", "2000-01-01"),
Key.of("Bob"))
The next example retrieves all events for "Bob":
KeyRange.prefix(Key.of("Bob"))
To retrieve events before the year 2000:
KeyRange.closedOpen(
Key.of("Bob"),
Key.of("Bob", "2000-01-01"))
The following range includes all rows in the table:
KeyRange.all()
This range returns all users whose UserName begins with any character from A to C:
KeyRange.closedOpen(Key.of("A"), Key.of("D"))
This range returns all users whose UserName begins with B:
KeyRange.closedOpen(Key.of("B"), Key.of("C"))
Key ranges honor column sort order. For example, suppose a table is defined as follows:
CREATE TABLE DescendingSortedTable {
Key INT64,
...
) PRIMARY KEY(Key DESC);
The following range retrieves all rows with key values between 1 and 100 inclusive:
KeyRange.closedClosed(Key.of(100), Key.of(1))
Note that 100 is passed as the start, and 1 is passed as the end, because Key is a
descending column in the schema.
KeyRange instances are immutable.
Implements
SerializableStatic Methods
closedClosed(Key start, Key end)
public static KeyRange closedClosed(Key start, Key end)Returns a key range from start inclusive to end inclusive.
| Parameters | |
|---|---|
| Name | Description |
start |
Key |
end |
Key |
| Returns | |
|---|---|
| Type | Description |
KeyRange |
|
closedOpen(Key start, Key end)
public static KeyRange closedOpen(Key start, Key end)Returns a key range from start inclusive to end exclusive.
| Parameters | |
|---|---|
| Name | Description |
start |
Key |
end |
Key |
| Returns | |
|---|---|
| Type | Description |
KeyRange |
|
newBuilder()
public static KeyRange.Builder newBuilder()Returns a new builder for constructing a range.
| Returns | |
|---|---|
| Type | Description |
KeyRange.Builder |
|
openClosed(Key start, Key end)
public static KeyRange openClosed(Key start, Key end)Returns a key range from start exclusive to end inclusive.
| Parameters | |
|---|---|
| Name | Description |
start |
Key |
end |
Key |
| Returns | |
|---|---|
| Type | Description |
KeyRange |
|
openOpen(Key start, Key end)
public static KeyRange openOpen(Key start, Key end)Returns a key range from start exclusive to end exclusive.
| Parameters | |
|---|---|
| Name | Description |
start |
Key |
end |
Key |
| Returns | |
|---|---|
| Type | Description |
KeyRange |
|
prefix(Key prefix)
public static KeyRange prefix(Key prefix)Returns a key range that covers all keys where the first prefix.size() components match
prefix exactly.
| Parameter | |
|---|---|
| Name | Description |
prefix |
Key |
| Returns | |
|---|---|
| Type | Description |
KeyRange |
|
Methods
equals(Object o)
public boolean equals(Object o)| Parameter | |
|---|---|
| Name | Description |
o |
Object |
| Returns | |
|---|---|
| Type | Description |
boolean |
|
geEndType()
public KeyRange.Endpoint geEndType()Indicates whether the end key is inclusive (CLOSED) or exclusive (OPEN).
| Returns | |
|---|---|
| Type | Description |
KeyRange.Endpoint |
|
getEnd()
public Key getEnd()Returns the end key of the range.
| Returns | |
|---|---|
| Type | Description |
Key |
|
getStart()
public Key getStart()Returns the start key of the range.
| Returns | |
|---|---|
| Type | Description |
Key |
|
getStartType()
public KeyRange.Endpoint getStartType()Indicates whether the start key is inclusive (CLOSED) or exclusive (OPEN).
| Returns | |
|---|---|
| Type | Description |
KeyRange.Endpoint |
|
hashCode()
public int hashCode()| Returns | |
|---|---|
| Type | Description |
int |
|
toBuilder()
public KeyRange.Builder toBuilder()Returns a builder initialized with the value of this range.
| Returns | |
|---|---|
| Type | Description |
KeyRange.Builder |
|
toString()
public String toString()| Returns | |
|---|---|
| Type | Description |
String |
|