lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbern...@apache.org
Subject [lucene-solr] 01/01: SOLR-13047: Basic test working
Date Thu, 09 May 2019 17:37:48 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit a97076cb091443089dbc8835b8433238ceaaac76
Author: Joel Bernstein <jbernste@apache.org>
AuthorDate: Thu May 9 13:37:26 2019 -0400

    SOLR-13047: Basic test working
---
 .../solr/client/solrj/io/stream/Facet2DStream.java | 104 ++++++++++-----------
 .../solrj/io/stream/StreamExpressionTest.java      |  29 +++---
 2 files changed, 65 insertions(+), 68 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java
index 6eb46ba..8505c85 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/Facet2DStream.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -61,10 +62,9 @@ public class Facet2DStream extends TupleStream implements Expressible {
   private ModifiableSolrParams params;
   private Bucket x;
   private Bucket y;
-  private String dimensions;
   private Metric metric;
   private String zkHost;
-
+  private Iterator<Tuple> out;
   private List<Tuple> tuples = new ArrayList<Tuple>();
   private int dimensionX;
   private int dimensionY;
@@ -284,6 +284,7 @@ public class Facet2DStream extends TupleStream implements Expressible
{
     FieldComparator[] adjustedSorts = adjustSorts(x, y, bucketSort);
 
     String json = getJsonFacetString(x, y, metric, adjustedSorts, dimensionX, dimensionY);
+    System.out.println("#######JSON:"+json);
     //assert expectedJson(json);
 
     ModifiableSolrParams paramsLoc = new ModifiableSolrParams(params);
@@ -293,7 +294,9 @@ public class Facet2DStream extends TupleStream implements Expressible
{
     QueryRequest request = new QueryRequest(paramsLoc, SolrRequest.METHOD.POST);
     try {
       NamedList response = cloudSolrClient.request(request, collection);
+      System.out.println("###### Response:"+response.toString());
       getTuples(response, x, y, metric);
+      this.out = tuples.iterator();
 
     } catch (Exception e) {
       throw new IOException(e);
@@ -301,11 +304,8 @@ public class Facet2DStream extends TupleStream implements Expressible
{
   }
 
   public Tuple read() throws IOException {
-    this.index = 0;
-    if (index < tuples.size() && index < dimensionX * dimensionY) {
-      Tuple tuple = tuples.get(index);
-      ++index;
-      return tuple;
+    if (out.hasNext()) {
+      return out.next();
     } else {
       Map fields = new HashMap();
       fields.put("rows", tuples.size());
@@ -379,10 +379,10 @@ public class Facet2DStream extends TupleStream implements Expressible
{
     buf.append(",\"facet\":{");
 
     String identifier = metric.getIdentifier();
-    if (identifier.startsWith("count(")) {
+    if (!identifier.startsWith("count(")) {
       buf.append("\"agg\":\"" + identifier + "\"");
+      buf.append(",");
     }
-    buf.append(",");
     buf.append('"');
     buf.append("y");
     buf.append('"');
@@ -393,7 +393,7 @@ public class Facet2DStream extends TupleStream implements Expressible
{
     String fsortY = getFacetSort(adjustedSorts[1].getLeftFieldName(), metric);
     buf.append(",\"sort\":\""+ fsortY + " desc\"");
     buf.append(",\"facet\":{");
-    if (identifier.startsWith("count(")) {
+    if (!identifier.startsWith("count(")) {
       buf.append("\"agg\":\"" + identifier + "\"");
     }
     buf.append("}}}}");
@@ -425,61 +425,57 @@ public class Facet2DStream extends TupleStream implements Expressible
{
 
   private void fillTuples(int level, List<Tuple> tuples, Tuple currentTuple, NamedList
facets, Bucket x, Bucket y, Metric metric) {
     String bucketXName = x.toString();
-    NamedList nlX = (NamedList) facets.get(bucketXName);
-
     String bucketYName = y.toString();
-    NamedList nlY = (NamedList) facets.get(bucketYName);
 
-    if (nlX == null || nlY == null) {
-      return;
-    }
-    List allXBuckets = (List) nlX.get("x");
+
+
+    NamedList allXBuckets = (NamedList) facets.get("x");
     for (int b = 0; b < allXBuckets.size(); b++) {
-      NamedList bucket = (NamedList) allXBuckets.get(b);
-      Object val = bucket.get("val");
-      if (val instanceof Integer) {
-        val = ((Integer) val).longValue();
-      }
-      Tuple t = currentTuple.clone();
-      t.put(bucketXName, val);
-
-      List allYBuckets = (List) nlY.get("y");
-      for (int d = 0; d < allYBuckets.size(); d++) {
-        NamedList bucketY = (NamedList) allYBuckets.get(d);
-        Object valY = bucketY.get("val");
-        if (valY instanceof Integer) {
-          valY = ((Integer) valY).longValue();
+      List buckets = (List) allXBuckets.get("buckets");
+      for(int s=0; s<buckets.size(); s++) {
+
+        NamedList bucket = (NamedList)buckets.get(s);
+        Object val = bucket.get("val");
+        if (val instanceof Integer) {
+          val = ((Integer) val).longValue();
         }
-        t = currentTuple.clone();
-        t.put(bucketYName, valY);
-      }
-      int nextLevel = level + 1;
-      if (nextLevel <= 2) {
-        fillTuples(nextLevel, tuples, t.clone(), bucket, x, y, metric);
-      } else {
-        int m = 0;
-        String identifier = metric.getIdentifier();
-        if (!identifier.startsWith("count(")) {
-          Number d = (Number) bucket.get("agg:" + identifier);
-          if (metric.outputLong) {
-            if (d instanceof Long || d instanceof Integer) {
-              t.put(identifier, d.longValue());
+        Tuple tx = currentTuple.clone();
+        tx.put(bucketXName, val);
+
+        NamedList allYBuckets = (NamedList) bucket.get("y");
+        List ybuckets = (List)allYBuckets.get("buckets");
+
+        for (int d = 0; d < ybuckets.size(); d++) {
+          NamedList bucketY = (NamedList) ybuckets.get(d);
+          Object valY = bucketY.get("val");
+          if (valY instanceof Integer) {
+            valY = ((Integer) valY).longValue();
+          }
+          Tuple yt = tx.clone();
+          yt.put(bucketYName, valY);
+
+          int m = 0;
+          String identifier = metric.getIdentifier();
+          if (!identifier.startsWith("count(")) {
+            Number d1 = (Number) buckets.get(0);
+            if (metric.outputLong) {
+              if (d1 instanceof Long || d1 instanceof Integer) {
+                yt.put(identifier, d1.longValue());
+              } else {
+                yt.put(identifier, Math.round(d1.doubleValue()));
+              }
             } else {
-              t.put(identifier, Math.round(d.doubleValue()));
+              yt.put(identifier, d1.doubleValue());
             }
+            ++m;
           } else {
-            t.put(identifier, d.doubleValue());
+            //long l = ((Number) bucket.get(0).longValue();
+            yt.put("count(*)", 1);
           }
-          ++m;
-        } else {
-          long l = ((Number) bucket.get("count(*)")).longValue();
-          t.put("count(*)", l);
+          tuples.add(yt);
         }
       }
-      tuples.add(t);
     }
-
-
   }
 
   public int getCost() {
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
index b4ba40f..f5d55cc 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
@@ -840,17 +840,17 @@ public class StreamExpressionTest extends SolrCloudTestCase {
   @Test
   public void testFacet2DStream() throws Exception {
     new UpdateRequest()
-         .add(id, "0", "diseases_s", "stroke", "symptoms_s", "confusion")
-         .add(id, "1", "diseases_s", "cancer", "symptoms_s", "indigestion")
-         .add(id, "2", "diseases_s", "diabetes", "symptoms_s", "thirsty")
-         .add(id, "3", "diseases_s", "stroke", "symptoms_s", "confusion")
-         .add(id, "4", "diseases_s", "bronchus", "symptoms_s", "nausea")
-         .add(id, "5", "diseases_s", "bronchus", "symptoms_s", "cough")
-         .add(id, "6", "diseases_s", "bronchus", "symptoms_s", "cough")
-         .add(id, "7", "diseases_s", "heart attack", "symptoms_s", "indigestion")
-         .add(id, "8", "diseases_s", "diabetes", "symptoms_s", "urination")
-         .add(id, "9", "diseases_s", "diabetes", "symptoms_s", "thirsty")
-         .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+        .add(id, "0", "diseases_s", "stroke", "symptoms_s", "confusion")
+        .add(id, "1", "diseases_s", "cancer", "symptoms_s", "indigestion")
+        .add(id, "2", "diseases_s", "diabetes", "symptoms_s", "thirsty")
+        .add(id, "3", "diseases_s", "stroke", "symptoms_s", "confusion")
+        .add(id, "4", "diseases_s", "bronchus", "symptoms_s", "nausea")
+        .add(id, "5", "diseases_s", "bronchus", "symptoms_s", "cough")
+        .add(id, "6", "diseases_s", "bronchus", "symptoms_s", "cough")
+        .add(id, "7", "diseases_s", "heart attack", "symptoms_s", "indigestion")
+        .add(id, "8", "diseases_s", "diabetes", "symptoms_s", "urination")
+        .add(id, "9", "diseases_s", "diabetes", "symptoms_s", "thirsty")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
     StreamExpression expression;
     TupleStream stream;
     List<Tuple> tuples;
@@ -864,10 +864,11 @@ public class StreamExpressionTest extends SolrCloudTestCase {
     expression = StreamExpressionParser.parse("facet2D(collection1, q=\"*:*\", x=\"diseases_s\",
y=\"symptoms_s\", dimensions=\"3,1\", count(*))");
     stream = factory.constructStream(expression);
     tuples = getTuples(stream);
+    for(Tuple tuple : tuples) {
+      System.out.println("####### Tuple:"+tuple.fields);
+    }
 
-
-    System.out.println(tuples.size() + " HHHHHHHHFHFHFHHFH");
-    assert(false==false);
+    assert (tuples.size() > 0);
   }
 
 


Mime
View raw message