You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2019/06/19 02:40:56 UTC

[lucene-solr] branch branch_8x updated (61292c9 -> d82fe01)

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

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


    from 61292c9  syntax error
     new ecd702b  SOLR-13560: Add isNull and notNull Stream Evaluators
     new d82fe01  SOLR-13560: Fix precommit

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/solr/client/solrj/io/Lang.java |  2 +
 .../client/solrj/io/eval/FieldValueEvaluator.java  |  6 ++
 .../{MatrixEvaluator.java => IsNullEvaluator.java} | 34 +++++-----
 ...oalesceEvaluator.java => NotNullEvaluator.java} | 32 +++++----
 .../solr/client/solrj/io/stream/HavingStream.java  |  1 +
 .../org/apache/solr/client/solrj/io/TestLang.java  |  2 +-
 .../client/solrj/io/stream/MathExpressionTest.java | 75 ++++++++++++++++++++++
 7 files changed, 123 insertions(+), 29 deletions(-)
 copy solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/{MatrixEvaluator.java => IsNullEvaluator.java} (61%)
 copy solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/{CoalesceEvaluator.java => NotNullEvaluator.java} (61%)


[lucene-solr] 01/02: SOLR-13560: Add isNull and notNull Stream Evaluators

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ecd702bf4a00fcc2215c815b81d7080724e2ee78
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Tue Jun 18 22:09:13 2019 -0400

    SOLR-13560: Add isNull and notNull Stream Evaluators
---
 .../java/org/apache/solr/client/solrj/io/Lang.java |  2 +
 .../client/solrj/io/eval/FieldValueEvaluator.java  |  9 +++
 .../solr/client/solrj/io/eval/IsNullEvaluator.java | 54 ++++++++++++++++
 .../client/solrj/io/eval/NotNullEvaluator.java     | 54 ++++++++++++++++
 .../solr/client/solrj/io/stream/HavingStream.java  |  1 +
 .../org/apache/solr/client/solrj/io/TestLang.java  |  2 +-
 .../client/solrj/io/stream/MathExpressionTest.java | 75 ++++++++++++++++++++++
 7 files changed, 196 insertions(+), 1 deletion(-)

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.java
index 4a1051e..52b8875 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
@@ -287,6 +287,8 @@ public class Lang {
         .withFunctionName("natural", NaturalEvaluator.class)
         .withFunctionName("movingMAD", MovingMADEvaluator.class)
         .withFunctionName("recNum", RecNumEvaluator.class)
+        .withFunctionName("notNull", NotNullEvaluator.class)
+        .withFunctionName("isNull", IsNullEvaluator.class)
 
         // Boolean Stream Evaluators
 
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java
index 3086fb4..809a284 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java
@@ -19,8 +19,12 @@ package org.apache.solr.client.solrj.io.eval;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.stream.StreamContext;
 import org.apache.solr.client.solrj.io.stream.expr.Explanation;
 import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType;
 import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
@@ -84,7 +88,12 @@ public class FieldValueEvaluator extends SourceEvaluator {
       }
     }
 
