Class VectorCodec<E>

java.lang.Object
org.apache.cassandra.cql3.functions.types.TypeCodec<List<E>>
org.apache.cassandra.cql3.functions.types.VectorCodec<E>
Type Parameters:
E - The type of the vector elements.

public abstract class VectorCodec<E> extends TypeCodec<List<E>>
TypeCodec for the CQL type vector. Vectors are represented as Lists for convenience, since it's probably easier for UDFs trying to return a newly created vector to create it as a standard Java list, rather than using a custom, not-standard vector class.
  • Field Details

  • Method Details

    • of

      public static <E> VectorCodec<E> of(VectorType type, TypeCodec<E> subtypeCodec)
    • parse

      public List<E> parse(String value) throws InvalidTypeException
      Description copied from class: TypeCodec
      Parse the given CQL literal into an instance of the Java type handled by this codec.

      Implementors should take care of unquoting and unescaping the given CQL string where applicable. Null values and empty Strings should be accepted, as well as the string "NULL"; in most cases, implementations should interpret these inputs has equivalent to a null reference.

      Implementing this method is not strictly mandatory: internally, the driver only uses it to parse the INITCOND when building the metadata of an aggregate function (and in most cases it will use a built-in codec, unless the INITCOND has a custom type).

      Specified by:
      parse in class TypeCodec<List<E>>
      Parameters:
      value - The CQL string to parse, may be null or empty.
      Returns:
      An instance of T; may be null on a null input.
      Throws:
      InvalidTypeException - if the given value cannot be parsed into the expected type
    • format

      public String format(List<E> value) throws InvalidTypeException
      Description copied from class: TypeCodec
      Format the given value as a valid CQL literal according to the CQL type handled by this codec.

      Implementors should take care of quoting and escaping the resulting CQL literal where applicable. Null values should be accepted; in most cases, implementations should return the CQL keyword "NULL" for null inputs.

      Implementing this method is not strictly mandatory. It is used:

      1. in the query builder, when values are inlined in the query string (see querybuilder.BuiltStatement for a detailed explanation of when this happens);
      2. in the QueryLogger, if parameter logging is enabled;
      3. to format the INITCOND in AggregateMetadata#asCQLQuery(boolean);
      4. in the toString() implementation of some objects (UDTValue, TupleValue, and the internal representation of a ROWS response), which may appear in driver logs.

      If you choose not to implement this method, you should not throw an exception but instead return a constant string (for example "XxxCodec.format not implemented").

      Specified by:
      format in class TypeCodec<List<E>>
      Parameters:
      value - An instance of T; may be null.
      Returns:
      CQL string
      Throws:
      InvalidTypeException - if the given value does not have the expected type