diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DoubleScriptFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/DoubleScriptFieldType.java index 32f6c234f5487..bf18bca8ce4b3 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DoubleScriptFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DoubleScriptFieldType.java @@ -8,9 +8,6 @@ package org.elasticsearch.index.mapper; -import com.carrotsearch.hppc.LongHashSet; -import com.carrotsearch.hppc.LongSet; - import org.apache.lucene.search.Query; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.time.DateMathParser; @@ -30,7 +27,9 @@ import java.time.ZoneId; import java.util.Collection; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; @@ -139,7 +138,7 @@ public Query termsQuery(Collection values, SearchExecutionContext context) { if (values.isEmpty()) { return Queries.newMatchAllQuery(); } - LongSet terms = new LongHashSet(values.size()); + Set terms = new HashSet<>(values.size()); for (Object value : values) { terms.add(Double.doubleToLongBits(NumberType.objectToDouble(value))); } diff --git a/server/src/main/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQuery.java b/server/src/main/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQuery.java index 7d0161c2c1031..945ae23df140c 100644 --- a/server/src/main/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQuery.java +++ b/server/src/main/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQuery.java @@ -8,23 +8,21 @@ package org.elasticsearch.search.runtime; -import com.carrotsearch.hppc.LongSet; -import com.carrotsearch.hppc.cursors.LongCursor; - import org.elasticsearch.script.DoubleFieldScript; import org.elasticsearch.script.Script; import java.util.Arrays; import java.util.Objects; +import java.util.Set; public class DoubleScriptFieldTermsQuery extends AbstractDoubleScriptFieldQuery { - private final LongSet terms; + private final Set terms; /** * Build the query. * @param terms The terms converted to a long with {@link Double#doubleToLongBits(double)}. */ - public DoubleScriptFieldTermsQuery(Script script, DoubleFieldScript.LeafFactory leafFactory, String fieldName, LongSet terms) { + public DoubleScriptFieldTermsQuery(Script script, DoubleFieldScript.LeafFactory leafFactory, String fieldName, Set terms) { super(script, leafFactory, fieldName); this.terms = terms; } @@ -66,8 +64,8 @@ public boolean equals(Object obj) { double[] terms() { double[] result = new double[terms.size()]; int i = 0; - for (LongCursor lc : terms) { - result[i++] = Double.longBitsToDouble(lc.value); + for (long l : terms) { + result[i++] = Double.longBitsToDouble(l); } return result; } diff --git a/server/src/test/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQueryTests.java b/server/src/test/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQueryTests.java index 6d28491b170bd..60c36fd8dd551 100644 --- a/server/src/test/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQueryTests.java +++ b/server/src/test/java/org/elasticsearch/search/runtime/DoubleScriptFieldTermsQueryTests.java @@ -8,13 +8,12 @@ package org.elasticsearch.search.runtime; -import com.carrotsearch.hppc.LongHashSet; -import com.carrotsearch.hppc.LongSet; - import org.elasticsearch.script.Script; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static java.util.stream.Collectors.toList; import static org.hamcrest.Matchers.endsWith; @@ -25,7 +24,7 @@ public class DoubleScriptFieldTermsQueryTests extends AbstractDoubleScriptFieldQueryTestCase { @Override protected DoubleScriptFieldTermsQuery createTestInstance() { - LongSet terms = new LongHashSet(); + Set terms = new HashSet<>(); int count = between(1, 100); while (terms.size() < count) { terms.add(Double.doubleToLongBits(randomDouble())); @@ -35,7 +34,7 @@ protected DoubleScriptFieldTermsQuery createTestInstance() { @Override protected DoubleScriptFieldTermsQuery copy(DoubleScriptFieldTermsQuery orig) { - LongSet terms = new LongHashSet(); + Set terms = new HashSet<>(); for (double term : orig.terms()) { terms.add(Double.doubleToLongBits(term)); } @@ -46,7 +45,7 @@ protected DoubleScriptFieldTermsQuery copy(DoubleScriptFieldTermsQuery orig) { protected DoubleScriptFieldTermsQuery mutate(DoubleScriptFieldTermsQuery orig) { Script script = orig.script(); String fieldName = orig.fieldName(); - LongSet terms = new LongHashSet(); + Set terms = new HashSet<>(); for (double term : orig.terms()) { terms.add(Double.doubleToLongBits(term)); } @@ -54,7 +53,7 @@ protected DoubleScriptFieldTermsQuery mutate(DoubleScriptFieldTermsQuery orig) { case 0 -> script = randomValueOtherThan(script, this::randomScript); case 1 -> fieldName += "modified"; case 2 -> { - terms = new LongHashSet(terms); + terms = new HashSet<>(terms); while (false == terms.add(Double.doubleToLongBits(randomDouble()))) { // Random double was already in the set } @@ -70,7 +69,7 @@ public void testMatches() { randomScript(), leafFactory, "test", - LongHashSet.from(Double.doubleToLongBits(0.1), Double.doubleToLongBits(0.2), Double.doubleToLongBits(7.5)) + Set.of(Double.doubleToLongBits(0.1), Double.doubleToLongBits(0.2), Double.doubleToLongBits(7.5)) ); assertTrue(query.matches(new double[] { 0.1 }, 1)); assertTrue(query.matches(new double[] { 0.2 }, 1));