From f35ed89b5dcac4edaafb05c44353bf6c160efd6b Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 9 Aug 2019 21:21:32 +0200 Subject: ArithmeticNode must propagate Result.INVALID. --- .../yahoo/document/select/rule/ArithmeticNode.java | 3 +++ .../document/select/ArithmeticNodeTestCase.java | 24 ++++++++++++++++++++++ .../yahoo/document/select/LogicalNodeTestCase.java | 1 - 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java (limited to 'document') 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 { -- cgit v1.2.3