Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8a0a14f
Implemented basic ES|QL exponential histogram type
JonasKunz Sep 5, 2025
b19aed7
Update x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearc…
JonasKunz Sep 5, 2025
af6efdb
Review fixes
JonasKunz Sep 5, 2025
e625bb4
Create deserialization utility in exp histo lib
JonasKunz Sep 5, 2025
f2e4113
Remove JsonBackedExponentialHistogram.java
JonasKunz Sep 5, 2025
6d05f43
Merge remote-tracking branch 'elastic/main' into exp-histo-esql
JonasKunz Sep 22, 2025
5dabd2e
Remove unnecessarry special case in hashcode
JonasKunz Sep 22, 2025
114cc58
[CI] Auto commit changes from spotless
Sep 22, 2025
723c5aa
Set of review fixes
JonasKunz Sep 22, 2025
4972c7b
Merge remote-tracking branch 'origin/exp-histo-esql' into exp-histo-esql
JonasKunz Sep 22, 2025
283da4d
Add equality test with random blocks.
JonasKunz Sep 23, 2025
51a5a84
[CI] Update transport version definitions
Sep 23, 2025
5a13b25
Add ToDo for NamedWriteable registration
JonasKunz Sep 23, 2025
76bf585
Merge branch 'main' into exp-histo-esql
JonasKunz Sep 23, 2025
6b84972
Merge branch 'main' into exp-histo-esql
JonasKunz Sep 23, 2025
0d8f467
Merge remote-tracking branch 'elastic/main' into exp-histo-esql
JonasKunz Oct 1, 2025
d5476c7
[CI] Auto commit changes from spotless
Oct 1, 2025
0c70b4f
Exclude from AllSupportedFieldsTestCase
JonasKunz Oct 1, 2025
5fc3538
Merge branch 'main' into exp-histo-esql
JonasKunz Oct 1, 2025
3a003ed
Fix rebase induced test failure
JonasKunz Oct 2, 2025
19a72a5
Merge remote-tracking branch 'elastic/main' into exp-histo-esql
JonasKunz Oct 17, 2025
08488a7
Fix merge conflicts
JonasKunz Oct 17, 2025
379dc91
Add accessor to minimize allocations
JonasKunz Oct 20, 2025
90e5862
Make block builder not accept null values
JonasKunz Oct 20, 2025
ad7c10b
Remove double closed check
JonasKunz Oct 20, 2025
4a10962
Revert "Remove csv tests as blockloader is not included in this PR"
JonasKunz Sep 5, 2025
4cf6417
Implemented BlockLoader
JonasKunz Sep 5, 2025
fa9082e
Fix EsqlSpecIT
JonasKunz Sep 23, 2025
14cf740
Add ignoredOrder, spotless
JonasKunz Sep 24, 2025
daa7934
Refactor: Move exponential histogram compression into shared library
JonasKunz Oct 22, 2025
858fd60
[CI] Auto commit changes from spotless
Oct 22, 2025
77762a5
Revert accidentally added character
JonasKunz Oct 22, 2025
e0a2888
Switch to block directly using doc values in disk format
JonasKunz Oct 22, 2025
275c05a
Implement block and block loader using disk layout
JonasKunz Oct 22, 2025
9af71b4
Extract multi value handling from ArrayBlock into base class
JonasKunz Oct 23, 2025
72c4732
Revert "Extract multi value handling from ArrayBlock into base class"
JonasKunz Oct 23, 2025
f69c492
Remove multi-value support
JonasKunz Oct 23, 2025
bedea36
Fix tests
JonasKunz Oct 23, 2025
d586acc
Merge remote-tracking branch 'elastic/main' into exp-histo-esql-v2
JonasKunz Oct 23, 2025
621b472
Revert BlockLoader related changes
JonasKunz Oct 23, 2025
537114f
Fix opentelemety default histogram size to actual values
JonasKunz Oct 23, 2025
d3c3bdf
Properly implement constant block, make invariants correctly handle n…
JonasKunz Oct 23, 2025
c3aa8fa
Avoid COnstantBytesRefBlock as it does not support serialization yet
JonasKunz Oct 23, 2025
f1b6b50
[CI] Auto commit changes from spotless
Oct 23, 2025
3578b0f
Move accessor outside of block, revert constant block implementation
JonasKunz Oct 23, 2025
4005297
[CI] Auto commit changes from spotless
Oct 23, 2025
9e955ff
Merge branch 'main' into exp-histo-esql
JonasKunz Oct 24, 2025
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
26 changes: 26 additions & 0 deletions libs/exponential-histogram/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

