Skip to content

Commit dcf319d

Browse files
committed
blacklist function that may output multivalued
1 parent edc7a1f commit dcf319d

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/approximate/Approximate.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.xpack.esql.expression.function.aggregate.StdDev;
3131
import org.elasticsearch.xpack.esql.expression.function.aggregate.Sum;
3232
import org.elasticsearch.xpack.esql.expression.function.aggregate.WeightedAvg;
33+
import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction;
3334
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToLong;
3435
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.ConfidenceInterval;
3536
import org.elasticsearch.xpack.esql.expression.function.scalar.multivalue.MvAppend;
@@ -142,6 +143,10 @@ public interface LogicalPlanRunner {
142143
org.elasticsearch.xpack.esql.expression.function.aggregate.Sample.class
143144
);
144145

146+
private static final Set<Class<? extends EsqlScalarFunction>> MULTI_VALUED_OUTPUT_FUNCTIONS = Set.of(
147+
MvAppend.class
148+
);
149+
145150
// TODO: find a good default value, or alternative ways of setting it
146151
private static final int SAMPLE_ROW_COUNT = 100000;
147152

@@ -402,7 +407,7 @@ private LogicalPlan approximatePlan(double sampleProbability) {
402407
case Eval eval:
403408
List<Alias> newFields = new ArrayList<>(eval.fields());
404409
for (Alias field : eval.fields()) {
405-
if (field.dataType().isNumeric() == false || field.child().anyMatch(expr -> expr instanceof MvAppend)) {
410+
if (field.dataType().isNumeric() == false || field.child().anyMatch(expr -> MULTI_VALUED_OUTPUT_FUNCTIONS.contains(expr.getClass()))) {
406411
continue;
407412
}
408413
if (field.child().anyMatch(expr -> expr instanceof NamedExpression named && variablesWithConfidenceInterval.containsKey(named.id()))) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/multivalue/ConfidenceInterval.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public boolean equals(Object obj) {
131131

132132
@Evaluator(extraName = "Double")
133133
static void process(DoubleBlock.Builder builder, @Position int position, DoubleBlock bestEstimateBlock, DoubleBlock estimatesBlock) {
134-
assert bestEstimateBlock.getValueCount(position) == 1 : "bestEstimate: expected 1 element, got " + bestEstimateBlock.getValueCount(position);
134+
if (bestEstimateBlock.getValueCount(position) != 1) {
135+
builder.appendNull();
136+
}
135137
Number bestEstimate = bestEstimateBlock.getDouble(bestEstimateBlock.getFirstValueIndex(position));
136138

137139
Number[] estimates = new Number[estimatesBlock.getValueCount(position)];
@@ -145,13 +147,14 @@ static void process(DoubleBlock.Builder builder, @Position int position, DoubleB
145147
builder.appendDouble(v.doubleValue());
146148
}
147149
builder.endPositionEntry();
148-
149-
System.out.println("@@@ bestEstimate = " + bestEstimate + ", estimates = " + Arrays.toString(estimates) + " --> confidenceInterval = " + Arrays.toString(confidenceInterval));
150150
}
151151

152152
@Evaluator(extraName = "Int")
153153
static void process(IntBlock.Builder builder, @Position int position, IntBlock bestEstimateBlock, IntBlock estimatesBlock) {
154-
assert bestEstimateBlock.getValueCount(position) == 1 : "bestEstimate: expected 1 element, got " + bestEstimateBlock.getValueCount(position);
154+
if (bestEstimateBlock.getValueCount(position) != 1) {
155+
builder.appendNull();
156+
return;
157+
}
155158
Number bestEstimate = bestEstimateBlock.getInt(bestEstimateBlock.getFirstValueIndex(position));
156159

157160
Number[] estimates = new Number[estimatesBlock.getValueCount(position)];
@@ -169,7 +172,10 @@ static void process(IntBlock.Builder builder, @Position int position, IntBlock b
169172

170173
@Evaluator(extraName = "Long")
171174
static void process(LongBlock.Builder builder, @Position int position, LongBlock bestEstimateBlock, LongBlock estimatesBlock) {
172-
assert bestEstimateBlock.getValueCount(position) == 1 : "bestEstimate: expected 1 element, got " + bestEstimateBlock.getValueCount(position);
175+
if (bestEstimateBlock.getValueCount(position) != 1) {
176+
builder.appendNull();
177+
return;
178+
}
173179
Number bestEstimate = bestEstimateBlock.getLong(bestEstimateBlock.getFirstValueIndex(position));
174180

175181
Number[] estimates = new Number[estimatesBlock.getValueCount(position)];

0 commit comments

Comments
 (0)