Skip to content

Commit ee1ebde

Browse files
committed
Cleanup and enable more tests
1 parent e470f7d commit ee1ebde

File tree

14 files changed

+56
-67
lines changed

14 files changed

+56
-67
lines changed

docs/reference/query-languages/esql/images/functions/knn.svg

Lines changed: 1 addition & 1 deletion
Loading

x-pack/plugin/esql/compute/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
requires org.elasticsearch.geo;
2222
requires org.elasticsearch.xcore;
2323
requires hppc;
24-
requires commons.math3;
2524
requires org.elasticsearch.exponentialhistogram;
2625

2726
exports org.elasticsearch.compute;

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ExponentialHistogramArrayBlock.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.core.Releasables;
1515
import org.elasticsearch.exponentialhistogram.AbstractExponentialHistogram;
1616
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;
17+
import org.elasticsearch.exponentialhistogram.ExponentialHistogramCircuitBreaker;
1718
import org.elasticsearch.exponentialhistogram.ZeroBucket;
1819

1920
import java.io.IOException;
@@ -22,7 +23,7 @@
2223

2324
public final class ExponentialHistogramArrayBlock extends AbstractNonThreadSafeRefCounted implements ExponentialHistogramBlock {
2425

25-
// TODO: Add AggregateMetricDoubleBlock for min/max/sum/count
26+
// TODO(b/133393): Add blocks for min/max/sum/count
2627
private final BytesRefBlock encodedHistograms;
2728
private boolean isClosed = false;
2829

@@ -128,7 +129,6 @@ public ReleasableIterator<? extends Block> lookup(IntBlock positions, ByteSizeVa
128129

129130
@Override
130131
public MvOrdering mvOrdering() {
131-
// TODO: is this correct? histograms don't have a natural ordering but might be ordered by e.g. their maximum value?
132132
return MvOrdering.UNORDERED;
133133
}
134134

@@ -169,9 +169,32 @@ void copyInto(BytesRefBlock.Builder encodedHistogramsBuilder, int beginInclusive
169169
encodedHistogramsBuilder.copyFrom(this.encodedHistograms, beginInclusive, endExclusive);
170170
}
171171

172+
@Override
173+
public boolean equals(Object o) {
174+
if (o instanceof ExponentialHistogramBlock block) {
175+
return ExponentialHistogramBlock.equals(this, block);
176+
}
177+
return false;
178+
}
179+
180+
boolean equalsAfterTypeCheck(ExponentialHistogramArrayBlock that) {
181+
return this.encodedHistograms.equals(that.encodedHistograms);
182+
}
183+
184+
@Override
185+
public int hashCode() {
186+
if (encodedHistograms.areAllValuesNull()) {
187+
// ensure consistent hash code for all-null blocks
188+
try (Block nullBlock = blockFactory().newConstantNullBlock(getPositionCount())) {
189+
return nullBlock.hashCode();
190+
}
191+
}
192+
return encodedHistograms.hashCode();
193+
}
194+
172195
private class BlockBackedHistogram extends AbstractExponentialHistogram implements ExponentialHistogram {
173196

174-
// TODO: encode all of the ExponentialHistogram data except for min/max/sum/count
197+
// TODO(b/133393): encode all of the ExponentialHistogram data except for min/max/sum/count
175198
private static final int SCALE_OFFSET = 0;
176199

177200
private final ByteBuffer data;
@@ -199,6 +222,7 @@ private static void resizeIfRequired(BytesRef growableBuffer, int totalSize) {
199222
if (growableBuffer.length >= totalSize) {
200223
return;
201224
}
225+
growableBuffer.length = Math.max(32, growableBuffer.length);
202226
while (growableBuffer.length < totalSize) {
203227
growableBuffer.length *= 2;
204228
}
@@ -220,43 +244,43 @@ private void checkForUseAfterClose() {
220244

221245
@Override
222246
public ZeroBucket zeroBucket() {
223-
// TODO: implement
247+
// TODO(b/133393): implement
224248
return ZeroBucket.minimalEmpty();
225249
}
226250

227251
@Override
228252
public ExponentialHistogram.Buckets positiveBuckets() {
229-
// TODO: implement
230-
return ExponentialHistogram.empty().positiveBuckets();
253+
// TODO(b/133393): implement
254+
return ExponentialHistogram.builder(scale(), ExponentialHistogramCircuitBreaker.noop()).build().positiveBuckets();
231255
}
232256

233257
@Override
234258
public ExponentialHistogram.Buckets negativeBuckets() {
235-
// TODO: implement
236-
return ExponentialHistogram.empty().negativeBuckets();
259+
// TODO(b/133393): implement
260+
return ExponentialHistogram.builder(scale(), ExponentialHistogramCircuitBreaker.noop()).build().negativeBuckets();
237261
}
238262

239263
@Override
240264
public double sum() {
241-
// TODO: implement
265+
// TODO(b/133393): implement
242266
return 0;
243267
}
244268

245269
@Override
246270
public long valueCount() {
247-
// TODO: implement
271+
// TODO(b/133393): implement
248272
return 0;
249273
}
250274

251275
@Override
252276
public double min() {
253-
// TODO: implement
277+
// TODO(b/133393): implement
254278
return Double.NaN;
255279
}
256280

257281
@Override
258282
public double max() {
259-
// TODO: implement
283+
// TODO(b/133393): implement
260284
return Double.NaN;
261285
}
262286

@@ -266,27 +290,4 @@ public long ramBytesUsed() {
266290
}
267291

268292
}
269-
270-
@Override
271-
public boolean equals(Object o) {
272-
if (o instanceof ExponentialHistogramBlock block) {
273-
return ExponentialHistogramBlock.equals(this, block);
274-
}
275-
return false;
276-
}
277-
278-
boolean equalsAfterTypeCheck(ExponentialHistogramArrayBlock that) {
279-
return this.encodedHistograms.equals(that.encodedHistograms);
280-
}
281-
282-
@Override
283-
public int hashCode() {
284-
if (encodedHistograms.areAllValuesNull()) {
285-
// ensure consistent hash code for all-null blocks
286-
try (Block nullBlock = blockFactory().newConstantNullBlock(getPositionCount())) {
287-
return nullBlock.hashCode();
288-
}
289-
}
290-
return encodedHistograms.hashCode();
291-
}
292293
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ExponentialHistogramBlock.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ public sealed interface ExponentialHistogramBlock extends Block permits Constant
1313

1414
ExponentialHistogram getExponentialHistogram(int valueIndex);
1515

16-
/**
17-
* Compares the given object with this block for equality. Returns {@code true} if and only if the
18-
* given object is a BytesRefBlock, and both blocks are {@link #equals(ExponentialHistogramBlock, ExponentialHistogramBlock) equal}.
19-
*/
20-
@Override
21-
boolean equals(Object obj);
22-
23-
@Override
24-
int hashCode();
25-
2616
static boolean equals(ExponentialHistogramBlock blockA, ExponentialHistogramBlock blockB) {
2717
if (blockA == blockB) {
2818
return true;

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ExponentialHistogramBlockBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public ExponentialHistogramBlockBuilder copyFrom(Block block, int beginInclusive
7272

7373
@Override
7474
public ExponentialHistogramBlockBuilder mvOrdering(Block.MvOrdering mvOrdering) {
75-
// TODO: does this need implementation?
7675
return this;
7776
}
7877

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BlockMultiValuedTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static List<Object[]> params() {
4949
|| e == ElementType.NULL
5050
|| e == ElementType.DOC
5151
|| e == ElementType.COMPOSITE
52-
|| e == ElementType.EXPONENTIAL_HISTOGRAM // TODO: implement
52+
|| e == ElementType.EXPONENTIAL_HISTOGRAM //TODO(b/133393): Enable tests once the block supports lookup
5353
|| e == ElementType.AGGREGATE_METRIC_DOUBLE) {
5454
continue;
5555
}

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/CompositeBlockTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ public class CompositeBlockTests extends ComputeTestCase {
2121

2222
static List<ElementType> supportedSubElementTypes = Arrays.stream(ElementType.values())
2323
.filter(
24-
e -> e != ElementType.COMPOSITE
25-
&& e != ElementType.UNKNOWN
26-
&& e != ElementType.DOC
27-
&& e != ElementType.AGGREGATE_METRIC_DOUBLE
28-
&& e != ElementType.EXPONENTIAL_HISTOGRAM
24+
e -> e != ElementType.COMPOSITE && e != ElementType.UNKNOWN && e != ElementType.DOC && e != ElementType.AGGREGATE_METRIC_DOUBLE
2925
)
3026
.toList();
3127

x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/BlockTestUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.compute.data.Page;
2929
import org.elasticsearch.core.Releasables;
3030
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;
31+
import org.elasticsearch.exponentialhistogram.ExponentialHistogramCircuitBreaker;
3132
import org.hamcrest.Matcher;
3233

3334
import java.util.ArrayList;
@@ -371,8 +372,9 @@ public static Page convertBytesRefsToOrdinals(Page page) {
371372
}
372373

373374
static ExponentialHistogram randomExponentialHistogram() {
374-
// TODO: implement with actualy randomization and non-empty histograms
375-
return ExponentialHistogram.empty();
375+
// TODO(b/133393): populate the random histogram fully when supported by the block
376+
int scale = randomIntBetween(ExponentialHistogram.MIN_SCALE, ExponentialHistogram.MAX_SCALE);
377+
return ExponentialHistogram.builder(scale, ExponentialHistogramCircuitBreaker.noop()).build();
376378
}
377379

378380
private static int dedupe(Map<BytesRef, Integer> dedupe, BytesRefVector.Builder bytes, BytesRef v) {

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ public void testSuggestedCast() throws IOException {
669669
shouldBeSupported.remove(DataType.DOC_DATA_TYPE);
670670
shouldBeSupported.remove(DataType.TSID_DATA_TYPE);
671671
shouldBeSupported.remove(DataType.DENSE_VECTOR);
672-
shouldBeSupported.remove(DataType.EXPONENTIAL_HISTOGRAM); // TODO: add support when blockloader is implemented
672+
shouldBeSupported.remove(DataType.EXPONENTIAL_HISTOGRAM); //TODO(b/133393): add support when blockloader is implemented
673673
if (EsqlCorePlugin.AGGREGATE_METRIC_DOUBLE_FEATURE_FLAG.isEnabled() == false) {
674674
shouldBeSupported.remove(DataType.AGGREGATE_METRIC_DOUBLE);
675675
}

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.elasticsearch.core.SuppressForbidden;
3939
import org.elasticsearch.core.Tuple;
4040
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;
41+
import org.elasticsearch.exponentialhistogram.ExponentialHistogramCircuitBreaker;
4142
import org.elasticsearch.geo.GeometryTestUtils;
4243
import org.elasticsearch.geo.ShapeTestUtils;
4344
import org.elasticsearch.geometry.utils.Geohash;
@@ -887,17 +888,17 @@ public static Literal randomLiteral(DataType type) {
887888
}
888889
}
889890
case DENSE_VECTOR -> Arrays.asList(randomArray(10, 10, i -> new Float[10], ESTestCase::randomFloat));
890-
case EXPONENTIAL_HISTOGRAM -> new WriteableExponentialHistogram(randomExponentialHistogram());
891-
// TODO: implement
891+
case EXPONENTIAL_HISTOGRAM -> new WriteableExponentialHistogram(EsqlTestUtils.randomExponentialHistogram());
892892
case UNSUPPORTED, OBJECT, DOC_DATA_TYPE, TSID_DATA_TYPE, PARTIAL_AGG -> throw new IllegalArgumentException(
893893
"can't make random values for [" + type.typeName() + "]"
894894
);
895895
}, type);
896896
}
897897

898898
private static ExponentialHistogram randomExponentialHistogram() {
899-
// TODO: implement properly with an actual histogram from random data
900-
return ExponentialHistogram.empty();
899+
// TODO(b/133393): populate the random histogram fully when supported by the block
900+
int scale = randomIntBetween(ExponentialHistogram.MIN_SCALE, ExponentialHistogram.MAX_SCALE);
901+
return ExponentialHistogram.builder(scale, ExponentialHistogramCircuitBreaker.noop()).build();
901902
}
902903

903904
static Version randomVersion() {

0 commit comments

Comments
 (0)