Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Jun 12, 2024
1 parent 78b4d9d commit 185ed4e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public ScaledFloatFieldMapper build(BuilderContext context) {

public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n, c.getSettings()));

public static final class ScaledFloatFieldType extends SimpleMappedFieldType implements PointFieldType {
public static final class ScaledFloatFieldType extends SimpleMappedFieldType implements NumericPointEncoder {

private final double scalingFactor;
private final Double nullValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public DateFieldMapper build(BuilderContext context) {
*
* @opensearch.internal
*/
public static final class DateFieldType extends MappedFieldType implements PointFieldType {
public static final class DateFieldType extends MappedFieldType implements NumericPointEncoder {
protected final DateFormatter dateTimeFormatter;
protected final DateMathParser dateMathParser;
protected final Resolution resolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public NumberFieldMapper build(BuilderContext context) {
*
* @opensearch.internal
*/
public enum NumberType {
public enum NumberType implements NumericPointEncoder {
HALF_FLOAT("half_float", NumericType.HALF_FLOAT) {
@Override
public Float parse(Object value, boolean coerce) {
Expand Down Expand Up @@ -1191,8 +1191,6 @@ public abstract Query rangeQuery(

public abstract Number parsePoint(byte[] value);

public abstract byte[] encodePoint(Number value);

public abstract List<Field> createFields(String name, Number value, boolean indexed, boolean docValued, boolean stored);

abstract Number valueForSearch(String value);
Expand Down Expand Up @@ -1421,7 +1419,7 @@ public static Query unsignedLongRangeQuery(
*
* @opensearch.internal
*/
public static class NumberFieldType extends SimpleMappedFieldType implements PointFieldType {
public static class NumberFieldType extends SimpleMappedFieldType implements NumericPointEncoder {

private final NumberType type;
private final boolean coerce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
/**
* Interface for encoding a point value
*/
public interface PointFieldType {
public interface NumericPointEncoder {
byte[] encodePoint(Number value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.opensearch.index.mapper.DateFieldMapper;
import org.opensearch.index.mapper.DocCountFieldMapper;
import org.opensearch.index.mapper.MappedFieldType;
import org.opensearch.index.mapper.PointFieldType;
import org.opensearch.index.mapper.NumericPointEncoder;
import org.opensearch.index.query.DateRangeIncludingNowQuery;
import org.opensearch.search.aggregations.bucket.composite.CompositeAggregator;
import org.opensearch.search.aggregations.bucket.composite.CompositeValuesSourceConfig;
Expand Down Expand Up @@ -479,7 +479,7 @@ public RangeAggregationType(ValuesSourceConfig config, Range[] ranges) {
public boolean isRewriteable(Object parent, int subAggLength) {
if (config.fieldType() == null) return false;
MappedFieldType fieldType = config.fieldType();
if (fieldType.isSearchable() == false || !(fieldType instanceof PointFieldType)) return false;
if (fieldType.isSearchable() == false || !(fieldType instanceof NumericPointEncoder)) return false;

if (parent == null && subAggLength == 0 && config.script() == null && config.missing() == null) {
if (config.getValuesSource() instanceof ValuesSource.Numeric.FieldData) {
Expand All @@ -500,15 +500,15 @@ public boolean isRewriteable(Object parent, int subAggLength) {

@Override
public Ranges buildRanges(SearchContext context, MappedFieldType fieldType) {
assert fieldType instanceof PointFieldType;
PointFieldType pointFieldType = (PointFieldType) fieldType;
assert fieldType instanceof NumericPointEncoder;
NumericPointEncoder numericPointEncoder = (NumericPointEncoder) fieldType;
byte[][] lowers = new byte[ranges.length][];
byte[][] uppers = new byte[ranges.length][];
for (int i = 0; i < ranges.length; i++) {
double rangeMin = ranges[i].getFrom();
double rangeMax = ranges[i].getTo();
byte[] lower = pointFieldType.encodePoint(rangeMin);
byte[] upper = pointFieldType.encodePoint(rangeMax);
byte[] lower = numericPointEncoder.encodePoint(rangeMin);
byte[] upper = numericPointEncoder.encodePoint(rangeMax);
lowers[i] = lower;
uppers[i] = upper;
}
Expand Down

0 comments on commit 185ed4e

Please sign in to comment.