You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mu...@apache.org on 2019/12/08 05:44:28 UTC

[lucene-solr] branch branch_8x updated: SOLR-11706: fix for multivalued trie date in min/max and more tests

This is an automated email from the ASF dual-hosted git repository.

munendrasn pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 42a6fcb  SOLR-11706: fix for multivalued trie date in min/max and more tests
42a6fcb is described below

commit 42a6fcbdd98de8ee6b7c87c4cfe78814505462fd
Author: Munendra S N <mu...@apache.org>
AuthorDate: Sun Dec 8 10:49:37 2019 +0530

    SOLR-11706: fix for multivalued trie date in min/max and more tests
    
    * selecting single value for multivalued trie date field is not
      supported.
    * add additional tests for variance, unique, hll aggregations
---
 .../org/apache/solr/search/facet/MinMaxAgg.java    | 12 ++++--
 ...stributedFacetSimpleRefinementLongTailTest.java | 21 +++++++++--
 .../apache/solr/search/facet/TestJsonFacets.java   | 44 ++++++++++------------
 3 files changed, 47 insertions(+), 30 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
index a62503a..f369226 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/MinMaxAgg.java
@@ -57,12 +57,18 @@ public class MinMaxAgg extends SimpleAggValueSource {
 
       if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
         if (sf.hasDocValues()) {
-          if(sf.getType().getNumberType() != null) {
+          if (sf.getType().isPointField()) {
             FieldType.MultiValueSelector choice = minmax == 1 ? FieldType.MultiValueSelector.MIN : FieldType.MultiValueSelector.MAX;
             vs = sf.getType().getSingleValueSource(choice, sf, null);
           } else {
-            // multi-valued strings
-            return new MinMaxSortedSetDVAcc(fcontext, sf, numSlots);
+            NumberType numberType = sf.getType().getNumberType();
+            if (numberType != null && numberType != NumberType.DATE) {
+              // TrieDate doesn't support selection of single value
+              FieldType.MultiValueSelector choice = minmax == 1 ? FieldType.MultiValueSelector.MIN : FieldType.MultiValueSelector.MAX;
+              vs = sf.getType().getSingleValueSource(choice, sf, null);
+            } else {
+              return new MinMaxSortedSetDVAcc(fcontext, sf, numSlots);
+            }
           }
         } else {
           if (sf.getType().isPointField()) {
diff --git a/solr/core/src/test/org/apache/solr/search/facet/DistributedFacetSimpleRefinementLongTailTest.java b/solr/core/src/test/org/apache/solr/search/facet/DistributedFacetSimpleRefinementLongTailTest.java
index 6c019b7..0ed8659 100644
--- a/solr/core/src/test/org/apache/solr/search/facet/DistributedFacetSimpleRefinementLongTailTest.java
+++ b/solr/core/src/test/org/apache/solr/search/facet/DistributedFacetSimpleRefinementLongTailTest.java
@@ -42,9 +42,8 @@ import org.junit.Test;
  */
 public class DistributedFacetSimpleRefinementLongTailTest extends BaseDistributedSearchTestCase {
 
-  // TODO: add hll & variance - update all assertions to test their values (right after any mention of 'stddev')
   private static List<String> ALL_STATS = Arrays.asList("min", "max", "sum", "stddev", "avg", "sumsq", "unique",
-      "missing", "countvals", "percentile");
+      "missing", "countvals", "percentile", "variance", "hll");
                                                         
   private final String STAT_FIELD;
   private String ALL_STATS_JSON = "";
@@ -236,8 +235,12 @@ public class DistributedFacetSimpleRefinementLongTailTest extends BaseDistribute
       assertEquals(1.0D, bucket.get("percentile"));
       assertEquals(0.475247524752475D, (double) bucket.get("avg"), 0.1E-7);
       assertEquals(54.0D, (double) bucket.get("sumsq"), 0.1E-7);
-      // assertEquals(0.55846323792D, bucket.getStddev(), 0.1E-7); // TODO: SOLR-11725
+      // assertEquals(0.55846323792D, (double) bucket.get("stddev"), 0.1E-7); // TODO: SOLR-11725
+      // assertEquals(0.3118811881D, (double) bucket.get("variance"), 0.1E-7); // TODO: SOLR-11725
       assertEquals(0.55569169111D, (double) bucket.get("stddev"), 0.1E-7); // json.facet is using the "uncorrected stddev"
+      assertEquals(0.3087932556D, (double) bucket.get("variance"), 0.1E-7); // json.facet is using the "uncorrected variance"
+      assertEquals(3L, bucket.get("unique"));
+      assertEquals(3L, bucket.get("hll"));
     }
 
 
@@ -397,7 +400,11 @@ public class DistributedFacetSimpleRefinementLongTailTest extends BaseDistribute
     assertEquals(115.5D, (double) aaa0_Bucket.get("avg"), 0.1E-7);
     assertEquals(1.674585E7D, (double) aaa0_Bucket.get("sumsq"), 0.1E-7);
     // assertEquals(206.4493184076D, (double) aaa0_Bucket.get("stddev"), 0.1E-7); // TODO: SOLR-11725
+    // assertEquals(42621.32107023412D, (double) aaa0_Bucket.get("variance"), 0.1E-7);  // TODO: SOLR-11725
     assertEquals(206.1049489944D, (double) aaa0_Bucket.get("stddev"), 0.1E-7); // json.facet is using the "uncorrected stddev"
+    assertEquals(42479.25D, (double) aaa0_Bucket.get("variance"), 0.1E-7); // json.facet is using the "uncorrected variance"
+    assertEquals(284L, aaa0_Bucket.get("unique"));
+    assertEquals(284L, aaa0_Bucket.get("hll"));
 
     NamedList tail_Bucket = foo_buckets.get(5);
     assertEquals(ALL_STATS.size() + 3, tail_Bucket.size()); // val,count,facet
@@ -412,7 +419,11 @@ public class DistributedFacetSimpleRefinementLongTailTest extends BaseDistribute
     assertEquals(22.0D, (double) tail_Bucket.get("avg"), 0.1E-7);
     assertEquals(58740.0D, (double) tail_Bucket.get("sumsq"), 0.1E-7);
     // assertEquals(13.0599310011D, (double) tail_Bucket.get("stddev"), 0.1E-7); // TODO: SOLR-11725
+    // assertEquals(170.5617977535D, (double) tail_Bucket.get("variance"), 0.1E-7); // TODO: SOLR-11725
     assertEquals(12.9871731592D, (double) tail_Bucket.get("stddev"), 0.1E-7); // json.facet is using the "uncorrected stddev"
+    assertEquals(168.666666667D, (double) tail_Bucket.get("variance"), 0.1E-7); // json.facet is using the "uncorrected variance"
+    assertEquals(45L, tail_Bucket.get("unique"));
+    assertEquals(45L, tail_Bucket.get("hll"));
 
     List<NamedList> tail_bar_buckets = (List) ((NamedList)tail_Bucket.get("bar")).get("buckets");
    
@@ -429,7 +440,11 @@ public class DistributedFacetSimpleRefinementLongTailTest extends BaseDistribute
     assertEquals(37.5D, (double) tailB_Bucket.get("avg"), 0.1E-7);
     assertEquals(16910.0D, (double) tailB_Bucket.get("sumsq"), 0.1E-7);
     // assertEquals(1.78376517D, (double) tailB_Bucket.get("stddev"), 0.1E-7); // TODO: SOLR-11725
+    // assertEquals(3.1818181817D, (double) tailB_Bucket.get("variance"), 0.1E-7); // TODO: SOLR-11725
     assertEquals(1.70782513D, (double) tailB_Bucket.get("stddev"), 0.1E-7); // json.facet is using the "uncorrected stddev"
+    assertEquals(2.9166666747D, (double) tailB_Bucket.get("variance"), 0.1E-7); // json.facet is using the "uncorrected variance"
+    assertEquals(6L, tailB_Bucket.get("unique"));
+    assertEquals(6L, tailB_Bucket.get("hll"));
 
     // check the SKG stats on our tailB bucket
     NamedList tailB_skg = (NamedList) tailB_Bucket.get("skg");
diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
index 06c13be..e85a295 100644
--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
@@ -1407,19 +1407,17 @@ public class TestJsonFacets extends SolrTestCaseHS {
 
     // Same thing for dates
     // test min/max of string field
-    if (date.equals("date_dt") || date.equals("date_dtd")) {  // supports only single valued currently... see SOLR-11706
-      client.testJQ(params(p, "q", "*:*"
-          , "json.facet", "{" +
-              " f3:{${terms}  type:field, field:${num_is}, facet:{a:'min(${date})'}, sort:'a desc' }" +
-              ",f4:{${terms}  type:field, field:${num_is}, facet:{a:'max(${date})'}, sort:'a asc' }" +
-              "}"
-          )
-          , "facets=={count:6 " +
-              ",f3:{ buckets:[{val:-1,count:2,a:'2002-02-02T02:02:02Z'},{val:3,count:2,a:'2002-02-02T02:02:02Z'},{val:0,count:2,a:'2001-02-03T01:02:03Z'},{val:-5,count:1,a:'2001-01-01T01:01:01Z'},{val:2,count:1,a:'2001-01-01T01:01:01Z'} ] } " +
-              ",f4:{ buckets:[{val:-5,count:1,a:'2001-01-01T01:01:01Z'},{val:2,count:1,a:'2001-01-01T01:01:01Z'},{val:-1,count:2,a:'2002-03-01T03:02:01Z'},{val:0,count:2,a:'2003-03-03T03:03:03Z'},{val:3,count:2,a:'2003-03-03T03:03:03Z'} ] } " +
-              "}"
-      );
-    }
+    client.testJQ(params(p, "q", "*:*"
+        , "json.facet", "{" +
+            " f3:{${terms}  type:field, field:${num_is}, facet:{a:'min(${date})'}, sort:'a desc' }" +
+            ",f4:{${terms}  type:field, field:${num_is}, facet:{a:'max(${date})'}, sort:'a asc' }" +
+            "}"
+        )
+        , "facets=={count:6 " +
+            ",f3:{ buckets:[{val:-1,count:2,a:'2002-02-02T02:02:02Z'},{val:3,count:2,a:'2002-02-02T02:02:02Z'},{val:0,count:2,a:'2001-02-03T01:02:03Z'},{val:-5,count:1,a:'2001-01-01T01:01:01Z'},{val:2,count:1,a:'2001-01-01T01:01:01Z'} ] } " +
+            ",f4:{ buckets:[{val:-5,count:1,a:'2001-01-01T01:01:01Z'},{val:2,count:1,a:'2001-01-01T01:01:01Z'},{val:-1,count:2,a:'2002-03-01T03:02:01Z'},{val:0,count:2,a:'2003-03-03T03:03:03Z'},{val:3,count:2,a:'2003-03-03T03:03:03Z'} ] } " +
+            "}"
+    );
 
     // test field faceting on date field
     client.testJQ(params(p, "q", "*:*"
@@ -1784,17 +1782,15 @@ public class TestJsonFacets extends SolrTestCaseHS {
             " } }"
     );
 
-    if (where_s.equals("where_s") || where_s.equals("where_sd")) {  // min/max only supports only single valued currently... see SOLR-11706
-      client.testJQ(params(p, "q", "*:*"
-          , "json.facet", "{f:{type:range, field:${num_d}, start:-5, end:10, gap:5, other:all,   facet:{ wmin:'min(${where_s})', wmax:'max(${where_s})'    }   }}"
-          )
-          , "facets=={count:6, f:{buckets:[ {val:-5.0,count:1,wmin:NY,wmax:NY}, {val:0.0,count:2,wmin:NJ,wmax:NY}, {val:5.0,count:0}]" +
-              " ,before:{count:1,wmin:NJ,wmax:NJ}" +
-              " ,after:{count:1,wmin:NJ,wmax:NJ} " +
-              " ,between:{count:3,wmin:NJ,wmax:NY} " +
-              " } }"
-      );
-    }
+    client.testJQ(params(p, "q", "*:*"
+        , "json.facet", "{f:{type:range, field:${num_d}, start:-5, end:10, gap:5, other:all,   facet:{ wmin:'min(${where_s})', wmax:'max(${where_s})'    }   }}"
+        )
+        , "facets=={count:6, f:{buckets:[ {val:-5.0,count:1,wmin:NY,wmax:NY}, {val:0.0,count:2,wmin:NJ,wmax:NY}, {val:5.0,count:0}]" +
+            " ,before:{count:1,wmin:NJ,wmax:NJ}" +
+            " ,after:{count:1,wmin:NJ,wmax:NJ} " +
+            " ,between:{count:3,wmin:NJ,wmax:NY} " +
+            " } }"
+    );
 
     // stats at top level
     client.testJQ(params(p, "q", "*:*"