Skip to content

Commit

Permalink
HSEARCH-5133 Introduce metric aggregation values
Browse files Browse the repository at this point in the history
To test metric aggregations on different types
  • Loading branch information
fax4ever committed Aug 26, 2024
1 parent 682bf4f commit e28a110
Show file tree
Hide file tree
Showing 28 changed files with 354 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,9 @@ public boolean rangeAggregationsDoNotIgnoreQuery() {
aoss -> false
);
}

@Override
public boolean negativeDecimalScaleIsAppliedToAvgAggregationFunction() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class AnalyzedStringFieldTypeDescriptor extends StandardFieldTypeDescriptor<String> {

Expand Down Expand Up @@ -62,6 +63,11 @@ protected List<List<String>> createMultiResultingInSingleAfterMedian() {
};
}

@Override
public MetricAggregationsValues<String> metricAggregationsValues() {
return null;
}

@Override
protected IndexableValues<String> createIndexableValues() {
return new IndexableValues<String>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration;

public class BigDecimalFieldTypeDescriptor extends StandardFieldTypeDescriptor<BigDecimal> {
Expand Down Expand Up @@ -66,6 +67,21 @@ protected BigDecimal applyDelta(BigDecimal value, int multiplierForDelta) {
};
}

@Override
public MetricAggregationsValues<BigDecimal> metricAggregationsValues() {
return new MetricAggregationsValues<BigDecimal>() {
@Override
protected BigDecimal valueOf(int value) {
return BigDecimal.valueOf( value ).setScale( 2, RoundingMode.FLOOR );
}

@Override
public BigDecimal avg() {
return BigDecimal.valueOf( 5.5 ).setScale( 2, RoundingMode.FLOOR );
}
};
}

@Override
protected IndexableValues<BigDecimal> createIndexableValues() {
return new IndexableValues<BigDecimal>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration;

public class BigIntegerFieldTypeDescriptor extends StandardFieldTypeDescriptor<BigInteger> {

Expand Down Expand Up @@ -60,6 +62,24 @@ protected BigInteger applyDelta(BigInteger value, int multiplierForDelta) {
};
}

@Override
public MetricAggregationsValues<BigInteger> metricAggregationsValues() {
return new MetricAggregationsValues<BigInteger>() {
@Override
protected BigInteger valueOf(int value) {
return BigInteger.valueOf( value * 100L );
}

@Override
public BigInteger avg() {
if ( TckConfiguration.get().getBackendFeatures().negativeDecimalScaleIsAppliedToAvgAggregationFunction() ) {
return super.avg(); // BigInteger.valueOf( 500L )
}
return BigInteger.valueOf( 550L );
}
};
}

@Override
protected IndexableValues<BigInteger> createIndexableValues() {
return new IndexableValues<BigInteger>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class BooleanFieldTypeDescriptor extends StandardFieldTypeDescriptor<Boolean> {

Expand Down Expand Up @@ -46,6 +47,11 @@ protected List<List<Boolean>> createMultiResultingInSingleAfterMedian() {
};
}

@Override
public MetricAggregationsValues<Boolean> metricAggregationsValues() {
return null;
}

@Override
protected IndexableValues<Boolean> createIndexableValues() {
return new IndexableValues<Boolean>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.List;
import java.util.Optional;

import org.hibernate.search.engine.cfg.spi.ConvertUtils;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class ByteFieldTypeDescriptor extends StandardFieldTypeDescriptor<Byte> {

Expand Down Expand Up @@ -56,6 +58,16 @@ private byte toByteExact(int value) {
};
}

@Override
public MetricAggregationsValues<Byte> metricAggregationsValues() {
return new MetricAggregationsValues<Byte>() {
@Override
protected Byte valueOf(int value) {
return ConvertUtils.convertByte( value );
}
};
}

@Override
protected IndexableValues<Byte> createIndexableValues() {
return new IndexableValues<Byte>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.List;
import java.util.Optional;

import org.hibernate.search.engine.cfg.spi.ConvertUtils;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class DoubleFieldTypeDescriptor extends StandardFieldTypeDescriptor<Double> {

Expand Down Expand Up @@ -49,6 +51,21 @@ protected Double applyDelta(Double value, int multiplierForDelta) {
};
}

@Override
public MetricAggregationsValues<Double> metricAggregationsValues() {
return new MetricAggregationsValues<Double>() {
@Override
protected Double valueOf(int value) {
return ConvertUtils.convertDouble( value );
}

@Override
public Double avg() {
return 5.5;
}
};
}

@Override
protected IndexableValues<Double> createIndexableValues() {
return new IndexableValues<Double>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration;

public abstract class FieldTypeDescriptor<F, S extends SearchableProjectableIndexFieldTypeOptionsStep<?, F>> {
Expand Down Expand Up @@ -181,6 +182,8 @@ public final AscendingUniqueTermValues<F> getAscendingUniqueTermValues() {

protected abstract AscendingUniqueTermValues<F> createAscendingUniqueTermValues();

public abstract MetricAggregationsValues<F> metricAggregationsValues();

/**
* @return A set of indexables values, not necessarily unique.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.List;
import java.util.Optional;

import org.hibernate.search.engine.cfg.spi.ConvertUtils;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class FloatFieldTypeDescriptor extends StandardFieldTypeDescriptor<Float> {

Expand Down Expand Up @@ -49,6 +51,21 @@ protected Float applyDelta(Float value, int multiplierForDelta) {
};
}

@Override
public MetricAggregationsValues<Float> metricAggregationsValues() {
return new MetricAggregationsValues<Float>() {
@Override
protected Float valueOf(int value) {
return ConvertUtils.convertFloat( value );
}

@Override
public Float avg() {
return 5.5F;
}
};
}

@Override
protected IndexableValues<Float> createIndexableValues() {
return new IndexableValues<Float>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class GeoPointFieldTypeDescriptor extends StandardFieldTypeDescriptor<GeoPoint> {

Expand All @@ -26,6 +27,11 @@ protected AscendingUniqueTermValues<GeoPoint> createAscendingUniqueTermValues()
return null; // Value lookup is not supported
}

@Override
public MetricAggregationsValues<GeoPoint> metricAggregationsValues() {
return null;
}

@Override
protected IndexableValues<GeoPoint> createIndexableValues() {
return new IndexableValues<GeoPoint>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class InstantFieldTypeDescriptor extends StandardFieldTypeDescriptor<Instant> {

Expand Down Expand Up @@ -57,6 +58,21 @@ protected Instant applyDelta(Instant value, int multiplierForDelta) {
};
}

@Override
public MetricAggregationsValues<Instant> metricAggregationsValues() {
return new MetricAggregationsValues<Instant>() {
@Override
protected Instant valueOf(int value) {
return Instant.ofEpochSecond( value * 100_000L );
}

@Override
public Instant avg() {
return Instant.parse( "1970-01-07T08:46:40Z" );
}
};
}

@Override
protected IndexableValues<Instant> createIndexableValues() {
return new IndexableValues<Instant>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class IntegerFieldTypeDescriptor extends StandardFieldTypeDescriptor<Integer> {

Expand Down Expand Up @@ -49,6 +50,16 @@ protected Integer applyDelta(Integer value, int multiplierForDelta) {
};
}

@Override
public MetricAggregationsValues<Integer> metricAggregationsValues() {
return new MetricAggregationsValues<Integer>() {
@Override
protected Integer valueOf(int value) {
return value;
}
};
}

@Override
protected IndexableValues<Integer> createIndexableValues() {
return new IndexableValues<Integer>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class KeywordStringFieldTypeDescriptor extends StandardFieldTypeDescriptor<String> {

Expand Down Expand Up @@ -54,6 +55,11 @@ protected List<List<String>> createMultiResultingInSingleAfterMedian() {
};
}

@Override
public MetricAggregationsValues<String> metricAggregationsValues() {
return null;
}

@Override
protected IndexableValues<String> createIndexableValues() {
return new IndexableValues<String>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class LocalDateFieldTypeDescriptor extends StandardFieldTypeDescriptor<LocalDate> {

Expand Down Expand Up @@ -51,6 +52,16 @@ protected LocalDate applyDelta(LocalDate value, int multiplierForDelta) {
};
}

@Override
public MetricAggregationsValues<LocalDate> metricAggregationsValues() {
return new MetricAggregationsValues<LocalDate>() {
@Override
protected LocalDate valueOf(int value) {
return LocalDate.ofEpochDay( value );
}
};
}

@Override
protected IndexableValues<LocalDate> createIndexableValues() {
return new IndexableValues<LocalDate>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.hibernate.search.integrationtest.backend.tck.testsupport.types;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;
Expand All @@ -14,6 +15,7 @@
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.AscendingUniqueTermValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.IndexableValues;
import org.hibernate.search.integrationtest.backend.tck.testsupport.types.values.MetricAggregationsValues;

public class LocalDateTimeFieldTypeDescriptor extends StandardFieldTypeDescriptor<LocalDateTime> {

Expand Down Expand Up @@ -53,6 +55,21 @@ protected LocalDateTime applyDelta(LocalDateTime value, int multiplierForDelta)
};
}

@Override
public MetricAggregationsValues<LocalDateTime> metricAggregationsValues() {
return new MetricAggregationsValues<LocalDateTime>() {
@Override
protected LocalDateTime valueOf(int value) {
return LocalDateTime.ofEpochSecond( value, 0, ZoneOffset.UTC );
}

@Override
public LocalDateTime avg() {
return LocalDateTime.of( 1970, 1, 1, 0, 0, 5, 500_000_000 );
}
};
}

@Override
protected IndexableValues<LocalDateTime> createIndexableValues() {
return new IndexableValues<LocalDateTime>() {
Expand Down
Loading

0 comments on commit e28a110

Please sign in to comment.