Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tighten up array handling, fix bug with array_slice output type inference #12914

Merged
merged 10 commits into from
Aug 25, 2022
20 changes: 13 additions & 7 deletions core/src/main/java/org/apache/druid/math/expr/ApplyFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public ExprEval apply(LambdaExpr lambdaExpr, List<Expr> argsExpr, Expr.ObjectBin
return ExprEval.of(null);
}
if (hadEmpty) {
return ExprEval.ofStringArray(new String[0]);
return ExprEval.ofStringArray(new Object[0]);
}
Expr accExpr = argsExpr.get(argsExpr.size() - 1);

Expand Down Expand Up @@ -576,9 +576,12 @@ public String name()
@Override
public ExprEval match(Object[] values, LambdaExpr expr, SettableLambdaBinding bindings)
{
boolean anyMatch = Arrays.stream(values)
.anyMatch(o -> expr.eval(bindings.withBinding(expr.getIdentifier(), o)).asBoolean());
return ExprEval.ofLongBoolean(anyMatch);
for (Object o : values) {
if (expr.eval(bindings.withBinding(expr.getIdentifier(), o)).asBoolean()) {
return ExprEval.ofLongBoolean(true);
}
}
return ExprEval.ofLongBoolean(false);
}
}

Expand All @@ -599,9 +602,12 @@ public String name()
@Override
public ExprEval match(Object[] values, LambdaExpr expr, SettableLambdaBinding bindings)
{
boolean allMatch = Arrays.stream(values)
.allMatch(o -> expr.eval(bindings.withBinding(expr.getIdentifier(), o)).asBoolean());
return ExprEval.ofLongBoolean(allMatch);
for (Object o : values) {
if (!expr.eval(bindings.withBinding(expr.getIdentifier(), o)).asBoolean()) {
return ExprEval.ofLongBoolean(false);
}
}
return ExprEval.ofLongBoolean(true);
}
}

Expand Down
15 changes: 12 additions & 3 deletions core/src/main/java/org/apache/druid/math/expr/Evals.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.apache.druid.math.expr;

import org.apache.druid.common.config.NullHandling;
import org.apache.druid.java.util.common.logger.Logger;

import javax.annotation.Nullable;
import java.util.Arrays;
Expand All @@ -30,8 +29,6 @@
*/
public class Evals
{
private static final Logger log = new Logger(Evals.class);

public static boolean isAllConstants(Expr... exprs)
{
return isAllConstants(Arrays.asList(exprs));
Expand Down Expand Up @@ -71,4 +68,16 @@ public static boolean asBoolean(@Nullable String x)
{
return !NullHandling.isNullOrEquivalent(x) && Boolean.parseBoolean(x);
}

/**
* Call {@link Object#toString()} on a non-null value
*/
@Nullable
public static String asString(@Nullable Object o)
{
if (o == null) {
return null;
}
return o.toString();
}
}
Loading