Package org.apache.druid.math.expr
Class ExprEval<T>
- java.lang.Object
-
- org.apache.druid.math.expr.ExprEval<T>
-
public abstract class ExprEval<T> extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract Object[]asArray()ExpressionTypeasArrayType()abstract booleanasBoolean()abstract doubleasDouble()Get the primitive double value.abstract intasInt()Get the primitive integer value.abstract longasLong()Get the primitive long value.StringasString()static ExprEvalbestEffortArray(List<?> theList)static ExprEvalbestEffortOf(Object val)Examine java type to find most appropriate expression typestatic ExprEval<?>castForEqualityComparison(ExprEval<?> valueToCompare, ExpressionType typeToCompareWith)Cast anExprEvalto someExpressionTypethat the value will be compared with.abstract ExprEvalcastTo(ExpressionType castTo)static NonnullPair<ExpressionType,Object[]>coerceListToArray(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].static NumbercomputeNumber(String value)static ExprEvaldeserialize(ByteBuffer buffer, int offset, int maxSize, ExpressionType type, boolean canRetainBufferReference)Deserialize an expression stored in a bytebuffer, e.g.ExpressionTypeelementType()static Types.InvalidCastExceptioninvalidCast(ExpressionType fromType, ExpressionType toType)booleanisArray()abstract booleanisNumericNull()The method returns true if numeric primitive value for thisExprEvalis null, otherwise false.static ExprEvalof(double doubleValue)static ExprEvalof(long longValue)static ExprEvalof(String stringValue)static ExprEvalofArray(ExpressionType outputType, Object[] value)static ExprEvalofBoolean(boolean value, ExpressionType type)Deprecated.static ExprEvalofComplex(ExpressionType outputType, Object value)static ExprEvalofDouble(Number doubleValue)static ExprEvalofDoubleArray(Object[] doubleValue)static ExprEvalofLong(Number longValue)static ExprEvalofLongArray(Object[] longValue)static ExprEvalofLongBoolean(boolean value)Convert a boolean into a long expression typestatic ExprEvalofStringArray(Object[] stringValue)static ExprEvalofType(ExpressionType type, Object value)static voidserialize(ByteBuffer buffer, int position, ExpressionType type, ExprEval<?> eval, int maxSizeBytes)Write an expression result to a bytebuffer, throwing anISEif the data exceeds a maximum size.abstract ExprtoExpr()abstract ExpressionTypetype()Tvalue()TvalueOrDefault()
-
-
-
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 providedByteBuffer, 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. ThecanRetainBufferReferenceparameter determines- Parameters:
buffer- source bufferoffset- position to start reading frommaxSize- 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 readcanRetainBufferReference- whether the returnedExprEvalmay retain a reference to the providedByteBuffer. 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 anISEif 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)
-
ofArray
public static ExprEval ofArray(ExpressionType outputType, @Nullable Object[] value)
-
ofBoolean
@Deprecated public static ExprEval ofBoolean(boolean value, ExpressionType type)
Deprecated.Convert a boolean back into native expression type Do not use this method unlessExpressionProcessing.useStrictBooleans()is set to false.ExpressionType.LONGis the Druid boolean unless this mode is enabled, so useofLongBoolean(boolean)instead.
-
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)
-
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)
-
castForEqualityComparison
@Nullable public static ExprEval<?> castForEqualityComparison(ExprEval<?> valueToCompare, ExpressionType typeToCompareWith)
Cast anExprEvalto someExpressionTypethat the value will be compared with. If the value is not appropriate to use for comparison after casting, this method returns null. For example, theExpressionType.DOUBLEvalue 1.1 when cast toExpressionType.LONGbecomes 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()
-
isNumericNull
public abstract boolean isNumericNull()
The method returns true if numeric primitive value for thisExprEvalis null, otherwise false. If this method returns false, then the values returned byasLong(),asDouble(), andasInt()are "valid", since this method is primarily used duringExprevaluation 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 forasInt(),asLong()}, andasDouble(), since this can still happen ifNullHandling.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 checkisNumericNull()prior to calling this method, otherwise it may improperly return placeholder a value (typically zero, which is expected ifNullHandling.sqlCompatible()is false)
-
asLong
public abstract long asLong()
Get the primitive long value. Callers should checkisNumericNull()prior to calling this method, otherwise it may improperly return a placeholder value (typically zero, which is expected ifNullHandling.sqlCompatible()is false)
-
asDouble
public abstract double asDouble()
Get the primitive double value. Callers should checkisNumericNull()prior to calling this method, otherwise it may improperly return a placeholder value (typically zero, which is expected ifNullHandling.sqlCompatible()is false)
-
asBoolean
public abstract boolean asBoolean()
-
castTo
public abstract ExprEval castTo(ExpressionType castTo)
-
toExpr
public abstract Expr toExpr()
-
invalidCast
public static Types.InvalidCastException invalidCast(ExpressionType fromType, ExpressionType toType)
-
-