Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ExprEval eval(ObjectBinding bindings)
ExprEval eval = estimateExpr.eval(bindings);
final Object valObj = eval.value();
if (valObj == null) {
return ExprEval.of(null);
return ExprEval.ofDouble(null);
}
if (valObj instanceof SketchHolder) {
SketchHolder thetaSketchHolder = (SketchHolder) valObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ExprEval eval(ObjectBinding bindings)
Thread.sleep((long) (seconds * 1000));
}
}
return ExprEval.of(null);
return ExprEval.ofMissing();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ExprEval eval(ObjectBinding bindings)
Thread.sleep((long) (seconds * 1000));
}
}
return ExprEval.of(null);
return ExprEval.ofMissing();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public ExprEval apply(LambdaExpr lambdaExpr, List<Expr> argsExpr, Expr.ObjectBin

Object[] array = arrayEval.asArray();
if (array == null) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}
if (array.length == 0) {
return arrayEval;
Expand Down Expand Up @@ -246,7 +246,7 @@ public ExprEval apply(LambdaExpr lambdaExpr, List<Expr> argsExpr, Expr.ObjectBin
arrayInputs.add(Arrays.asList(array));
}
if (hadNull) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}
if (hadEmpty) {
return ExprEval.ofStringArray(new String[0]);
Expand Down Expand Up @@ -334,7 +334,7 @@ public ExprEval apply(LambdaExpr lambdaExpr, List<Expr> argsExpr, Expr.ObjectBin

Object[] array = arrayEval.asArray();
if (array == null) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}
Object accumulator = accEval.value();

Expand Down Expand Up @@ -401,7 +401,7 @@ public ExprEval apply(LambdaExpr lambdaExpr, List<Expr> argsExpr, Expr.ObjectBin
arrayInputs.add(Arrays.asList(array));
}
if (hadNull) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}
if (hadEmpty) {
return ExprEval.ofStringArray(new Object[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public ExprEval eval(ObjectBinding bindings)
// Result of any Binary expressions is null if any of the argument is null.
// e.g "select null * 2 as c;" or "select null + 1 as c;" will return null as per Standard SQL spec.
if (leftVal.value() == null || rightVal.value() == null) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}

ExpressionType type = ExpressionTypeConversion.autoDetect(leftVal, rightVal);
Expand All @@ -144,7 +144,7 @@ public ExprEval eval(ObjectBinding bindings)
case DOUBLE:
default:
if (leftVal.isNumericNull() || rightVal.isNumericNull()) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}
return ExprEval.of(evalDouble(leftVal.asDouble(), rightVal.asDouble()));
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public ExprEval eval(ObjectBinding bindings)
// Result of any Binary expressions is null if any of the argument is null.
// e.g "select null * 2 as c;" or "select null + 1 as c;" will return null as per Standard SQL spec.
if (leftVal.value() == null || rightVal.value() == null) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}

