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()
ExpressionType
asArrayType()
abstract boolean
asBoolean()
abstract double
asDouble()
Get the primitive double value.abstract int
asInt()
Get the primitive integer value.abstract long
asLong()
Get the primitive long value.String
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 anExprEval
to someExpressionType
that the value will be compared with.abstract ExprEval
castTo(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 Number
computeNumber(String value)
static ExprEval
deserialize(ByteBuffer buffer, int offset, int maxSize, ExpressionType type, boolean canRetainBufferReference)
Deserialize an expression stored in a bytebuffer, e.g.ExpressionType
elementType()
static IAE
invalidCast(ExpressionType fromType, ExpressionType toType)
boolean
isArray()
abstract boolean
isNumericNull()
The method returns true if numeric primitive value for thisExprEval
is null, otherwise false.static ExprEval
of(double doubleValue)
static ExprEval
of(long longValue)
static ExprEval
of(String stringValue)
static ExprEval
ofArray(ExpressionType outputType, Object[] value)
static ExprEval
ofBoolean(boolean value, ExprType type)
Deprecated.static ExprEval
ofComplex(ExpressionType outputType, Object value)
static ExprEval
ofDouble(Number doubleValue)
static ExprEval
ofDoubleArray(Object[] doubleValue)
static ExprEval
ofLong(Number longValue)
static ExprEval
ofLongArray(Object[] longValue)
static ExprEval
ofLongBoolean(boolean value)
Convert a boolean into a long expression typestatic ExprEval
ofStringArray(Object[] stringValue)
static ExprEval
ofType(ExpressionType type, Object value)
static void
serialize(ByteBuffer buffer, int position, ExpressionType type, ExprEval<?> eval, int maxSizeBytes)
Write an expression result to a bytebuffer, throwing anISE
if the data exceeds a maximum size.abstract Expr
toExpr()
abstract ExpressionType
type()
T
value()
T
valueOrDefault()
-
-
-
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. ThecanRetainBufferReference
parameter 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 returnedExprEval
may 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 anISE
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)
-
ofArray
public static ExprEval ofArray(ExpressionType outputType, @Nullable Object[] value)
-
ofBoolean
@Deprecated public static ExprEval ofBoolean(boolean value, ExprType type)
Deprecated.Convert a boolean back into native expression type Do not use this method unlessExpressionProcessing.useStrictBooleans()
is set to false.ExpressionType.LONG
is 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 anExprEval
to someExpressionType
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, theExpressionType.DOUBLE
value 1.1 when cast toExpressionType.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()
-
isNumericNull
public abstract boolean isNumericNull()
The method returns true if numeric primitive value for thisExprEval
is null, otherwise false. If this method returns false, then the values returned byasLong()
,asDouble()
, andasInt()
are "valid", since this method is primarily used duringExpr
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 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 IAE invalidCast(ExpressionType fromType, ExpressionType toType)
-
-