module org.elasticsearch.exponentialhistogram {
requires org.elasticsearch.xcontent;
requires org.apache.lucene.core;
requires org.elasticsearch.base;

exports org.elasticsearch.exponentialhistogram;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class EsqlCorePlugin extends Plugin implements ExtensiblePlugin {

public static final FeatureFlag AGGREGATE_METRIC_DOUBLE_FEATURE_FLAG = new FeatureFlag("esql_aggregate_metric_double");
public static final FeatureFlag DENSE_VECTOR_FEATURE_FLAG = new FeatureFlag("esql_dense_vector");
public static final FeatureFlag EXPONENTIAL_HISTOGRAM_FEATURE_FLAG = new FeatureFlag("esql_exponential_histogram");
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ public enum DataType {

AGGREGATE_METRIC_DOUBLE(builder().esType("aggregate_metric_double").estimatedSize(Double.BYTES * 3 + Integer.BYTES)),

EXPONENTIAL_HISTOGRAM(builder().esType("exponential_histogram").unknownSize().docValues()),

/**
* Fields with this type are dense vectors, represented as an array of double values.
*/
Expand All @@ -320,7 +322,8 @@ public enum DataType {
*/
public static final Map<DataType, FeatureFlag> UNDER_CONSTRUCTION = Map.ofEntries(
Map.entry(AGGREGATE_METRIC_DOUBLE, EsqlCorePlugin.AGGREGATE_METRIC_DOUBLE_FEATURE_FLAG),
Map.entry(DENSE_VECTOR, EsqlCorePlugin.DENSE_VECTOR_FEATURE_FLAG)
Map.entry(DENSE_VECTOR, EsqlCorePlugin.DENSE_VECTOR_FEATURE_FLAG),
Map.entry(EXPONENTIAL_HISTOGRAM, EsqlCorePlugin.EXPONENTIAL_HISTOGRAM_FEATURE_FLAG)
);

private final String typeName;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugin/esql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
implementation project('compute:ann')
implementation project(':libs:dissect')
implementation project(':libs:grok')
implementation project(':libs:exponential-histogram')
api "org.apache.lucene:lucene-spatial3d:${versions.lucene}"
api project(":libs:h3")
implementation project('arrow')
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugin/esql/compute/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
compileOnly project(xpackModule('ml'))
annotationProcessor project('gen')
implementation 'com.carrotsearch:hppc:0.8.1'
api project(':libs:exponential-histogram')

testImplementation(project(':modules:analysis-common'))
testImplementation(project(':test:framework'))
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugin/esql/compute/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
requires org.elasticsearch.geo;
requires org.elasticsearch.xcore;
requires hppc;
requires org.elasticsearch.exponentialhistogram;

exports org.elasticsearch.compute;
exports org.elasticsearch.compute.aggregation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.BytesRefArray;
import org.elasticsearch.compute.data.Block.MvOrdering;
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;

import java.util.BitSet;

Expand Down Expand Up @@ -467,6 +468,19 @@ public final AggregateMetricDoubleBlock newConstantAggregateMetricDoubleBlock(
}
}

public ExponentialHistogramBlockBuilder newExponentialHistogramBlockBuilder(int estimatedSize) {
return new ExponentialHistogramBlockBuilder(estimatedSize, this);
}

public final ExponentialHistogramBlock newConstantExponentialHistogramBlock(ExponentialHistogram value, int positionCount) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add the constant later - not sure if we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for testing. While we don't allow the construction of exponential_histogram literals via a query (at least for now), tests do construct literals. And to turn those literals into blocks, constant blocks are used.

So if we remove the constant block, we get a lot of test failures like this one:

REPRODUCE WITH: ./gradlew ":x-pack:plugin:esql:test" --tests "org.elasticsearch.xpack.esql.expression.function.scalar.nulls.IsNullTests.testEvaluate {TestCase=non-null exponential_histogram}" -Dtests.seed=E0138310B809341F -Dtests.locale=hi-Deva-IN -Dtests.timezone=Etc/GMT+2 -Druntime.java=25

unsupported element type [EXPONENTIAL_HISTOGRAM]
java.lang.UnsupportedOperationException: unsupported element type [EXPONENTIAL_HISTOGRAM]
	at __randomizedtesting.SeedInfo.seed([E0138310B809341F:CABEDCCC64462444]:0)
	at org.elasticsearch.compute.data.BlockUtils.constantBlock(BlockUtils.java:259)
	at org.elasticsearch.compute.data.BlockUtils.constantBlock(BlockUtils.java:245)
	at org.elasticsearch.compute.data.BlockUtils.fromListRow(BlockUtils.java:107)
	at org.elasticsearch.compute.data.BlockUtils.fromListRow(BlockUtils.java:77)
	at org.elasticsearch.xpack.esql.expression.function.AbstractFunctionTestCase.row(AbstractFunctionTestCase.java:577)
	at org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase.testEvaluate(AbstractScalarFunctionTestCase.java:117)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)

And I don't think we'd want to exclude exponential histogram blocks from IsNullTests for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to "properly" implement the constant block. What I did was create constant-blocks for the sub-blocks (e.g. constant block for min, constant block for zero_threshold, etc).
Unfortunately it seems like something is wrong with the serialization of those blocks, as then several tests fail when trying to deserialize the block.

For that reason I reverted to the current, non-optimal solution, as it is only used in tests anyway AFAIK

try (ExponentialHistogramBlockBuilder builder = newExponentialHistogramBlockBuilder(positionCount)) {
for (int i = 0; i < positionCount; i++) {
builder.append(value);
}
return builder.build();
}
}

public final AggregateMetricDoubleBlock newAggregateMetricDoubleBlock(
double[] minValues,
double[] maxValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.elasticsearch.compute.data.AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;
import org.elasticsearch.exponentialhistogram.ExponentialHistogramCircuitBreaker;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -217,6 +219,7 @@ public static void appendValue(Block.Builder builder, Object val, ElementType ty
case FLOAT -> ((FloatBlock.Builder) builder).appendFloat((Float) val);
case DOUBLE -> ((DoubleBlock.Builder) builder).appendDouble((Double) val);
case BOOLEAN -> ((BooleanBlock.Builder) builder).appendBoolean((Boolean) val);
case EXPONENTIAL_HISTOGRAM -> ((ExponentialHistogramBlockBuilder) builder).append((ExponentialHistogram) val);
default -> throw new UnsupportedOperationException("unsupported element type [" + type + "]");
}
}
Expand Down Expand Up @@ -246,6 +249,7 @@ private static Block constantBlock(BlockFactory blockFactory, ElementType type,
case BOOLEAN -> blockFactory.newConstantBooleanBlockWith((boolean) val, size);
case AGGREGATE_METRIC_DOUBLE -> blockFactory.newConstantAggregateMetricDoubleBlock((AggregateMetricDoubleLiteral) val, size);
case FLOAT -> blockFactory.newConstantFloatBlockWith((float) val, size);
case EXPONENTIAL_HISTOGRAM -> blockFactory.newConstantExponentialHistogramBlock((ExponentialHistogram) val, size);
default -> throw new UnsupportedOperationException("unsupported element type [" + type + "]");
};
}
Expand Down Expand Up @@ -299,6 +303,11 @@ yield new AggregateMetricDoubleLiteral(
aggBlock.countBlock().getInt(offset)
);
}
case EXPONENTIAL_HISTOGRAM -> {
ExponentialHistogram histogram = ((ExponentialHistogramArrayBlock) block).getExponentialHistogram(offset);
// return a copy so that the returned value is not bound to the lifetime of the block
yield ExponentialHistogram.builder(histogram, ExponentialHistogramCircuitBreaker.noop()).build();
}
case UNKNOWN -> throw new IllegalArgumentException("can't read values from [" + block + "]");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.core.ReleasableIterator;
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;

