diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-04-14 13:52:07 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2023-04-14 13:52:07 +0200 |
commit | 057fa96d6776e275efbb4c5ed0d758277985338a (patch) | |
tree | 8a40aeae1a30655144dea9b43c99c8222ed72973 /indexinglanguage | |
parent | a2d73b3942d48015a0e52fe1163e5e0c27aa2316 (diff) |
Resolve parent before children
Diffstat (limited to 'indexinglanguage')
3 files changed, 27 insertions, 2 deletions
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceExpression.java index 86826770828..5dbb9292a9d 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceExpression.java @@ -50,9 +50,9 @@ public class ChoiceExpression extends ExpressionList<Expression> { @Override protected void doVerify(VerificationContext context) { DataType input = context.getValueType(); + context.setValueType(input); for (Expression exp : this) context.setValueType(input).execute(exp); - context.setValueType(input); } private static DataType resolveInputType(Collection<? extends Expression> list) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java index c667a0019c2..fb1338b8b65 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java @@ -11,7 +11,7 @@ import java.util.Map; */ public class VerificationContext implements FieldTypeAdapter, Cloneable { - private final Map<String, DataType> variables = new HashMap<String, DataType>(); + private final Map<String, DataType> variables = new HashMap<>(); private final FieldTypeAdapter adapter; private DataType value; private String outputField; diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java index 7ece841e9b7..e6d5c550e93 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java @@ -2,7 +2,9 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; +import com.yahoo.document.Document; import com.yahoo.document.Field; +import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.language.Linguistics; import com.yahoo.language.process.Embedder; @@ -44,6 +46,7 @@ public class ChoiceTestCase { var adapter = new SimpleTestAdapter(new Field("foo", DataType.STRING), new Field("bar", DataType.STRING)); adapter.setValue("foo", new StringFieldValue("foo1")); adapter.setValue("bar", new StringFieldValue("bar1")); + choice.verify(adapter); ExecutionContext context = new ExecutionContext(adapter); choice.execute(context); assertEquals("foo1", context.getValue().getWrappedValue()); @@ -51,6 +54,28 @@ public class ChoiceTestCase { } @Test + public void testChoiceWithConstant() throws ParseException { + var choice = parse("input timestamp || 99999999L | attribute timestamp"); + + { // value is set + var adapter = new SimpleTestAdapter(new Field("timestamp", DataType.LONG)); + choice.verify(adapter); + adapter.setValue("timestamp", new LongFieldValue(34)); + ExecutionContext context = new ExecutionContext(adapter); + choice.execute(context); + assertEquals(34L, context.getValue().getWrappedValue()); + } + + { // fallback to default + var adapter = new SimpleTestAdapter(new Field("timestamp", DataType.LONG)); + choice.verify(adapter); + ExecutionContext context = new ExecutionContext(adapter); + choice.execute(context); + assertEquals(99999999L, context.getValue().getWrappedValue()); + } + } + + @Test public void testIllegalChoiceExpression() throws ParseException { try { parse("input (foo || 99999999) | attribute"); |