You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ge...@apache.org on 2019/05/06 04:10:49 UTC

[lucene-solr] branch branch_8_1 updated: SOLR-13318: Fix casting issues in BucketBasedJsonFacet

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

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


The following commit(s) were added to refs/heads/branch_8_1 by this push:
     new 538b450  SOLR-13318: Fix casting issues in BucketBasedJsonFacet
538b450 is described below

commit 538b450236367907b4ab75852ca6d44032ac670b
Author: Jason Gerlowski <ge...@apache.org>
AuthorDate: Sun May 5 23:38:05 2019 -0400

    SOLR-13318: Fix casting issues in BucketBasedJsonFacet
---
 solr/CHANGES.txt                                   |  2 +
 .../solrj/response/json/BucketBasedJsonFacet.java  | 71 +++++++++++++++++++---
 .../JsonQueryRequestFacetingIntegrationTest.java   |  8 +--
 3 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3c2e479..053ac4c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -204,6 +204,8 @@ Bug Fixes
 * SOLR-13410: Designated overseer wasn't able to rejoin election queue upon restart (Ishan Chattopadhyaya,
   Kesharee Nandan Vishwakarma)
 
+* SOLR-13318: Fix ClassCastException in SolrJ JsonFaceting classes (Munendra S N via Jason Gerlowski)
+
 Improvements
 ----------------------
 
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/BucketBasedJsonFacet.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/BucketBasedJsonFacet.java
index 29b67a3..0ef8fb1 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/BucketBasedJsonFacet.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/BucketBasedJsonFacet.java
@@ -43,11 +43,11 @@ import org.apache.solr.common.util.NamedList;
 public class BucketBasedJsonFacet {
   public static final int UNSET_FLAG = -1;
   private List<BucketJsonFacet> buckets;
-  private int numBuckets = UNSET_FLAG;
+  private long numBuckets = UNSET_FLAG;
   private long allBuckets = UNSET_FLAG;
-  private int beforeFirstBucketCount = UNSET_FLAG;
-  private int afterLastBucketCount = UNSET_FLAG;
-  private int betweenAllBucketsCount = UNSET_FLAG;
+  private long beforeFirstBucketCount = UNSET_FLAG;
+  private long afterLastBucketCount = UNSET_FLAG;
+  private long betweenAllBucketsCount = UNSET_FLAG;
 
   public BucketBasedJsonFacet(NamedList<Object> bucketBasedFacet) {
     for (Map.Entry<String, Object> entry : bucketBasedFacet) {
@@ -60,15 +60,15 @@ public class BucketBasedJsonFacet {
           buckets.add(new BucketJsonFacet(bucket));
         }
       } else if ("numBuckets".equals(key)) {
-        numBuckets = (int) value;
+        numBuckets = ((Number) value).longValue();
       } else if ("allBuckets".equals(key)) {
-        allBuckets = (long) ((NamedList)value).get("count");
+        allBuckets = ((Number) ((NamedList)value).get("count")).longValue();
       } else if ("before".equals(key)) {
-        beforeFirstBucketCount = (int) ((NamedList)value).get("count");
+        beforeFirstBucketCount = ((Number) ((NamedList)value).get("count")).longValue();
       } else if ("after".equals(key)) {
-        afterLastBucketCount = (int) ((NamedList)value).get("count");
+        afterLastBucketCount = ((Number) ((NamedList)value).get("count")).longValue();
       } else if ("between".equals(key)) {
-        betweenAllBucketsCount = (int) ((NamedList)value).get("count");
+        betweenAllBucketsCount = ((Number) ((NamedList)value).get("count")).longValue();
       } else {
         // We don't recognize the key.  Possible JSON faceting schema has changed without updating client.
         // Silently ignore for now, though we may want to consider throwing an error if this proves problematic.
@@ -89,8 +89,22 @@ public class BucketBasedJsonFacet {
    * This value can only be computed on "terms" facets where the user has specifically requested it with the
    * {@code numBuckets} option.  {@link #UNSET_FLAG} is returned if this is a "range" facet or {@code numBuckets}
    * computation was not requested in the intiial request.
+   *
+   * @deprecated this method can trigger ClassCastException's if the returned value is a long.  In the future it will
+   * return a 'long' instead to avoid this problem.  Until then, use {@link #getNumBucketsCount()} instead.
    */
   public int getNumBuckets() {
+    return (int) numBuckets;
+  }
+
+  /**
+   * The total number of buckets found in the domain (of which the returned buckets are only a part).
+   *
+   * This value can only be computed on "terms" facets where the user has specifically requested it with the
+   * {@code numBuckets} option.  {@link #UNSET_FLAG} is returned if this is a "range" facet or {@code numBuckets}
+   * computation was not requested in the intiial request.
+   */
+  public long getNumBucketsCount() {
     return numBuckets;
   }
 
@@ -112,18 +126,42 @@ public class BucketBasedJsonFacet {
    *
    * This value is only present if the user has specifically requested it with the {@code other} option.
    * {@link #UNSET_FLAG} is returned if this is not the case.
+   *
+   * @deprecated this method can trigger ClassCastException's if the returned value is a long.  In the future it will
+   * return a 'long' instead to avoid this problem.  Until then, use {@link #getBeforeCount()} instead.
    */
   public int getBefore() {
-    return beforeFirstBucketCount;
+    return (int) beforeFirstBucketCount;
   }
 
   /**
+   * The count of all records whose field value precedes the {@code start} of this "range" facet
+   *
+   * This value is only present if the user has specifically requested it with the {@code other} option.
+   * {@link #UNSET_FLAG} is returned if this is not the case.
+   */
+  public long getBeforeCount() { return beforeFirstBucketCount; }
+
+  /**
    * The count of all records whose field value follows the {@code end} of this "range" facet
    *
    * This value is only present if the user has specifically requested it with the {@code other} option.
    * {@link #UNSET_FLAG} is returned if this is not the case.
+   *
+   * @deprecated this method can trigger ClassCastException's if the returned value is a long.  In the future it will
+   * return a 'long' instead to avoid this problem.  Until then, use {@link #getAfterCount()} instead.
    */
   public int getAfter() {
+    return (int) afterLastBucketCount;
+  }
+
+  /**
+   * The count of all records whose field value follows the {@code end} of this "range" facet
+   *
+   * This value is only present if the user has specifically requested it with the {@code other} option.
+   * {@link #UNSET_FLAG} is returned if this is not the case.
+   */
+  public long getAfterCount() {
     return afterLastBucketCount;
   }
 
@@ -132,8 +170,21 @@ public class BucketBasedJsonFacet {
    *
    * This value is only present if the user has specifically requested it with the {@code other} option.
    * {@link #UNSET_FLAG} is returned if this is not the case.
+   *
+   * @deprecated this method can trigger ClassCastException's if the returned value is a long.  In the future it will
+   * return a 'long' instead to avoid this problem.  Until then, use {@link #getBetweenCount()} instead.
    */
   public int getBetween() {
+    return (int) betweenAllBucketsCount;
+  }
+
+  /**
+   * The count of all records whose field value falls between {@code start} and {@code end}.
+   *
+   * This value is only present if the user has specifically requested it with the {@code other} option.
+   * {@link #UNSET_FLAG} is returned if this is not the case.
+   */
+  public long getBetweenCount() {
     return betweenAllBucketsCount;
   }
 }
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java
index 4852c76..757a0eb 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java
@@ -132,7 +132,7 @@ public class JsonQueryRequestFacetingIntegrationTest extends SolrCloudTestCase {
         new FacetBucket("electronics", NUM_ELECTRONICS),
         new FacetBucket("currency", NUM_CURRENCY),
         new FacetBucket("memory", NUM_MEMORY));
-    assertEquals(NUM_CATEGORIES, topLevelFacetData.getBucketBasedFacets("top_cats").getNumBuckets());
+    assertEquals(NUM_CATEGORIES, topLevelFacetData.getBucketBasedFacets("top_cats").getNumBucketsCount());
   }
 
   @Test
@@ -539,9 +539,9 @@ public class JsonQueryRequestFacetingIntegrationTest extends SolrCloudTestCase {
         new FacetBucket(40.0f, 0),
         new FacetBucket(60.0f, 1),
         new FacetBucket(80.0f, 1));
-    assertEquals(0, topLevelFacetData.getBucketBasedFacets("price_range").getBefore());
-    assertEquals(9, topLevelFacetData.getBucketBasedFacets("price_range").getAfter());
-    assertEquals(7, topLevelFacetData.getBucketBasedFacets("price_range").getBetween());
+    assertEquals(0, topLevelFacetData.getBucketBasedFacets("price_range").getBeforeCount());
+    assertEquals(9, topLevelFacetData.getBucketBasedFacets("price_range").getAfterCount());
+    assertEquals(7, topLevelFacetData.getBucketBasedFacets("price_range").getBetweenCount());
   }
 
   private class FacetBucket {