+    StreamContext sc = getStreamContext();
+
+    if(sc != null) {sc.getTupleContext().remove("null");}
+
     if(value == null) {
+      if(sc != null) {sc.getTupleContext().put("null", fieldName);}
       return fieldName;
     }
 
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/IsNullEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/IsNullEvaluator.java
new file mode 100644
index 0000000..dc912fd
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/IsNullEvaluator.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.eval;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Locale;
+
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+
+public class IsNullEvaluator extends RecursiveBooleanEvaluator implements ManyValueWorker {
+  protected static final long serialVersionUID = 1L;
+
+  public IsNullEvaluator(StreamExpression expression, StreamFactory factory) throws IOException{
+    super(expression, factory);
+
+    if(containedEvaluators.size() != 1){
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting one parameter but found %d",expression,containedEvaluators.size()));
+    }
+  }
+
+  public Object doWork(Object ... values) throws IOException {
+
+    if(values[0] instanceof String) {
+      //Check to see if the this tuple had a null value for that string.
+      Map tupleContext = getStreamContext().getTupleContext();
+      String nullField = (String)tupleContext.get("null");
+      if(nullField != null && nullField.equals(values[0])) {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
+  protected Checker constructChecker(Object value) throws IOException {
+    return null;
+  }
+}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/NotNullEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/NotNullEvaluator.java
new file mode 100644
index 0000000..8b9a9b1
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/NotNullEvaluator.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.eval;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Locale;
+
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+
+public class NotNullEvaluator extends RecursiveBooleanEvaluator implements ManyValueWorker {
+  protected static final long serialVersionUID = 1L;
+
+  public NotNullEvaluator(StreamExpression expression, StreamFactory factory) throws IOException{
+    super(expression, factory);
+
+    if(containedEvaluators.size() != 1){
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - expecting one parameter but found %d",expression,containedEvaluators.size()));
+    }
+  }
+
+  public Object doWork(Object ... values) throws IOException {
+
+    if(values[0] instanceof String) {
+      //Check to see if the this tuple had a null value for that string.
+      Map tupleContext = getStreamContext().getTupleContext();
+      String nullField = (String)tupleContext.get("null");
+      if(nullField != null && nullField.equals(values[0])) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  protected Checker constructChecker(Object value) throws IOException {
+    return null;
+  }
+}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/HavingStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/HavingStream.java
index eeb2935..bf56484 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/HavingStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/HavingStream.java
@@ -132,6 +132,7 @@ public class HavingStream extends TupleStream implements Expressible {
   public void setStreamContext(StreamContext context) {
     this.streamContext = context;
     this.stream.setStreamContext(context);
+    this.evaluator.setStreamContext(context);
   }
 
   public List<TupleStream> children() {
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.java
index b7db83d..a2ad7de 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
@@ -75,7 +75,7 @@ public class TestLang extends SolrTestCase {
       "convexHull", "getVertices", "getBaryCenter", "getArea", "getBoundarySize","oscillate",
       "getAmplitude", "getPhase", "getAngularFrequency", "enclosingDisk", "getCenter", "getRadius",
       "getSupportPoints", "pairSort", "log10", "plist", "recip", "pivot", "ltrim", "rtrim", "export",
-      "zplot", "natural", "repeat", "movingMAD", "hashRollup", "noop", "var", "stddev", "recNum"};
+      "zplot", "natural", "repeat", "movingMAD", "hashRollup", "noop", "var", "stddev", "recNum", "isNull", "notNull"};
 
   @Test
   public 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.java
index c14e126..8c8718c 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
@@ -1997,6 +1997,81 @@ public class MathExpressionTest extends SolrCloudTestCase {
 
   }
 
+
+  @Test
+  public void testNotNullHaving() throws Exception {
+    String cexpr = "having(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), notNull(b))";
+    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 tuple0 = tuples.get(0);
+    assertEquals(tuple0.getLong("b").longValue(), 3L);
+  }
+
+  @Test
+  public void testIsNullHaving() throws Exception {
+    String cexpr = "having(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), isNull(b))";
+    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 tuple0 = tuples.get(0);
+    assertEquals(tuple0.getLong("a").longValue(), 2L);
+  }
+
+
+  @Test
+  public void testNotNullSelect() throws Exception {
+    String cexpr = "select(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), if(notNull(a),a, 0) as out)";
+    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("out").longValue(), 2L);
+
+    Tuple tuple1 = tuples.get(1);
+    assertEquals(tuple1.getLong("out").longValue(), 0L);
+
+  }
+
+
+  @Test
+  public void testIsNullSelect() throws Exception {
+    String cexpr = "select(list(tuple(a=add(1, 1)), tuple(b=add(1, 2))), if(isNull(a), 0, a) as out)";
+    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("out").longValue(), 2L);
+
+    Tuple tuple1 = tuples.get(1);
+    assertEquals(tuple1.getLong("out").longValue(), 0L);
+
+  }
+
   @Test
   public void testLetWithNumericVariables() throws Exception {
     String cexpr = "let(echo=true, a=1.88888, b=8888888888.98)";


[lucene-solr] 02/02: SOLR-13560: Fix precommit

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d82fe011bfeaf67fdff9e363b80b1489c2da369f
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Tue Jun 18 22:26:27 2019 -0400

    SOLR-13560: Fix precommit
---
 .../java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java
index 809a284..1587a43 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/FieldValueEvaluator.java
@@ -19,9 +19,6 @@ package org.apache.solr.client.solrj.io.eval;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
 
 import org.apache.solr.client.solrj.io.Tuple;
 import org.apache.solr.client.solrj.io.stream.StreamContext;