lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctarg...@apache.org
Subject [13/50] [abbrv] lucene-solr:jira/solr-12746: SOLR-12851: Improvements and fixes to let and select Streaming Expressions
Date Mon, 22 Oct 2018 23:34:58 GMT
SOLR-12851: Improvements and fixes to let and select Streaming Expressions


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/935547f2
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/935547f2
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/935547f2

Branch: refs/heads/jira/solr-12746
Commit: 935547f2fa788d1137692b3a2a2808cbc9fa9131
Parents: ef1338a
Author: Joel Bernstein <jbernste@apache.org>
Authored: Thu Oct 11 10:43:30 2018 -0400
Committer: Cassandra Targett <ctargett@apache.org>
Committed: Sun Oct 21 15:46:46 2018 -0500

----------------------------------------------------------------------
 .../solr/client/solrj/io/stream/LetStream.java  | 11 +++++-
 .../client/solrj/io/stream/SelectStream.java    | 11 ++++--
 .../solrj/io/stream/expr/StreamFactory.java     |  5 +--
 .../solrj/io/stream/MathExpressionTest.java     | 41 +++++++++++++++++++-
 4 files changed, 58 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/935547f2/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/LetStream.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/LetStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/LetStream.java
index e88eaf6..23881c3 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/LetStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/LetStream.java
@@ -36,6 +36,7 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExplanation;
 import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
 import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter;
 import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue;
 import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
 
 /**
@@ -76,7 +77,11 @@ public class LetStream extends TupleStream implements Expressible {
       }
 
       StreamExpressionParameter param = ((StreamExpressionNamedParameter)np).getParameter();
-      if(factory.isEvaluator((StreamExpression)param)) {
+
+      if(param instanceof StreamExpressionValue) {
+        String paramValue = ((StreamExpressionValue) param).getValue();
+        letParams.put(name, factory.constructPrimitiveObject(paramValue));
+      } else if(factory.isEvaluator((StreamExpression)param)) {
         StreamEvaluator evaluator = factory.constructEvaluator((StreamExpression) param);
         letParams.put(name, evaluator);
       } else {
@@ -182,7 +187,7 @@ public class LetStream extends TupleStream implements Expressible {
         } finally {
           tStream.close();
         }
-      } else {
+      } else if(o instanceof StreamEvaluator) {
         //Add the data from the StreamContext to a tuple.
         //Let the evaluator works from this tuple.
         //This will allow columns to be created from tuples already in the StreamContext.
@@ -196,6 +201,8 @@ public class LetStream extends TupleStream implements Expressible {
         } else {
           lets.put(name, eo);
         }
+      } else {
+        lets.put(name, o);
       }
     }
     stream.open();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/935547f2/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SelectStream.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SelectStream.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SelectStream.java
index d6664cd..d87a637 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SelectStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SelectStream.java
@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.io.stream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -63,14 +64,14 @@ public class SelectStream extends TupleStream implements Expressible {
       this.selectedFields.put(selectedField, selectedField);
     }
     operations = new ArrayList<>();
-    selectedEvaluators = new HashMap<>();
+    selectedEvaluators = new LinkedHashMap();
   }
   
   public SelectStream(TupleStream stream, Map<String,String> selectedFields) throws
IOException {
     this.stream = stream;
     this.selectedFields = selectedFields;
     operations = new ArrayList<>();
-    selectedEvaluators = new HashMap<>();
+    selectedEvaluators = new LinkedHashMap();
   }
   
   public SelectStream(StreamExpression expression,StreamFactory factory) throws IOException
{
@@ -100,7 +101,7 @@ public class SelectStream extends TupleStream implements Expressible {
     stream = factory.constructStream(streamExpressions.get(0));
     
     selectedFields = new HashMap<String,String>();
-    selectedEvaluators = new HashMap<StreamEvaluator, String>();
+    selectedEvaluators = new LinkedHashMap();
     for(StreamExpressionParameter parameter : selectAsFieldsExpressions){
       StreamExpressionValue selectField = (StreamExpressionValue)parameter;
       String value = selectField.getValue().trim();
@@ -281,7 +282,9 @@ public class SelectStream extends TupleStream implements Expressible {
     
     // Apply all evaluators
     for(Map.Entry<StreamEvaluator, String> selectedEvaluator : selectedEvaluators.entrySet())
{
-      workingToReturn.put(selectedEvaluator.getValue(), selectedEvaluator.getKey().evaluate(workingForEvaluators));
+      Object o = selectedEvaluator.getKey().evaluate(workingForEvaluators);
+      workingForEvaluators.put(selectedEvaluator.getValue(), o);
+      workingToReturn.put(selectedEvaluator.getValue(), o);
     }
     
     return workingToReturn;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/935547f2/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
index 321545b..0ba5d5c 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamFactory.java
@@ -439,9 +439,8 @@ public class StreamFactory implements Serializable {
     if("null".equals(lower)){ return null; }
     if("true".equals(lower) || "false".equals(lower)){ return Boolean.parseBoolean(lower);
}
     try{ return Long.valueOf(original); } catch(Exception ignored){};
-    try{ if (original.matches(".{1,8}")){ return Double.valueOf(original); }} catch(Exception
ignored){};
-    try{ if (original.matches(".{1,17}")){ return Double.valueOf(original); }} catch(Exception
ignored){};
-    
+    try{ return Double.valueOf(original); } catch(Exception ignored){};
+
     // is a string
     return original;
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/935547f2/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
index a095dd8..45633e3 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
@@ -1169,7 +1169,6 @@ public class MathExpressionTest extends SolrCloudTestCase {
     List<Tuple> tuples = getTuples(solrStream);
     assertTrue(tuples.size() == 1);
     List<List<Number>> out = (List<List<Number>>)tuples.get(0).get("c");
-    System.out.println("###### out:"+out);
     assertEquals(out.size(), 2);
     List<Number> row1 = out.get(0);
     assertEquals(row1.get(0).doubleValue(), 2.1, 0);
@@ -1722,6 +1721,46 @@ public class MathExpressionTest extends SolrCloudTestCase {
   }
 
   @Test
+  public void testSelectWithSequentialEvaluators() throws Exception {
+    String cexpr = "select(list(tuple(a=add(1,2)), tuple(a=add(2,2))), " +
+        "                  add(1, a) as blah, " +
+        "                  add(1, blah) as blah1)";
+    ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
+    paramsLoc.set("expr", cexpr);
+    paramsLoc.set("qt", "/stream");
+    String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
+    TupleStream solrStream = new SolrStream(url, paramsLoc);
+    StreamContext context = new StreamContext();
+    solrStream.setStreamContext(context);
+    List<Tuple> tuples = getTuples(solrStream);
+    assertEquals(tuples.size(), 2);
+    Tuple tuple0 = tuples.get(0);
+    assertEquals(tuple0.getLong("blah").longValue(), 4L);
+    assertEquals(tuple0.getLong("blah1").longValue(), 5L);
+
+    Tuple tuple1 = tuples.get(1);
+    assertEquals(tuple1.getLong("blah").longValue(), 5L);
+    assertEquals(tuple1.getLong("blah1").longValue(), 6L);
+  }
+
+  @Test
+  public void testLetWithNumericVariables() throws Exception {
+    String cexpr = "let(echo=true, a=1.88888, b=8888888888.98)";
+    ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
+    paramsLoc.set("expr", cexpr);
+    paramsLoc.set("qt", "/stream");
+    String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
+    TupleStream solrStream = new SolrStream(url, paramsLoc);
+    StreamContext context = new StreamContext();
+    solrStream.setStreamContext(context);
+    List<Tuple> tuples = getTuples(solrStream);
+    assertEquals(tuples.size(), 1);
+    Tuple tuple = tuples.get(0);
+    assertEquals(tuple.getDouble("a").doubleValue(), 1.88888, 0.0);
+    assertEquals(tuple.getDouble("b").doubleValue(), 8888888888.98, 0.0);
+  }
+
+  @Test
   public void testTermVectors() throws Exception {
     // Test termVectors with only documents and default termVector settings
     String cexpr = "let(echo=true," +


Mime
View raw message