Skip to content

Commit 7b669b8

Browse files
fix test failures
1 parent 5a152ab commit 7b669b8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/Bucket.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,9 @@ public Expression surrogate(SearchStats searchStats) {
520520
var max = searchStats.max(fieldName);
521521
// If min/max is available create rounding with them
522522
if (min != null && max != null && buckets().foldable()) {
523-
// System.out.println("field: " + fieldName + ", min string: " + dateWithTypeToString((Long) min, fieldType));
524-
// System.out.println("field: " + fieldName + ", max string: " + dateWithTypeToString((Long) max, fieldType));
523+
// System.out.println("field: " + fieldName + ", min: " + min + ", " + dateWithTypeToString((Long) min, fieldType));
524+
// System.out.println("field: " + fieldName + ", max: " + max + ", " + dateWithTypeToString((Long) max, fieldType));
525525
Rounding.Prepared rounding = getDateRounding(FoldContext.small(), (Long) min, (Long) max);
526-
// createRounding(foldedInterval, DEFAULT_TZ, (Long) min, (Long) max);
527526
long[] roundingPoints = rounding.fixedRoundingPoints();
528527
// the min/max long values for date and date_nanos are correct, however the roundingPoints for date_nanos is null
529528
// System.out.println("roundingPoints = " + Arrays.toString(roundingPoints));

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/stats/SearchContextStats.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
3131
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
3232
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute.FieldName;
33+
import org.elasticsearch.xpack.esql.core.util.Holder;
3334

3435
import java.io.IOException;
3536
import java.util.LinkedHashMap;
@@ -205,17 +206,19 @@ public Object min(FieldName field) {
205206
}
206207
if (stat.min == null) {
207208
var min = new long[] { Long.MAX_VALUE };
209+
Holder<Boolean> foundMinValue = new Holder<>(false);
208210
doWithContexts(r -> {
209211
byte[] minPackedValue = PointValues.getMinPackedValue(r, field.string());
210212
if (minPackedValue != null) {
211213
long minValue = NumericUtils.sortableBytesToLong(minPackedValue, 0);
212-
if (minValue < min[0]) {
214+
if (minValue <= min[0]) {
213215
min[0] = minValue;
216+
foundMinValue.set(true);
214217
}
215218
}
216219
return true;
217220
}, true);
218-
stat.min = min[0];
221+
stat.min = foundMinValue.get() ? min[0] : null;
219222
}
220223
return stat.min;
221224
}
@@ -230,17 +233,19 @@ public Object max(FieldName field) {
230233
}
231234
if (stat.max == null) {
232235
var max = new long[] { Long.MIN_VALUE };
236+
Holder<Boolean> foundMaxValue = new Holder<>(false);
233237
doWithContexts(r -> {
234238
byte[] maxPackedValue = PointValues.getMaxPackedValue(r, field.string());
235239
if (maxPackedValue != null) {
236240
long maxValue = NumericUtils.sortableBytesToLong(maxPackedValue, 0);
237-
if (maxValue > max[0]) {
241+
if (maxValue >= max[0]) {
238242
max[0] = maxValue;
243+
foundMaxValue.set(true);
239244
}
240245
}
241246
return true;
242247
}, true);
243-
stat.max = max[0];
248+
stat.max = foundMaxValue.get() ? max[0] : null;
244249
}
245250
return stat.max;
246251
}

0 commit comments

Comments
 (0)