From 0ef8e5aa800845d63a3c848a646aa08afa24f0e6 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Wed, 25 Apr 2018 15:05:39 +0000 Subject: [PATCH] SOLR-12271: Fix for analytics component reading negative values from double and float fields. --- .../analytics/function/field/DoubleField.java | 3 +- .../analytics/function/field/FloatField.java | 3 +- .../field/AbstractAnalyticsFieldTest.java | 34 +++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/DoubleField.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/DoubleField.java index 68941a4e7a8..fae26e3e03d 100644 --- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/DoubleField.java +++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/DoubleField.java @@ -23,7 +23,6 @@ import java.util.function.DoubleConsumer; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.util.NumericUtils; import org.apache.solr.analytics.facet.compare.ExpressionComparator; import org.apache.solr.analytics.value.DoubleValue.CastingDoubleValue; import org.apache.solr.schema.DoublePointField; @@ -50,7 +49,7 @@ public class DoubleField extends AnalyticsField implements CastingDoubleValue { public void collect(int doc) throws IOException { exists = docValues.advanceExact(doc); if (exists) { - value = NumericUtils.sortableLongToDouble(docValues.longValue()); + value = Double.longBitsToDouble(docValues.longValue()); } } diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/FloatField.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/FloatField.java index c382d610340..82e8295835d 100644 --- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/FloatField.java +++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/function/field/FloatField.java @@ -23,7 +23,6 @@ import java.util.function.DoubleConsumer; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.util.NumericUtils; import org.apache.solr.analytics.facet.compare.ExpressionComparator; import org.apache.solr.analytics.util.function.FloatConsumer; import org.apache.solr.analytics.value.FloatValue.CastingFloatValue; @@ -51,7 +50,7 @@ public class FloatField extends AnalyticsField implements CastingFloatValue { public void collect(int doc) throws IOException { exists = docValues.advanceExact(doc); if (exists) { - value = NumericUtils.sortableIntToFloat((int)docValues.longValue()); + value = Float.intBitsToFloat((int)docValues.longValue()); } } diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java index 4361dea2715..299d21e8c10 100644 --- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java +++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/function/field/AbstractAnalyticsFieldTest.java @@ -84,11 +84,11 @@ public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 { missingDocuments = new ArrayList<>(); - assertU(adoc("id", "-1")); - missingDocuments.add("-1"); + assertU(adoc("id", "-2")); + missingDocuments.add("-2"); assertU(adoc("id", "5")); missingDocuments.add("5"); - for (int i = 0; i < 5; ++i) { + for (int i = -1; i < 5; ++i) { assertU(adoc( "id", "" + i, @@ -140,17 +140,17 @@ public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 { "double_dm_p", "" + (i + 10.5), "double_dm_p", "" + (i + 20.5), - "date_dt_t", "180" + i + "-12-31T23:59:59Z", - "date_dtm_t", "180" + i + "-12-31T23:59:59Z", - "date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z", - "date_dtm_t", "18" + (i + 10) + "-12-31T23:59:59Z", - "date_dtm_t", "18" + (i + 20) + "-12-31T23:59:59Z", + "date_dt_t", (1800 + i) + "-12-31T23:59:59Z", + "date_dtm_t", (1800 + i) + "-12-31T23:59:59Z", + "date_dtm_t", (1800 + i + 10) + "-12-31T23:59:59Z", + "date_dtm_t", (1800 + i + 10) + "-12-31T23:59:59Z", + "date_dtm_t", (1800 + i + 20) + "-12-31T23:59:59Z", - "date_dt_p", "180" + i + "-12-31T23:59:59Z", - "date_dtm_p", "180" + i + "-12-31T23:59:59Z", - "date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z", - "date_dtm_p", "18" + (i + 10) + "-12-31T23:59:59Z", - "date_dtm_p", "18" + (i + 20) + "-12-31T23:59:59Z", + "date_dt_p", (1800 + i) + "-12-31T23:59:59Z", + "date_dtm_p", (1800 + i) + "-12-31T23:59:59Z", + "date_dtm_p", (1800 + i + 10) + "-12-31T23:59:59Z", + "date_dtm_p", (1800 + i + 10) + "-12-31T23:59:59Z", + "date_dtm_p", (1800 + i + 20) + "-12-31T23:59:59Z", "string_s", "abc" + i, "string_sm", "abc" + i, @@ -192,11 +192,11 @@ public class AbstractAnalyticsFieldTest extends SolrTestCaseJ4 { doubles.put(i + 20.5, 1); multiDoubles.put(""+i, doubles); - singleDates.put(""+i, Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli()); + singleDates.put(""+i, Instant.parse((1800 + i) + "-12-31T23:59:59Z").toEpochMilli()); Map dates = new HashMap<>(); - dates.put(Instant.parse("180" + i + "-12-31T23:59:59Z").toEpochMilli(), 1); - dates.put(Instant.parse("18" + ( i + 10 ) + "-12-31T23:59:59Z").toEpochMilli(), 2); - dates.put(Instant.parse("18" + ( i + 20 ) + "-12-31T23:59:59Z").toEpochMilli(), 1); + dates.put(Instant.parse((1800 + i) + "-12-31T23:59:59Z").toEpochMilli(), 1); + dates.put(Instant.parse((1800 + i + 10) + "-12-31T23:59:59Z").toEpochMilli(), 2); + dates.put(Instant.parse((1800 + i + 20) + "-12-31T23:59:59Z").toEpochMilli(), 1); multiDates.put(""+i, dates); singleStrings.put(""+i, "abc" + i);