Class Index

    • Method Detail

      • getBooleanOption

        public boolean getBooleanOption​(@Nonnull
                                        String key,
                                        boolean defaultValue)
      • isUnique

        public boolean isUnique()
        Whether this index should have the property that any two records with different primary keys should have different values for this index. The default value for this is false if the option is not set explicitly.
        Returns:
        the value of the "unique" option
      • getSubspaceKey

        @Nonnull
        public Object getSubspaceKey()
        Get the key used to determine this index's subspace prefix. All of the index's data will live within a subspace constructed by adding this key to a record store's subspace for secondary indexes. Each index within a given meta-data definition must have a unique subspace key. By default, this is equal to the index's name, but alternative keys can be set by calling setSubspaceKey(Object).
        Returns:
        the key used to determine this index's subspace prefix
        See Also:
        FDBRecordStore.indexSubspace(Index)
      • getSubspaceTupleKey

        @Nonnull
        public Object getSubspaceTupleKey()
        Get a 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.
        Returns:
        a Tuple-encodable version of index subspace key
      • setSubspaceKey

        public void setSubspaceKey​(@Nonnull
                                   Object subspaceKey)
        Set the key used to determine this index's subspace prefix. This value must be unique for each index within a given meta-data definition and must be serializable using a FoundationDB 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.

        Parameters:
        subspaceKey - the key used to determine this index's subspace prefix
        See Also:
        getSubspaceKey()
      • hasExplicitSubspaceKey

        public boolean hasExplicitSubspaceKey()
        Checks whether the subspace key was set using setSubspaceKey(Object).
        Returns:
        true if the subspace key was set using #setSubspaceKey(Object)
      • getPrimaryKeyComponentPositions

        @Nullable
        public int[] getPrimaryKeyComponentPositions()
        Get the positions of the primary key components within the index key. This is used if the index key and the primary key expressions share fields to avoid duplicating the shared fields when writing serializing the index entry. This might return 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.

        Returns:
        the positions of primary key components within the index key or null
      • setPrimaryKeyComponentPositions

        public void setPrimaryKeyComponentPositions​(int[] primaryKeyComponentPositions)
        Set the positions of primary key components within the index key. This generally should not be called by users outside of the Record Layer as it can affect how data are serialized to disk in incompatible ways.
        Parameters:
        primaryKeyComponentPositions - the positions of primary key components within the index key
        See Also:
        getPrimaryKeyComponentPositions()
      • trimPrimaryKey

        @API(INTERNAL)
        public void trimPrimaryKey​(List<?> primaryKeys)
      • getColumnSize

        public int getColumnSize()
        Get the number of indexed value columns.
        Returns:
        the number of columns
      • getEntrySize

        public int getEntrySize​(KeyExpression primaryKey)
        The number of columns stored for an index entry. Does not count primary key columns that are part of the indexed value, which do not need to be duplicated.
        Parameters:
        primaryKey - the primary key for eliminating duplicates
        Returns:
        the size of an index entry
      • getEntryPrimaryKey

        @Nonnull
        public Tuple getEntryPrimaryKey​(@Nonnull
                                        Tuple entry)
        Get the primary key portion of an index entry.
        Parameters:
        entry - the index entry
        Returns:
        the primary key extracted from the entry
      • getAddedVersion

        public int getAddedVersion()
        Get the version at which the index was first added.
        Returns:
        the added version
      • setAddedVersion

        public void setAddedVersion​(int addedVersion)
        Set the version at which the index was first added.
        Parameters:
        addedVersion - the added version
      • getLastModifiedVersion

        public int getLastModifiedVersion()
        Get the version at which the index was changed. Any record store older than this will need to have the index rebuilt.
        Returns:
        the last modified version
      • setLastModifiedVersion

        public void setLastModifiedVersion​(int lastModifiedVersion)
        Set the version at which the index was changed.
        Parameters:
        lastModifiedVersion - the last modified version
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object