Package org.apache.druid.math.expr
Class ExprEval<T>
java.lang.Object
org.apache.druid.math.expr.ExprEval<T>
-
Method Summary
Modifier and TypeMethodDescriptionabstract Object[]asArray()abstract booleanabstract doubleasDouble()Get the primitive double value.abstract intasInt()Get the primitive integer value.abstract longasLong()Get the primitive long value.asString()static ExprEval<?>bestEffortArray(List<?> theList) static ExprEval<?>bestEffortOf(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 ExprEval<?>deserialize(ByteBuffer buffer, int offset, int maxSize, ExpressionType type, boolean canRetainBufferReference) Deserialize an expression stored in a bytebuffer, e.g.static Types.InvalidCastExceptioninvalidCast(ExpressionType fromType, ExpressionType toType) booleanisArray()abstract booleanThe method returns true if numeric primitive value for thisExprEvalis null, otherwise false.static ExprEval<?>of(double doubleValue) static ExprEval<?>of(long longValue) static ExprEval<?>Deprecated.static ExprEval<?>ofArray(ExpressionType outputType, Object[] value) static ExprEval<?>ofComplex(ExpressionType outputType, Object value) static ExprEval<?>static ExprEval<?>ofDoubleArray(Object[] doubleValue) static ExprEval<?>static ExprEval<?>ofLongArray(Object[] longValue) static ExprEval<?>ofLongBoolean(boolean value) Convert a boolean into a long expression typestatic ExprEval<?>Eval that represents a null value of undefined type.static ExprEval<?>static ExprEval<?>ofStringArray(Object[] stringValue) static ExprEval<?>ofType(ExpressionType type, Object value) Create an eval of the provided type.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()value()
-
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 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 -
ofMissing
Eval that represents a null value of undefined type. Commonly used to represent columns that do not exist. Behaviorally equivalent toofLong(null). Generally, this function is preferred if the type is unknown, andofLong(null)is preferred if the type is known to be long. -
of
-
of
-
of
Deprecated.useofString(String)instead, which is clearer as to typeEquivalent toofString(String). Deprecated because the patternExprEval.of(null)for an "unknown type" null is not recommended-- instead it should beofMissing() -
ofString
-
ofLong
-
ofDouble
-
ofLongArray
-
ofDoubleArray
-
ofStringArray
-
ofArray
-
ofLongBoolean
Convert a boolean into a long expression type -
ofComplex
-
bestEffortArray
-
bestEffortOf
Examine java type to find most appropriate expression type -
ofType
Create an eval of the provided type. Coerces the provided object to the desired type.- Parameters:
type- type, or null to be equivalent tobestEffortOf(Object)value- object to be coerced to the type
-
computeNumber
-
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
-
elementType
-
asArrayType
-
value
-
asString
-
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. -
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) -
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) -
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) -
asBoolean
public abstract boolean asBoolean() -
asArray
-
castTo
-
toExpr
-
invalidCast
public static Types.InvalidCastException invalidCast(ExpressionType fromType, ExpressionType toType)
-
ofString(String)instead, which is clearer as to type