@API(value=MAINTAINED) public class Index extends Object
Modifier and Type | Field and Description |
---|---|
static KeyExpression |
EMPTY_VALUE |
Constructor and Description |
---|
Index(Index orig)
Copy constructor.
|
Index(RecordMetaDataProto.Index proto) |
Index(String name,
KeyExpression rootExpression) |
Index(String name,
KeyExpression rootExpression,
KeyExpression valueExpression,
String type,
Map<String,String> options) |
Index(String name,
KeyExpression rootExpression,
String type) |
Index(String name,
KeyExpression rootExpression,
String type,
Map<String,String> options)
Construct new index meta-data.
|
Index(String name,
String first) |
Index(String name,
String first,
String second,
String... rest) |
Modifier and Type | Method and Description |
---|---|
static Map<String,String> |
buildOptions(List<RecordMetaDataProto.Index.Option> optionList,
boolean addUnique) |
static Object |
decodeSubspaceKey(ByteString bytes) |
boolean |
equals(Object o) |
int |
getAddedVersion()
Get the version at which the index was first added.
|
boolean |
getBooleanOption(String key,
boolean defaultValue) |
int |
getColumnSize()
Get the number of indexed value columns.
|
Tuple |
getEntryPrimaryKey(Tuple entry)
Get the primary key portion of an index entry.
|
int |
getEntrySize(KeyExpression primaryKey)
The number of columns stored for an index entry.
|
int |
getLastModifiedVersion()
Get the version at which the index was changed.
|
String |
getName() |
String |
getOption(String key) |
Map<String,String> |
getOptions() |
int[] |
getPrimaryKeyComponentPositions()
Get the positions of the primary key components within the index key.
|
KeyExpression |
getRootExpression() |
Object |
getSubspaceKey()
Get the key used to determine this index's subspace prefix.
|
Object |
getSubspaceTupleKey()
Get a
Tuple -encodable version of the subspace key of this index. |
String |
getType() |
int |
getVersion()
Deprecated.
|
boolean |
hasExplicitSubspaceKey()
Checks whether the subspace key was set using
setSubspaceKey(Object) . |
int |
hashCode() |
static Map<String,String> |
indexTypeToOptions(RecordMetaDataProto.Index.Type indexType) |
static String |
indexTypeToType(RecordMetaDataProto.Index.Type indexType) |
boolean |
isUnique()
Whether this index should have the property that any two records
with different primary keys should have different values for this
index.
|
void |
setAddedVersion(int addedVersion)
Set the version at which the index was first added.
|
void |
setLastModifiedVersion(int lastModifiedVersion)
Set the version at which the index was changed.
|
void |
setPrimaryKeyComponentPositions(int[] primaryKeyComponentPositions)
Set the positions of primary key components within the index key.
|
void |
setSubspaceKey(Object subspaceKey)
Set the key used to determine this index's subspace prefix.
|
void |
setVersion(int version)
Deprecated.
|
RecordMetaDataProto.Index |
toProto() |
String |
toString() |
void |
trimPrimaryKey(List<?> primaryKeys) |
List<Descriptors.FieldDescriptor> |
validate(Descriptors.Descriptor recordType) |
@Nonnull public static final KeyExpression EMPTY_VALUE
public Index(@Nonnull String name, @Nonnull KeyExpression rootExpression, @Nonnull String type, @Nonnull Map<String,String> options)
name
- the name of the index, which is unique for the whole meta-datarootExpression
- the key expression for the index, such as what field(s) to indextype
- the type of indexoptions
- additional options, which may be type-specificIndexTypes
public Index(@Nonnull String name, @Nonnull KeyExpression rootExpression, @Nonnull KeyExpression valueExpression, @Nonnull String type, @Nonnull Map<String,String> options)
public Index(@Nonnull String name, @Nonnull KeyExpression rootExpression, @Nonnull String type)
public Index(@Nonnull String name, @Nonnull KeyExpression rootExpression)
public Index(@Nonnull String name, @Nonnull String first, @Nonnull String second, @Nonnull String... rest)
public Index(@Nonnull Index orig)
Index
instance.orig
- original index to copypublic Index(@Nonnull RecordMetaDataProto.Index proto) throws KeyExpression.DeserializationException
public static Object decodeSubspaceKey(@Nonnull ByteString bytes)
public static Map<String,String> buildOptions(List<RecordMetaDataProto.Index.Option> optionList, boolean addUnique)
public static String indexTypeToType(RecordMetaDataProto.Index.Type indexType)
public static Map<String,String> indexTypeToOptions(RecordMetaDataProto.Index.Type indexType)
@Nonnull public KeyExpression getRootExpression()
public boolean isUnique()
false
if the
option is not set explicitly.@Nonnull public Object getSubspaceKey()
setSubspaceKey(Object)
.FDBRecordStore.indexSubspace(Index)
@Nonnull public Object getSubspaceTupleKey()
Tuple
-encodable version of the subspace key of this index.
As the subspace key is not guaranteed to be of a Tuple
-encodable type on its own, this
method is preferred over getSubspaceKey()
if one is constructing a key to read or write data
from the database.Tuple
-encodable version of index subspace keypublic void setSubspaceKey(@Nonnull Object subspaceKey)
Tuple
. As this value will prefix all keys used by the
index, it is generally advisable that this key have a compact serialized form. For
example, integers are encoded by the Tuple
layer using a variable length
encoding scheme that makes them a natural choice for this key.
It is important that once an index has data that its subspace key not change. If
one wishes to change the key, the guidance would be to create a new index with the
same definition but at the new key. Then that index can be built using the
OnlineIndexer
.
When that index has been fully built, the original index can be safely dropped.
subspaceKey
- the key used to determine this index's subspace prefixgetSubspaceKey()
public boolean hasExplicitSubspaceKey()
setSubspaceKey(Object)
.true
if the subspace key was set using #setSubspaceKey(Object)
@Nullable public int[] getPrimaryKeyComponentPositions()
null
if there are no common fields used by both the
index key and the primary key. Otherwise, it will return an array that is the
same length as the column size of the
primary key. Each position in the array should either contain the index in the
index key where one can find the value of the primary key component in that
position or a negative value to indicate that that column is not found in the
index key.
For example, suppose one had an index defined on a record type with a primary
key of Key.Expressions.concatenateFields("a", "b")
and suppose the index
was defined on Key.Expressions.concatenateFields("a", "c")
. A naïve
approach might serialize index key tuples of the form (a, c, a, b)
by concatenating the index key (i.e., (a, c)
) with the primary key
(i.e., (a, b)
). However, as the first component of the primary key tuple
can be found within the index's tuple, indexes will instead serialize index
key tuples of the form (a, c, b)
. This function will then return the array
{0, -1}
to indicate that the first component of the primary key can be
found at position 0 in the index entry key but the second component is found after
the index key data (which is the default location).
This method should generally not be called by users outside of the Record Layer.
For the most part, it should be sufficient for index maintainers to call
FDBRecordStoreBase.indexEntryPrimaryKey()
to determine the primary key of a record from an index entry and
FDBRecordStoreBase.indexEntryKey()
to determine the index entry given a record's primary key.
At the moment, this optimization is not used with multi-type or universal indexes. See Issue #93 for more details.
null
public void setPrimaryKeyComponentPositions(int[] primaryKeyComponentPositions)
primaryKeyComponentPositions
- the positions of primary key components within the index keygetPrimaryKeyComponentPositions()
public int getColumnSize()
public int getEntrySize(KeyExpression primaryKey)
primaryKey
- the primary key for eliminating duplicates@Nonnull public Tuple getEntryPrimaryKey(@Nonnull Tuple entry)
entry
- the index entry@Deprecated public int getVersion()
getLastModifiedVersion()
.getLastModifiedVersion()
.@Deprecated public void setVersion(int version)
setLastModifiedVersion(int)
.setLastModifiedVersion(int)
.version
- the last modified versionpublic int getAddedVersion()
public void setAddedVersion(int addedVersion)
addedVersion
- the added versionpublic int getLastModifiedVersion()
public void setLastModifiedVersion(int lastModifiedVersion)
lastModifiedVersion
- the last modified versionpublic List<Descriptors.FieldDescriptor> validate(@Nonnull Descriptors.Descriptor recordType)
@Nonnull public RecordMetaDataProto.Index toProto() throws KeyExpression.SerializationException