Apache Lucene open-source search software
SOLR-12660: Refine output form and register stream function
Joel Bernsteina2bbeec27c0d
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.javaindex c6485bb73bd..c9e132619a9 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java@@ -249,6 +249,7 @@ public class Lang {.withFunctionName("knnRegress", KnnRegressionEvaluator.class).withFunctionName("gaussfit", GaussFitEvaluator.class).withFunctionName("outliers", OutliersEvaluator.class)+ .withFunctionName("stream", GetStream.class)// Boolean Stream Evaluatorsdiff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/OutliersEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/OutliersEvaluator.javaindex 85d298f2e18..5a14a52428f 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/OutliersEvaluator.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/OutliersEvaluator.java@@ -93,16 +93,14 @@ public class OutliersEvaluator extends RecursiveObjectEvaluator implements ManyVdouble cumProb = d.cumulativeProbability(n.intValue());if(low >= 0 && cumProb <= low) {- t.put("lowOutlier", true);- t.put("lowOutlierValue", n);- t.put("cumulativeProbablity", cumProb);+ t.put("lowOutlierValue_d", n);+ t.put("cumulativeProbablity_d", cumProb);outliers.add(t);}if(hi >= 0 && cumProb >= hi) {- t.put("highOutlier", true);- t.put("highOutlierValue", n);- t.put("cumulativeProbablity", cumProb);+ t.put("highOutlierValue_d", n);+ t.put("cumulativeProbablity_d", cumProb);outliers.add(t);}}@@ -119,17 +117,15 @@ public class OutliersEvaluator extends RecursiveObjectEvaluator implements ManyVdouble cumProb = d.cumulativeProbability(n.doubleValue());if(low >= 0 && cumProb <= low) {- t.put("lowOutlier", true);- t.put("lowOutlierValue", n);- t.put("cumulativeProbablity", cumProb);+ t.put("lowOutlierValue_d", n);+ t.put("cumulativeProbablity_d", cumProb);outliers.add(t);}if(hi >= 0 && cumProb >= hi) {- t.put("highOutlier", true);- t.put("highOutlierValue", n);- t.put("cumulativeProbablity", cumProb);+ t.put("highOutlierValue_d", n);+ t.put("cumulativeProbablity_d", cumProb);outliers.add(t);}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.javaindex c615bcb4f19..3abd196188a 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java@@ -70,7 +70,7 @@ public class TestLang extends LuceneTestCase {"mod", "ceil", "floor", "sin", "asin", "sinh", "cos", "acos", "cosh", "tan", "atan", "tanh", "round", "sqrt","cbrt", "coalesce", "uuid", "if", "convert", "valueAt", "memset", "fft", "ifft", "euclidean","manhattan","earthMovers", "canberra", "chebyshev", "ones", "zeros", "setValue", "getValue", "knnRegress", "gaussfit",- "outliers"};+ "outliers", "stream"};@Testpublic void testLang() {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.javaindex be510504e7d..bfd4160d2f5 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@@ -3296,32 +3296,28 @@ public class MathExpressionTest extends SolrCloudTestCase {Map high = out.get(0);assertEquals(((String)high.get("id")), "1");- assertEquals(((Number)high.get("cumulativeProbablity")).doubleValue(), 0.9772498680518208, 0.0 );- assertEquals(((Number)high.get("highOutlierValue")).doubleValue(), 110.0, 0.0);- assertEquals(((Boolean)high.get("highOutlier")).booleanValue(), true);+ assertEquals(((Number)high.get("cumulativeProbablity_d")).doubleValue(), 0.9772498680518208, 0.0 );+ assertEquals(((Number)high.get("highOutlierValue_d")).doubleValue(), 110.0, 0.0);Map low = out.get(1);assertEquals(((String)low.get("id")), "2");- assertEquals(((Number)low.get("cumulativeProbablity")).doubleValue(), 0.022750131948179167, 0.0 );- assertEquals(((Number)low.get("lowOutlierValue")).doubleValue(), 90, 0.0);- assertEquals(((Boolean)low.get("lowOutlier")).booleanValue(), true);+ assertEquals(((Number)low.get("cumulativeProbablity_d")).doubleValue(), 0.022750131948179167, 0.0 );+ assertEquals(((Number)low.get("lowOutlierValue_d")).doubleValue(), 90, 0.0);List<Map> out1 = (List<Map>)tuples.get(0).get("f");assertEquals(out1.size(), 2);Map high1 = out1.get(0);assert(high1.get("id") == null);- assertEquals(((Number)high1.get("cumulativeProbablity")).doubleValue(), 0.9772498680518208, 0.0 );- assertEquals(((Number)high1.get("highOutlierValue")).doubleValue(), 110.0, 0.0);- assertEquals(((Boolean)high1.get("highOutlier")).booleanValue(), true);+ assertEquals(((Number)high1.get("cumulativeProbablity_d")).doubleValue(), 0.9772498680518208, 0.0 );+ assertEquals(((Number)high1.get("highOutlierValue_d")).doubleValue(), 110.0, 0.0);Map low1 = out1.get(1);assert(low1.get("id") == null);- assertEquals(((Number)low1.get("cumulativeProbablity")).doubleValue(), 0.022750131948179167, 0.0 );- assertEquals(((Number)low1.get("lowOutlierValue")).doubleValue(), 90, 0.0);- assertEquals(((Boolean)low1.get("lowOutlier")).booleanValue(), true);+ assertEquals(((Number)low1.get("cumulativeProbablity_d")).doubleValue(), 0.022750131948179167, 0.0 );+ assertEquals(((Number)low1.get("lowOutlierValue_d")).doubleValue(), 90, 0.0);}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.javaindex be919ebd0bd..ba050ffe729 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java@@ -3488,6 +3488,31 @@ public class StreamDecoratorTest extends SolrCloudTestCase {assertTrue(tuples.size() == 0);+ }++ @Test+ public void testStream() throws Exception {+ UpdateRequest updateRequest = new UpdateRequest();+ updateRequest.add(id, "hello", "test_t", "l b c d c e", "test_i", "5");+ updateRequest.add(id, "hello1", "test_t", "l b c d c", "test_i", "4");++ updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);++ String expr = "search("+COLLECTIONORALIAS+", q=\"id:hello1\", fl=\"id,test_t, test_i\", sort=\"id desc\")";+ String cat = "let(a ="+expr+",stream(a))";+ ModifiableSolrParams paramsLoc = new ModifiableSolrParams();+ paramsLoc.set("expr", cat);+ 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);+ assertTrue(tuples.size() == 1);++}@Test