Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
support all numeric types
minus one on the upper range

Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed May 29, 2024
1 parent c7043e4 commit 90d6790
Showing 1 changed file with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.sandbox.document.BigIntegerPoint;
import org.apache.lucene.sandbox.document.HalfFloatPoint;
import org.apache.lucene.search.CollectionTerminatedException;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.DocIdSetIterator;
Expand Down Expand Up @@ -45,6 +49,8 @@

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -535,11 +541,17 @@ public Ranges buildRanges(SearchContext ctx, MappedFieldType fieldType) throws I
// TODO any heavy operation that shouldn't be in the loop?
switch (pointType) {
case "half_float":
HalfFloatPoint.encodeDimension((float) rangeMin, min, 0);
HalfFloatPoint.encodeDimension((float) rangeMax - 1, max, 0);
break;
case "int":
IntPoint.encodeDimension((int) rangeMin, min, 0);
IntPoint.encodeDimension((int) rangeMax, max, 0);
IntPoint.encodeDimension((int) rangeMax - 1, max, 0);
break;
case "float":
FloatPoint.encodeDimension((float) rangeMin, min, 0);
FloatPoint.encodeDimension((float) rangeMax - 1, max, 0);
break;
case "long":
if (scaled) {
// use reflection to see if fieldType has a method called getScalingFactor
Expand All @@ -557,10 +569,16 @@ public Ranges buildRanges(SearchContext ctx, MappedFieldType fieldType) throws I
rangeMax = scalingFactor * rangeMax;
}
LongPoint.encodeDimension((long) rangeMin, min, 0);
LongPoint.encodeDimension((long) rangeMax, max, 0);
LongPoint.encodeDimension((long) rangeMax - 1, max, 0);
break;
case "double":
DoublePoint.encodeDimension(rangeMin, min, 0);
DoublePoint.encodeDimension(rangeMax - 1, max, 0);
break;
case "big_integer":
BigIntegerPoint.encodeDimension(convertDoubleToBigInteger(rangeMin), min, 0);
BigIntegerPoint.encodeDimension(convertDoubleToBigInteger(rangeMax - 1), max, 0);
break;
}

mins[i] = min;
Expand All @@ -570,6 +588,24 @@ public Ranges buildRanges(SearchContext ctx, MappedFieldType fieldType) throws I
return new Ranges(mins, maxs, byteLen);
}

public static BigInteger convertDoubleToBigInteger(double value) {
// we use big integer to represent unsigned long
BigInteger maxUnsignedLong = BigInteger.valueOf(2).pow(64).subtract(BigInteger.ONE);

if (Double.isNaN(value)) {
return BigInteger.ZERO;
} else if (Double.isInfinite(value)) {
if (value > 0) {
return maxUnsignedLong;
} else {
return BigInteger.ZERO;
}
} else {
BigDecimal bigDecimal = BigDecimal.valueOf(value);
return bigDecimal.toBigInteger();
}
}

@Override
public Ranges buildRanges(LeafReaderContext leaf, SearchContext ctx, MappedFieldType fieldType) throws IOException {
return buildRanges(ctx, fieldType);
Expand Down Expand Up @@ -701,8 +737,6 @@ private static DebugInfo multiRangesTraverse(
return debugInfo;
}

private static final ArrayUtil.ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(8);

private static class Ranges {
byte[][] min;
byte[][] max;
Expand Down

0 comments on commit 90d6790

Please sign in to comment.