Class 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 Detail

      • 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
      • of

        public static ExprEval of​(long longValue)
      • of

        public static ExprEval of​(double doubleValue)
      • ofLongBoolean

        public static ExprEval ofLongBoolean​(boolean value)
        Convert a boolean into a long expression type
      • bestEffortOf

        public static ExprEval bestEffortOf​(@Nullable
                                            Object val)
        Examine java type to find most appropriate expression type
      • 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.
      • valueOrDefault

        @Nullable
        public T valueOrDefault()
      • 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. Note that all types must still return values for asInt(), asLong()}, and asDouble(), since this can still happen if NullHandling.sqlCompatible() is false, but it should be assumed that this can only happen in that mode and 0s are typical and expected for values that would otherwise be null.
      • 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, which is expected if NullHandling.sqlCompatible() is false)
      • 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, which is expected if NullHandling.sqlCompatible() is false)
      • 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, which is expected if NullHandling.sqlCompatible() is false)
      • asBoolean

        public abstract boolean asBoolean()
      • toExpr

        public abstract Expr toExpr()