Class ExprEval<T>

java.lang.Object
org.apache.druid.math.expr.ExprEval<T>

public abstract class ExprEval<T> extends Object
Generic result holder for evaluated Expr containing the value and ExprType of the value to allow
  • Method Details

    • deserialize

      public static ExprEval<?> deserialize(ByteBuffer buffer, int offset, int maxSize, ExpressionType type, boolean canRetainBufferReference)
      Deserialize an expression stored in a bytebuffer, e.g. for an agg. This method is not thread-safe with respect to the provided ByteBuffer, because the position of the buffer may be changed transiently during execution of this method. However, it will be restored to its original position prior to the method completing. Therefore, if the provided buffer is being used by a single thread, then this method does not change the position of the buffer. The canRetainBufferReference parameter determines
      Parameters:
      buffer - source buffer
      offset - position to start reading from
      maxSize - maximum number of bytes from "offset" that may be required. This is used as advice, but is not strictly enforced in all cases. It is possible that type strategies may attempt reads past this limit.
      type - data type to read
      canRetainBufferReference - whether the returned ExprEval may retain a reference to the provided ByteBuffer. Certain types are deserialized more efficiently if allowed to retain references to the provided buffer.
    • serialize

      public static void serialize(ByteBuffer buffer, int position, ExpressionType type, ExprEval<?> eval, int maxSizeBytes)
      Write an expression result to a bytebuffer, throwing an ISE if the data exceeds a maximum size. Primitive numeric types are not validated to be lower than max size, so it is expected to be at least 10 bytes. Callers of this method should enforce this themselves (instead of doing it here, which might be done every row) This should be refactored to be consolidated with some of the standard type handling of aggregators probably
    • coerceListToArray

      @Nullable public static NonnullPair<ExpressionType,Object[]> coerceListToArray(@Nullable List<?> val, boolean homogenizeMultiValueStrings)
      Converts a List to an appropriate array type, optionally doing some conversion to make multi-valued strings consistent across selector types, which are not consistent in treatment of null, [], and [null]. If homogenizeMultiValueStrings is true, null and [] will be converted to [null], otherwise they will retain
    • ofMissing

      public static ExprEval<?> ofMissing()
      Eval that represents a null value of undefined type. Commonly used to represent columns that do not exist. Behaviorally equivalent to ofLong(null). Generally, this function is preferred if the type is unknown, and ofLong(null) is preferred if the type is known to be long.
    • of

      public static ExprEval<?> of(long longValue)
    • of

      public static ExprEval<?> of(double doubleValue)
    • of

      @Deprecated public static ExprEval<?> of(@Nullable String stringValue)
      Deprecated.
      use ofString(String) instead, which is clearer as to type
      Equivalent to ofString(String). Deprecated because the pattern ExprEval.of(null) for an "unknown type" null is not recommended-- instead it should be ofMissing()
    • ofString

      public static ExprEval<?> ofString(@Nullable String stringValue)
    • ofLong

      public static ExprEval<?> ofLong(@Nullable Number longValue)
    • ofDouble

      public static ExprEval<?> ofDouble(@Nullable Number doubleValue)
    • ofLongArray

      public static ExprEval<?> ofLongArray(@Nullable Object[] longValue)
    • ofDoubleArray

      public static ExprEval<?> ofDoubleArray(@Nullable Object[] doubleValue)
    • ofStringArray

      public static ExprEval<?> ofStringArray(@Nullable Object[] stringValue)
    • ofArray

      public static ExprEval<?> ofArray(ExpressionType outputType, @Nullable Object[] value)
    • ofLongBoolean

      public static ExprEval<?> ofLongBoolean(boolean value)
      Convert a boolean into a long expression type
    • ofComplex

      public static ExprEval<?> ofComplex(ExpressionType outputType, @Nullable Object value)
    • bestEffortArray

      public static ExprEval<?> bestEffortArray(@Nullable List<?> theList)
    • bestEffortOf

      public static ExprEval<?> bestEffortOf(@Nullable Object val)
      Examine java type to find most appropriate expression type
    • ofType

      public static ExprEval<?> ofType(@Nullable ExpressionType type, @Nullable Object value)
      Create an eval of the provided type. Coerces the provided object to the desired type.
      Parameters:
      type - type, or null to be equivalent to bestEffortOf(Object)
      value - object to be coerced to the type
    • computeNumber

      @Nullable public static Number computeNumber(@Nullable String value)
    • castForEqualityComparison

      @Nullable public static ExprEval<?> castForEqualityComparison(ExprEval<?> valueToCompare, ExpressionType typeToCompareWith)
      Cast an ExprEval to some ExpressionType that the value will be compared with. If the value is not appropriate to use for comparison after casting, this method returns null. For example, the ExpressionType.DOUBLE value 1.1 when cast to ExpressionType.LONG becomes 1L, which is no longer appropriate to use for value equality comparisons, while 1.0 is valid.
    • type

      public abstract ExpressionType type()
    • elementType

      public ExpressionType elementType()
    • asArrayType

      public ExpressionType asArrayType()
    • value

      @Nullable public T value()
    • asString

      @Nullable public String asString()
    • isNumericNull

      public abstract boolean isNumericNull()
      The method returns true if numeric primitive value for this ExprEval is null, otherwise false. If this method returns false, then the values returned by asLong(), asDouble(), and asInt() are "valid", since this method is primarily used during Expr evaluation to decide if primitive numbers can be fetched to use. If a type cannot sanely convert into a primitive numeric value, then this method should always return true so that these primitive numeric getters are not called, since returning false is assumed to mean these values are valid.
    • isArray

      public boolean isArray()
    • asInt

      public abstract int asInt()
      Get the primitive integer value. Callers should check isNumericNull() prior to calling this method, otherwise it may improperly return placeholder a value (typically zero)
    • asLong

      public abstract long asLong()
      Get the primitive long value. Callers should check isNumericNull() prior to calling this method, otherwise it may improperly return a placeholder value (typically zero)
    • asDouble

      public abstract double asDouble()
      Get the primitive double value. Callers should check isNumericNull() prior to calling this method, otherwise it may improperly return a placeholder value (typically zero)
    • asBoolean

      public abstract boolean asBoolean()
    • asArray

      @Nullable public abstract Object[] asArray()
    • castTo

      public abstract ExprEval castTo(ExpressionType castTo)
    • toExpr

      public abstract Expr toExpr()
    • invalidCast

      public static Types.InvalidCastException invalidCast(ExpressionType fromType, ExpressionType toType)