Class IndexTermType

java.lang.Object
org.apache.cassandra.index.sai.utils.IndexTermType

public class IndexTermType extends Object
This class is a representation of an AbstractType as an indexable type. It is responsible for determining the capabilities of the type and provides helper methods for handling term values associated with the type.
  • Method Details

    • create

      public static IndexTermType create(ColumnMetadata columnMetadata, List<ColumnMetadata> partitionColumns, IndexTarget.Type indexTargetType)
      Parameters:
      columnMetadata - the ColumnMetadata for the column being indexed
      partitionColumns - the partition columns for the table this column belongs to. This is used for identifying if the columnMetadata is a partition column and if it belongs to a composite partition
      indexTargetType - the IndexTarget.Type for the index
      Returns:
      the IndexTermType
    • isLiteral

      public boolean isLiteral()
      Returns true if the index type is a literal type and will use a literal index. This applies to string types, frozen types, composite types and boolean type.
    • isString

      public boolean isString()
      Returns true if the index type is a string type. This is used to determine if the type supports analysis.
    • isVector

      public boolean isVector()
      Returns true if the index type is a vector type. Note: being a vector type does not mean that the type is valid for indexing in that we don't check the element type and dimension constraints here.
    • isReversed

      public boolean isReversed()
      Returns true if the index type is reversed. This is only the case (currently) for clustering keys with descending ordering.
    • isFrozen

      public boolean isFrozen()
      Returns true if the index type is frozen, e.g. the type is wrapped with frozen<type>.
    • isNonFrozenCollection

      public boolean isNonFrozenCollection()
      Returns true if the index type is a non-frozen collection
    • isFrozenCollection

      public boolean isFrozenCollection()
      Returns true if the index type is a frozen collection. This is the inverse of a non-frozen collection but this method is here for clarity.
    • isComposite

      public boolean isComposite()
      Returns true if the index type is a composite type, e.g. it has the form Composite<typea, typeb>
    • isMultiExpression

      public boolean isMultiExpression(RowFilter.Expression expression)
      Returns true if the RowFilter.Expression passed is backed by a non-frozen collection and the Operator is one that cannot be merged together.
    • isValid

      public boolean isValid(ByteBuffer term)
      Returns true if given buffer would pass the AbstractType.validate(ByteBuffer) check. False otherwise.
    • skipsEmptyValue

      public boolean skipsEmptyValue()
      Returns:
      true if the empty values of the given type should be excluded from indexing
    • indexType

      public AbstractType<?> indexType()
    • subTypes

      public Collection<IndexTermType> subTypes()
    • asCQL3Type

      public CQL3Type asCQL3Type()
    • columnMetadata

      public ColumnMetadata columnMetadata()
    • columnName

      public String columnName()
    • vectorElementType

      public AbstractType<?> vectorElementType()
    • vectorDimension

      public int vectorDimension()
    • dependsOn

      public boolean dependsOn(ColumnMetadata columnMetadata)
    • isEqOnlyType

      public static boolean isEqOnlyType(AbstractType<?> type)
    • supportsRounding

      public boolean supportsRounding()
      Indicates if the type encoding supports rounding of the raw value.

      This is significant in range searches where we have to make all range queries inclusive when searching the indexes in order to avoid excluding rounded values. Excluded values are removed by post-filtering.

    • fixedSizeOf

      public int fixedSizeOf()
      Returns the value length for the given AbstractType, selecting 16 for types that officially use VARIABLE_LENGTH but are, in fact, of a fixed length.
    • asString

      public String asString(ByteBuffer value)
      Allows overriding the default getString method for CompositeType. It is a requirement of the ConcurrentRadixTree that the keys are strings but the getString method of CompositeType does not return a string that compares in the same order as the underlying ByteBuffer. To get round this we convert the CompositeType bytes to a hex string.
    • fromString

      public ByteBuffer fromString(String value)
      The inverse of the above method. Overrides the fromString method on CompositeType in order to convert the hex string to bytes.
    • valueOf

      public ByteBuffer valueOf(DecoratedKey key, Row row, long nowInSecs)
      Returns the cell value from the DecoratedKey or Row for the IndexTermType based on the kind of column this IndexTermType is based on.
      Parameters:
      key - the DecoratedKey of the row
      row - the Row containing the non-partition column data
      nowInSecs - the time that the index write operation started
      Returns:
      a ByteBuffer containing the cell value
    • valuesOf

      public Iterator<ByteBuffer> valuesOf(Row row, long nowInSecs)
      Returns a value iterator for collection type IndexTermTypes.
      Parameters:
      row - the Row containing the column data
      nowInSecs - the time that the index write operation started
      Returns:
      an Iterator of the collection values
    • comparator

      public Comparator<ByteBuffer> comparator()
    • compare

      public int compare(ByteBuffer b1, ByteBuffer b2)
      Compare two terms based on their type. This is used in place of AbstractType.compare(ByteBuffer, ByteBuffer) so that the default comparison can be overridden for specific types.

      Note: This should be used for all term comparison

    • min

      public ByteBuffer min(ByteBuffer a, ByteBuffer b)
      Returns the smaller of two ByteBuffer values, based on the result of compare(ByteBuffer, ByteBuffer) comparision.
    • max

      public ByteBuffer max(ByteBuffer a, ByteBuffer b)
      Returns the greater of two ByteBuffer values, based on the result of compare(ByteBuffer, ByteBuffer) comparision.
    • comparePostFilter

      public int comparePostFilter(Expression.Value requestedValue, Expression.Value columnValue)
      This is used for value comparison in post-filtering - Expression.isSatisfiedBy(ByteBuffer).

      This allows types to decide whether they should be compared based on their encoded value or their raw value. At present only InetAddressType values are compared by their encoded values to allow for ipv4 -> ipv6 equivalency in searches.

    • toComparableBytes

      public void toComparableBytes(ByteBuffer value, byte[] bytes)
      Fills a byte array with the comparable bytes for a type.

      This method expects a value parameter generated by calling asIndexBytes(ByteBuffer). It is not generally safe to pass the output of other serialization methods to this method. For instance, it is not generally safe to pass the output of AbstractType.decompose(Object) as the value parameter (there are certain types for which this is technically OK, but that doesn't hold for all types).

      Parameters:
      value - a value buffer returned by asIndexBytes(ByteBuffer)
      bytes - this method's output
    • asComparableBytes

      public ByteSource asComparableBytes(ByteBuffer value, ByteComparable.Version version)
    • asIndexBytes

      public ByteBuffer asIndexBytes(ByteBuffer value)
      Translates the external value of specific types into a format used by the index.
    • decomposeVector

      public float[] decomposeVector(ByteBuffer byteBuffer)
    • supports

      public boolean supports(Operator operator)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • encodeBigInteger

      public static ByteBuffer encodeBigInteger(ByteBuffer value)
      Encode a BigInteger into a fixed width 20 byte encoded value. The encoded value is byte comparable and prefix compressible.

      The format of the encoding is:

      The first 4 bytes contain the integer length of the BigInteger byte array with the top bit flipped for positive values.

      The remaining 16 bytes contain the 16 most significant bytes of the BigInteger byte array.

      For BigInteger values whose underlying byte array is less than 16 bytes, the encoded value is sign extended.

    • encodeDecimal

      public static ByteBuffer encodeDecimal(ByteBuffer value)