import java.io.IOException;

Expand All @@ -26,7 +27,8 @@ public final class ConstantNullBlock extends AbstractNonThreadSafeRefCounted
FloatBlock,
DoubleBlock,
BytesRefBlock,
AggregateMetricDoubleBlock {
AggregateMetricDoubleBlock,
ExponentialHistogramBlock {

private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(ConstantNullBlock.class);
private final int positionCount;
Expand Down Expand Up @@ -292,6 +294,12 @@ public long getLong(int valueIndex) {
throw new UnsupportedOperationException("null block");
}

@Override
public ExponentialHistogram getExponentialHistogram(int valueIndex) {
assert false : "null block";
throw new UnsupportedOperationException("null block");
}

@Override
public int getTotalValueCount() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.exponentialhistogram.ExponentialHistogram;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -64,6 +65,16 @@ public enum ElementType {
"AggregateMetricDouble",
BlockFactory::newAggregateMetricDoubleBlockBuilder,
AggregateMetricDoubleArrayBlock::readFrom
),

/**
* Blocks that contain exponential_histograms.
*/
EXPONENTIAL_HISTOGRAM(
11,
"ExponentialHistogram",
BlockFactory::newExponentialHistogramBlockBuilder,
ExponentialHistogramArrayBlock::readFrom
);

private interface BuilderSupplier {
Expand Down Expand Up @@ -111,6 +122,8 @@ public static ElementType fromJava(Class<?> type) {
elementType = BOOLEAN;
} else if (type == AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral.class) {
elementType = AGGREGATE_METRIC_DOUBLE;
} else if (type != null && ExponentialHistogram.class.isAssignableFrom(type)) {
elementType = EXPONENTIAL_HISTOGRAM;
} else if (type == null || type == Void.class) {
elementType = NULL;
} else {
Expand Down
Loading