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 1, 2024
1 parent 197e230 commit cc7c324
Show file tree
Hide file tree
Showing 26 changed files with 281 additions and 2 deletions.
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,16 @@ 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
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,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 BigIntegerFieldTypeDescriptor extends StandardFieldTypeDescriptor<BigInteger> {

Expand Down Expand Up @@ -60,6 +61,16 @@ 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
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,16 @@ 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
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,16 @@ 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
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,16 @@ 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
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,16 @@ 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
protected IndexableValues<LocalDateTime> createIndexableValues() {
return new IndexableValues<LocalDateTime>() {
Expand Down
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 LocalTimeFieldTypeDescriptor extends StandardFieldTypeDescriptor<LocalTime> {

Expand Down Expand Up @@ -53,6 +54,11 @@ protected LocalTime applyDelta(LocalTime value, int multiplierForDelta) {
};
}

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

@Override
protected IndexableValues<LocalTime> createIndexableValues() {
return new IndexableValues<LocalTime>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,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;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration;

public class LongFieldTypeDescriptor extends StandardFieldTypeDescriptor<Long> {
Expand Down Expand Up @@ -61,6 +63,16 @@ protected Long applyDelta(Long value, int multiplierForDelta) {
};
}

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

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

0 comments on commit cc7c324

Please sign in to comment.