ExpressionType type = ExpressionTypeConversion.autoDetect(leftVal, rightVal);
Expand All @@ -201,7 +201,7 @@ public ExprEval eval(ObjectBinding bindings)
case DOUBLE:
default:
if (leftVal.isNumericNull() || rightVal.isNumericNull()) {
return ExprEval.of(null);
return ExprEval.ofMissing();
}
result = evalDouble(leftVal.asDouble(), rightVal.asDouble());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected BinaryOpExprBase copy(Expr left, Expr right)
@Override
protected ExprEval evalString(@Nullable String left, @Nullable String right)
{
return ExprEval.of(left + right);
return ExprEval.ofString(left + right);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public ExprEval eval(ObjectBinding bindings)
{
ExprEval<?> toDecode = arg.eval(bindings);
if (toDecode.value() == null) {
return ExprEval.of(null);
return ExprEval.ofString(null);
}
return new StringExpr(StringUtils.fromUtf8(StringUtils.decodeBase64String(toDecode.asString()))).eval(bindings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public String toString()
@Override
protected ExprEval realEval()
{
return ExprEval.of(value);
return ExprEval.ofString(value);
}

@Override
Expand Down
65 changes: 44 additions & 21 deletions processing/src/main/java/org/apache/druid/math/expr/ExprEval.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class ExprEval<T>
* {@link ByteBuffer}. Certain types are deserialized more efficiently if allowed
* to retain references to the provided buffer.
*/
public static ExprEval deserialize(
public static ExprEval<?> deserialize(
final ByteBuffer buffer,
final int offset,
final int maxSize,
Expand Down Expand Up @@ -281,57 +281,80 @@ private static Class convertType(@Nullable Class existing, Class next)
return Object.class;
}

public static ExprEval of(long longValue)
/**
* Eval that represents a null value of undefined type. Commonly used to represent columns that do not exist.
*
* Behaviorally equivalent to {@code ofLong(null)}. Generally, this function is preferred if the type is unknown, and
* {@code ofLong(null)} is preferred if the type is known to be long.
*/
public static ExprEval<?> ofMissing()
{
return LongExprEval.OF_NULL;
}

public static ExprEval<?> of(long longValue)
{
return new LongExprEval(longValue);
}

public static ExprEval of(double doubleValue)
public static ExprEval<?> of(double doubleValue)
{
return new DoubleExprEval(doubleValue);
}

public static ExprEval of(@Nullable String stringValue)
/**
* Equivalent to {@link #ofString(String)}. Deprecated because the pattern {@code ExprEval.of(null)} for
* an "unknown type" null is not recommended-- instead it should be {@link ExprEval#ofMissing()}
*
* @deprecated use {@link #ofString(String)} instead, which is clearer as to type
*/
@Deprecated
public static ExprEval<?> of(@Nullable String stringValue)
{
return ofString(stringValue);
}

public static ExprEval<?> ofString(@Nullable String stringValue)
{
if (stringValue == null) {
return StringExprEval.OF_NULL;
}
return new StringExprEval(stringValue);
}

public static ExprEval ofLong(@Nullable Number longValue)
public static ExprEval<?> ofLong(@Nullable Number longValue)
{
if (longValue == null) {
return LongExprEval.OF_NULL;
}
return new LongExprEval(longValue);
}

public static ExprEval ofDouble(@Nullable Number doubleValue)
public static ExprEval<?> ofDouble(@Nullable Number doubleValue)
{
if (doubleValue == null) {
return DoubleExprEval.OF_NULL;
}
return new DoubleExprEval(doubleValue);
}

public static ExprEval ofLongArray(@Nullable Object[] longValue)
public static ExprEval<?> ofLongArray(@Nullable Object[] longValue)
{
if (longValue == null) {
return ArrayExprEval.OF_NULL_LONG;
}
return new ArrayExprEval(ExpressionType.LONG_ARRAY, longValue);
}

public static ExprEval ofDoubleArray(@Nullable Object[] doubleValue)
public static ExprEval<?> ofDoubleArray(@Nullable Object[] doubleValue)
{
if (doubleValue == null) {
return ArrayExprEval.OF_NULL_DOUBLE;
}
return new ArrayExprEval(ExpressionType.DOUBLE_ARRAY, doubleValue);
}

public static ExprEval ofStringArray(@Nullable Object[] stringValue)
public static ExprEval<?> ofStringArray(@Nullable Object[] stringValue)
{
if (stringValue == null) {
return ArrayExprEval.OF_NULL_STRING;
Expand All @@ -340,7 +363,7 @@ public static ExprEval ofStringArray(@Nullable Object[] stringValue)
}


public static ExprEval ofArray(ExpressionType outputType, @Nullable Object[] value)
public static ExprEval<?> ofArray(ExpressionType outputType, @Nullable Object[] value)
{
Preconditions.checkArgument(outputType.isArray(), "Output type %s is not an array", outputType);
return new ArrayExprEval(outputType, value);
Expand All @@ -349,20 +372,20 @@ public static ExprEval ofArray(ExpressionType outputType, @Nullable Object[] val
/**
* Convert a boolean into a long expression type
*/
public static ExprEval ofLongBoolean(boolean value)
public static ExprEval<?> ofLongBoolean(boolean value)
{
return value ? LongExprEval.TRUE : LongExprEval.FALSE;
}

public static ExprEval ofComplex(ExpressionType outputType, @Nullable Object value)
public static ExprEval<?> ofComplex(ExpressionType outputType, @Nullable Object value)
{
if (ExpressionType.NESTED_DATA.equals(outputType)) {
return new NestedDataExprEval(value);
}
return new ComplexExprEval(outputType, value);
}

public static ExprEval bestEffortArray(@Nullable List<?> theList)
public static ExprEval<?> bestEffortArray(@Nullable List<?> theList)
{
// do not convert empty lists to arrays with a single null element here, because that should have been done
// by the selectors preparing their ObjectBindings if necessary. If we get to this point it was legitimately
Expand All @@ -377,13 +400,13 @@ public static ExprEval bestEffortArray(@Nullable List<?> theList)
/**
* Examine java type to find most appropriate expression type
*/
public static ExprEval bestEffortOf(@Nullable Object val)
public static ExprEval<?> bestEffortOf(@Nullable Object val)
{
if (val == null) {
return StringExprEval.OF_NULL;
return LongExprEval.OF_NULL;
}
if (val instanceof ExprEval) {
return (ExprEval) val;
return (ExprEval<?>) val;
}
if (val instanceof String) {
return new StringExprEval((String) val);
Expand Down Expand Up @@ -496,7 +519,7 @@ public static ExprEval bestEffortOf(@Nullable Object val)
* @param type type, or null to be equivalent to {@link #bestEffortOf(Object)}
* @param value object to be coerced to the type
*/
public static ExprEval ofType(@Nullable ExpressionType type, @Nullable Object value)
public static ExprEval<?> ofType(@Nullable ExpressionType type, @Nullable Object value)
{
if (type == null) {
return bestEffortOf(value);
Expand All @@ -521,7 +544,7 @@ public static ExprEval ofType(@Nullable ExpressionType type, @Nullable Object va
if (value instanceof byte[]) {
return new StringExprEval(StringUtils.encodeBase64String((byte[]) value));
}
return of(Evals.asString(value));
return ofString(Evals.asString(value));
case LONG:
if (value instanceof Number) {
return ofLong((Number) value);
Expand Down Expand Up @@ -844,7 +867,7 @@ public final ExprEval castTo(ExpressionType castTo)
return ExprEval.of(asLong());
}
case STRING:
return ExprEval.of(asString());
return ExprEval.ofString(asString());
case ARRAY:
switch (castTo.getElementType().getType()) {
case DOUBLE:
Expand Down Expand Up @@ -918,7 +941,7 @@ public final ExprEval castTo(ExpressionType castTo)
case LONG:
return this;
case STRING:
return ExprEval.of(asString());
return ExprEval.ofString(asString());
case ARRAY:
if (value == null) {
return new ArrayExprEval(castTo, null);
Expand Down Expand Up @@ -1283,7 +1306,7 @@ public ExprEval castTo(ExpressionType castTo)
switch (castTo.getType()) {
case STRING:
if (value.length == 1) {
return ExprEval.of(asString());
return ExprEval.ofString(asString());
}
return ExprEval.ofType(castTo, null);
case LONG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void exitFunctionArgs(ExprParser.FunctionArgsContext ctx)
@Override
public void exitNull(ExprParser.NullContext ctx)
{
nodes.put(ctx, new StringExpr(null));
nodes.put(ctx, new NullLongExpr());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ public class ExpressionProcessing
@VisibleForTesting
public static void initializeForTests()
{
INSTANCE = new ExpressionProcessingConfig(null, null, null, null);
INSTANCE = new ExpressionProcessingConfig(null, null, null);
}

@VisibleForTesting
public static void initializeForHomogenizeNullMultiValueStrings()
{
INSTANCE = new ExpressionProcessingConfig(null, null, true, null);
INSTANCE = new ExpressionProcessingConfig(null, true, null);
}

@VisibleForTesting
public static void initializeForFallback()
{
INSTANCE = new ExpressionProcessingConfig(null, null, null, true);
INSTANCE = new ExpressionProcessingConfig(null, null, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.java.util.common.logger.Logger;

import javax.annotation.Nullable;

public class ExpressionProcessingConfig
{
private static final Logger LOG = new Logger(ExpressionProcessingConfig.class);

public static final String NULL_HANDLING_LEGACY_LOGICAL_OPS_STRING = "druid.expressions.useStrictBooleans";
// Coerce arrays to multi value strings
public static final String PROCESS_ARRAYS_AS_MULTIVALUE_STRINGS_CONFIG_STRING =
Expand All @@ -47,23 +44,13 @@ public class ExpressionProcessingConfig
@JsonProperty("allowVectorizeFallback")
private final boolean allowVectorizeFallback;

@Deprecated
@JsonProperty("useStrictBooleans")
private final boolean useStrictBooleans;

@JsonCreator
public ExpressionProcessingConfig(
@Deprecated @JsonProperty("useStrictBooleans") @Nullable Boolean useStrictBooleans,
@JsonProperty("processArraysAsMultiValueStrings") @Nullable Boolean processArraysAsMultiValueStrings,
@JsonProperty("homogenizeNullMultiValueStringArrays") @Nullable Boolean homogenizeNullMultiValueStringArrays,
@JsonProperty("allowVectorizeFallback") @Nullable Boolean allowVectorizeFallback
)
{
this.useStrictBooleans = getWithPropertyFallback(
useStrictBooleans,
NULL_HANDLING_LEGACY_LOGICAL_OPS_STRING,
"true"
);
this.processArraysAsMultiValueStrings = getWithPropertyFallbackFalse(
processArraysAsMultiValueStrings,
PROCESS_ARRAYS_AS_MULTIVALUE_STRINGS_CONFIG_STRING
Expand Down
Loading