From a89340fc36586ca0966c86716d245ccd2a916dbc Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Thu, 7 Dec 2023 13:48:21 -0800 Subject: [PATCH] Fixing some tests Signed-off-by: Harsha Vamsi Kalluri --- .../360_number_field_term_doc_values_only.yml | 6 +++--- .../{document => util}/LongHashSet.java | 4 +--- .../SortedUnsignedLongDocValuesSetQuery.java | 2 +- .../index/mapper/NumberFieldMapper.java | 20 ++++++++++++------- 4 files changed, 18 insertions(+), 14 deletions(-) rename server/src/main/java/org/apache/lucene/{document => util}/LongHashSet.java (97%) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/360_number_field_term_doc_values_only.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/360_number_field_term_doc_values_only.yml index cb2589821df9d..1818f3371ca66 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/360_number_field_term_doc_values_only.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/360_number_field_term_doc_values_only.yml @@ -62,7 +62,7 @@ setup: integer: 1 long: 1 short: 1 - unsigned_long: 1 + unsigned_long: 10223372036854775807 - do: headers: @@ -78,7 +78,7 @@ setup: integer: 1 long: 1 short: 1 - unsigned_long: 1 + unsigned_long: 10223372036854775807 - do: @@ -95,7 +95,7 @@ setup: integer: 1 long: 1 short: 1 - unsigned_long: 1 + unsigned_long: 10223372036854775807 - do: diff --git a/server/src/main/java/org/apache/lucene/document/LongHashSet.java b/server/src/main/java/org/apache/lucene/util/LongHashSet.java similarity index 97% rename from server/src/main/java/org/apache/lucene/document/LongHashSet.java rename to server/src/main/java/org/apache/lucene/util/LongHashSet.java index fde20466042cd..a463e8a189585 100644 --- a/server/src/main/java/org/apache/lucene/document/LongHashSet.java +++ b/server/src/main/java/org/apache/lucene/util/LongHashSet.java @@ -6,10 +6,8 @@ * compatible open source license. */ -package org.apache.lucene.document; +package org.apache.lucene.util; -import org.apache.lucene.util.Accountable; -import org.apache.lucene.util.RamUsageEstimator; import org.apache.lucene.util.packed.PackedInts; import java.util.Arrays; diff --git a/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java b/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java index 1cfbbd5ebf2a8..2372adbdacf52 100644 --- a/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java +++ b/server/src/main/java/org/opensearch/index/document/SortedUnsignedLongDocValuesSetQuery.java @@ -8,7 +8,6 @@ package org.opensearch.index.document; -import org.apache.lucene.document.LongHashSet; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.LeafReader; @@ -25,6 +24,7 @@ import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; import org.apache.lucene.search.Weight; +import org.apache.lucene.util.LongHashSet; import java.io.IOException; import java.math.BigInteger; diff --git a/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java index 7e35e561b898e..a484b427b64e7 100644 --- a/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java @@ -222,7 +222,9 @@ public Query termsQuery(String field, List values, boolean hasDocValues, long points[] = new long[v.length]; for (int i = 0; i < values.size(); ++i) { v[i] = parse(values.get(i), false); - points[i] = HalfFloatPoint.halfFloatToSortableShort(v[i]); + if (hasDocValues) { + points[i] = HalfFloatPoint.halfFloatToSortableShort(v[i]); + } } if (isSearchable && hasDocValues) { Query query = HalfFloatPoint.newSetQuery(field, v); @@ -357,7 +359,9 @@ public Query termsQuery(String field, List values, boolean hasDocValues, long points[] = new long[v.length]; for (int i = 0; i < values.size(); ++i) { v[i] = parse(values.get(i), false); - points[i] = NumericUtils.floatToSortableInt(v[i]); + if (hasDocValues) { + points[i] = NumericUtils.floatToSortableInt(v[i]); + } } if (isSearchable && hasDocValues) { return new IndexOrDocValuesQuery( @@ -481,7 +485,9 @@ public Query termsQuery(String field, List values, boolean hasDocValues, long points[] = new long[v.length]; for (int i = 0; i < values.size(); ++i) { v[i] = parse(values.get(i), false); - points[i] = NumericUtils.doubleToSortableLong(v[i]); + if (hasDocValues) { + points[i] = NumericUtils.doubleToSortableLong(v[i]); + } } if (isSearchable && hasDocValues) { return new IndexOrDocValuesQuery( @@ -758,8 +764,10 @@ public Query termsQuery(String field, List values, boolean hasDocValues, v = Arrays.copyOf(v, upTo); } long points[] = new long[v.length]; - for (int i = 0; i < v.length; i++) { - points[i] = v[i]; + if (hasDocValues) { + for (int i = 0; i < v.length; i++) { + points[i] = v[i]; + } } if (isSearchable && hasDocValues) { return new IndexOrDocValuesQuery( @@ -999,14 +1007,12 @@ public Query termQuery(String field, Object value, boolean hasDocValues, boolean @Override public Query termsQuery(String field, List values, boolean hasDocvalues, boolean isSearchable) { BigInteger[] v = new BigInteger[values.size()]; - long points[] = new long[v.length]; int upTo = 0; for (int i = 0; i < values.size(); i++) { Object value = values.get(i); if (!hasDecimalPart(value)) { v[upTo++] = parse(value, true); - points[i] = v[i].longValue(); } }