summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-08-09 21:21:32 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2019-08-09 21:21:32 +0200
commitf35ed89b5dcac4edaafb05c44353bf6c160efd6b (patch)
tree3a5afb2aeba03d49f7bb1b00eb5ca9d22eab6fdd /document
parent247c57f87631a684fa72f410a8c896900c01e303 (diff)
ArithmeticNode must propagate Result.INVALID.
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java3
-rw-r--r--document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java24
-rw-r--r--document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java1
3 files changed, 27 insertions, 1 deletions
diff --git a/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java b/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java
index c39bd7e668d..c8c4103ec5c 100644
--- a/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java
+++ b/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java
@@ -6,6 +6,7 @@ import com.yahoo.document.datatypes.NumericFieldValue;
import com.yahoo.document.select.BucketSet;
import com.yahoo.document.select.Context;
import com.yahoo.document.select.OrderingSpecification;
+import com.yahoo.document.select.Result;
import com.yahoo.document.select.Visitor;
import java.util.List;
@@ -88,6 +89,8 @@ public class ArithmeticNode implements ExpressionNode {
}
buf.push(new ValueItem(item.operator, (Number)val));
continue;
+ } else if (val == Result.INVALID) {
+ return val;
}
throw new IllegalStateException("Term '" + item.node + " with class " + val.getClass() + "' does not evaluate to a number.");
}
diff --git a/document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java b/document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java
new file mode 100644
index 00000000000..20b0e2034cc
--- /dev/null
+++ b/document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java
@@ -0,0 +1,24 @@
+package com.yahoo.document.select;
+
+import com.yahoo.document.select.rule.ArithmeticNode;
+import com.yahoo.document.select.rule.LiteralNode;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ArithmeticNodeTestCase {
+
+ private void verify(Object expect, String operator, Object arg2) {
+ assertEquals(expect,
+ new ArithmeticNode().add(null, new LiteralNode(10)).add(operator, new LiteralNode(arg2)).evaluate(new Context(null)));
+ assertEquals(Result.INVALID,
+ new ArithmeticNode().add(null, new LiteralNode(10)).add(operator, new LiteralNode(Result.INVALID)).evaluate(new Context(null)));
+ }
+ @Test
+ public void testThatInvalidPropagates() {
+ verify(12.0, "+", 2);
+ verify(8.0, "-", 2);
+ verify(30.0, "*", 3);
+ verify(5.0, "/", 2);
+ }
+}
diff --git a/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java
index 25aca22b108..e1e2bb276b3 100644
--- a/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java
+++ b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java
@@ -11,7 +11,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
public class LogicalNodeTestCase {
private static class TracedNode implements ExpressionNode {