From cf890ebdfc09b74a2b36a66a19ac2ac2a68481ec Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 11 Nov 2024 09:37:38 +0100 Subject: [PATCH 1/8] Remove construction-time type checking WIP --- .../schema/processing/IndexingInputs.java | 2 +- .../expressions/ClearStateExpression.java | 3 ++ .../expressions/ConstantExpression.java | 3 ++ .../expressions/Expression.java | 31 +++++++-------- .../expressions/GetVarExpression.java | 3 ++ .../expressions/HostNameExpression.java | 3 ++ .../expressions/InputExpression.java | 3 ++ .../expressions/LiteralBoolExpression.java | 3 ++ .../expressions/NowExpression.java | 3 ++ .../expressions/RandomExpression.java | 3 ++ .../expressions/ScriptExpression.java | 1 + .../indexinglanguage/ScriptTestCase.java | 32 +++++++++++++-- .../expressions/ArithmeticTestCase.java | 28 ++++--------- .../expressions/CatTestCase.java | 2 +- .../expressions/ExpressionTestCase.java | 11 ------ .../expressions/IfThenTestCase.java | 15 +++++-- .../expressions/SimpleExpression.java | 39 ++++++++++++------- .../expressions/SimpleExpressionTestCase.java | 3 -- .../expressions/StatementTestCase.java | 15 ------- .../resolvers/IndexingLanguageResolver.java | 9 ++--- 20 files changed, 120 insertions(+), 92 deletions(-) diff --git a/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java b/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java index a5ba67d69769..b29f76393fca 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java @@ -75,7 +75,7 @@ protected boolean shouldConvert(Expression exp) { @Override protected Expression doConvert(Expression exp) { - if (exp.requiredInputType() != null) { + if (exp.requiresInput()) { return new StatementExpression(new InputExpression(field.getName()), exp); } else { return exp; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java index 48b69525df52..5c41ee3058c1 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java @@ -12,6 +12,9 @@ public ClearStateExpression() { super(null); } + @Override + public boolean requiresInput() { return false; } + @Override protected void doVerify(VerificationContext context) { context.clear(); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java index d7af8669b3a4..ea45fead1eab 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java @@ -21,6 +21,9 @@ public ConstantExpression(FieldValue value) { this.value = Objects.requireNonNull(value); } + @Override + public boolean requiresInput() { return false; } + public FieldValue getValue() { return value; } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java index c1c2b5fc68fd..e315016545c6 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java @@ -18,7 +18,14 @@ import java.util.Map; /** + * Superclass of expressions. + * + * Rules: + * - All expressions produce an output. + * - Expressions that does not require an input overrides requiresInput() to return false + * * @author Simon Thoresen Hult + * @author bratseth */ public abstract class Expression extends Selectable { @@ -39,6 +46,9 @@ protected Expression(DataType requiredInputType) { this.requiredInputType = requiredInputType; } + /** Returns whether this expression requires an input value. */ + public boolean requiresInput() { return true; } + /** * Returns an expression where the children of this has been converted using the given converter. * This default implementation returns this as it has no children. @@ -64,7 +74,7 @@ public void setStatementOutput(DocumentType documentType, Field field) {} * @throws IllegalArgumentException if inputType isn't assignable to requiredType */ protected final DataType setInputType(DataType inputType, DataType requiredType, VerificationContext context) { - if ( ! (inputType.isAssignableTo(requiredType))) + if ( requiredType != null && ! (inputType.isAssignableTo(requiredType))) throw new VerificationException(this, "This requires type " + requiredType.getName() + ", but gets " + inputType.getName()); return assignInputType(inputType); } @@ -200,33 +210,22 @@ public final DataType verify(FieldTypeAdapter adapter) { } public final DataType verify(VerificationContext context) { + //if (requiresInput() && context.getCurrentType() == null) (My try, but since scriptexpression bafflingly requires input ... + // throw new VerificationException(this, "Missing an input"); if (requiredInputType != null) { DataType input = context.getCurrentType(); if (input == null) { throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, but no input is specified"); } - if (input.getPrimitiveType() == UnresolvedDataType.INSTANCE) { + if (input != null && input.getPrimitiveType() == UnresolvedDataType.INSTANCE) { throw new VerificationException(this, "Failed to resolve input type"); } - if (!requiredInputType.isAssignableFrom(input)) { + if (input != null && !requiredInputType.isAssignableFrom(input)) { throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, got " + input.getName()); } } doVerify(context); - DataType outputType = createdOutputType(); - if (outputType != null) { - DataType output = context.getCurrentType(); - if (output == null) { - throw new VerificationException(this, "Expected " + outputType.getName() + " output, but no output is specified"); - } - if (output.getPrimitiveType() == UnresolvedDataType.INSTANCE) { - throw new VerificationException(this, "Failed to resolve output type"); - } - if (!outputType.isAssignableFrom(output)) { - throw new VerificationException(this, "Expected " + outputType.getName() + " output, got " + output.getName()); - } - } return context.getCurrentType(); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java index 2c0ca758601f..01f9fa13f17c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java @@ -15,6 +15,9 @@ public GetVarExpression(String variableName) { this.variableName = variableName; } + @Override + public boolean requiresInput() { return false; } + public String getVariableName() { return variableName; } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java index 7cd4241fdb4b..98ca6249a46e 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java @@ -14,6 +14,9 @@ public HostNameExpression() { super(null); } + @Override + public boolean requiresInput() { return false; } + @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java index bfadc5d174b0..e39b3a0f30b5 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java @@ -25,6 +25,9 @@ public InputExpression(String fieldName) { this.fieldName = fieldName; } + @Override + public boolean requiresInput() { return false; } + public String getFieldName() { return fieldName; } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java index c33241152edb..3c89c8fa352b 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java @@ -19,6 +19,9 @@ public LiteralBoolExpression(boolean value) { this.value = value; } + @Override + public boolean requiresInput() { return false; } + @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java index c01dedee426e..40bd820e8ef0 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java @@ -20,6 +20,9 @@ public NowExpression(Timer timer) { this.timer = timer; } + @Override + public boolean requiresInput() { return false; } + public Timer getTimer() { return timer; } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java index 08d4e0823746..565495e66665 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java @@ -23,6 +23,9 @@ public RandomExpression(Integer max) { this.max = max; } + @Override + public boolean requiresInput() { return false; } + public Integer getMaxValue() { return max; } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java index 1c4e097b1f8a..e41515c7d77d 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java @@ -45,6 +45,7 @@ public ScriptExpression convertChildren(ExpressionConverter converter) { @Override public DataType setInputType(DataType inputType, VerificationContext context) { + System.out.println("Scripts input type " + inputType); super.setInputType(inputType, context); DataType currentOutput = null; for (var expression : expressions()) diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java index c9b9e0c01fb3..40516270de0d 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -52,7 +52,7 @@ public void requireThatScriptExecutesStatements() { } @Test - public void requireThatEachStatementHasEmptyInput() { + public void failsWhenOneStatementIsMissingInput() { Document input = new Document(type, "id:scheme:mytype::"); input.setFieldValue(input.getField("in-1"), new StringFieldValue("69")); @@ -61,13 +61,39 @@ public void requireThatEachStatementHasEmptyInput() { new StatementExpression(new AttributeExpression("out-2"))); try { exp.verify(input); - fail(); + fail("Expected exception"); } catch (VerificationException e) { assertEquals(e.getExpressionType(), ScriptExpression.class); - assertEquals("Invalid expression '{ input in-1 | attribute out-1; attribute out-2; }': Expected any input, but no input is specified", e.getMessage()); + assertEquals("Invalid expression '{ input in-1 | attribute out-1; attribute out-2; }': Missing an input", e.getMessage()); } } + @Test + public void failsWhenAllStatementIsMissingInput() { + Document input = new Document(type, "id:scheme:mytype::"); + input.setFieldValue(input.getField("in-1"), new StringFieldValue("69")); + + Expression exp = new ScriptExpression( + new StatementExpression(new AttributeExpression("out-2"))); + try { + exp.verify(input); + fail("Expected exception"); + } catch (VerificationException e) { + assertEquals(e.getExpressionType(), ScriptExpression.class); + assertEquals("Invalid expression '{ attribute out-2; }': Missing an input", e.getMessage()); + } + } + + @Test + public void succeedsWhenAllStatementsHaveInput() { + Document input = new Document(type, "id:scheme:mytype::"); + input.setFieldValue(input.getField("in-1"), new StringFieldValue("69")); + + Expression exp = new ScriptExpression( + new StatementExpression(new InputExpression("in-1"), new AttributeExpression("out-1"))); + exp.verify(input); + } + @Test public void requireThatFactoryMethodWorks() throws ParseException { Document input = new Document(type, "id:scheme:mytype::"); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java index 54f888b42e80..e1f8d7c16b07 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java @@ -63,15 +63,6 @@ public void requireThatConstructorDoesNotAcceptNull() { public void requireThatVerifyCallsAreForwarded() { assertVerify(SimpleExpression.newOutput(DataType.INT), Operator.ADD, SimpleExpression.newOutput(DataType.INT), null); - assertVerifyThrows(SimpleExpression.newOutput(null), Operator.ADD, - SimpleExpression.newOutput(DataType.INT), null, - "Expected any output, but no output is specified"); - assertVerifyThrows(SimpleExpression.newOutput(DataType.INT), Operator.ADD, - SimpleExpression.newOutput(null), null, - "Expected any output, but no output is specified"); - assertVerifyThrows(SimpleExpression.newOutput(null), Operator.ADD, - SimpleExpression.newOutput(null), null, - "Expected any output, but no output is specified"); assertVerifyThrows(SimpleExpression.newOutput(DataType.INT), Operator.ADD, SimpleExpression.newOutput(DataType.STRING), null, "The second argument must be a number, but has type string"); @@ -80,16 +71,6 @@ public void requireThatVerifyCallsAreForwarded() { "The first argument must be a number, but has type string"); } - @Test - public void requireThatOperandInputCanBeNull() { - SimpleExpression reqNull = new SimpleExpression(); - SimpleExpression reqInt = new SimpleExpression(DataType.INT); - assertNull(newArithmetic(reqNull, Operator.ADD, reqNull).requiredInputType()); - assertEquals(DataType.INT, newArithmetic(reqInt, Operator.ADD, reqNull).requiredInputType()); - assertEquals(DataType.INT, newArithmetic(reqInt, Operator.ADD, reqInt).requiredInputType()); - assertEquals(DataType.INT, newArithmetic(reqNull, Operator.ADD, reqInt).requiredInputType()); - } - @Test public void requireThatOperandsAreInputCompatible() { assertVerify(new SimpleExpression(DataType.INT), Operator.ADD, @@ -183,7 +164,14 @@ private static ArithmeticExpression newArithmetic(FieldValue lhs, Operator op, F } private static ArithmeticExpression newArithmetic(Expression lhs, Operator op, Expression rhs) { - return new ArithmeticExpression(lhs, op, rhs); + return newArithmetic(lhs, op, rhs, null); + } + + private static ArithmeticExpression newArithmetic(Expression lhs, Operator op, Expression rhs, VerificationContext context) { + var expression = new ArithmeticExpression(lhs, op, rhs); + if (context != null) + expression.verify(context); + return expression; } private static ConstantExpression newLong(long val) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java index 4de31753695b..8cc2d4daa72d 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java @@ -57,7 +57,7 @@ public void requireThatExpressionCanBeVerified() { "Invalid expression of type 'CatExpression': Operands require conflicting input types, string vs int"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), null, - "Invalid expression 'SimpleExpression . SimpleExpression': Expected string input, but no input is specified"); + "Invalid expression 'SimpleExpression . SimpleExpression': In SimpleExpression: Attempting to concatenate a null value"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), DataType.INT, "Invalid expression 'SimpleExpression . SimpleExpression': Expected string input, got int"); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java index 9bc54e26645b..6c1ffab9e73f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java @@ -41,17 +41,6 @@ public void requireThatInputTypeIsCheckedBeforeVerify() { "Invalid expression 'SimpleExpression': Expected int input, got string"); } - @Test - public void requireThatOutputTypeIsCheckedAfterVerify() { - assertVerify(newCreatedOutput(DataType.INT, DataType.INT), null); - assertVerifyThrows(newCreatedOutput(DataType.INT, (DataType)null), null, - "Invalid expression 'SimpleExpression': Expected int output, but no output is specified"); - assertVerifyThrows(newCreatedOutput(DataType.INT, UnresolvedDataType.INSTANCE), null, - "Invalid expression 'SimpleExpression': Failed to resolve output type"); - assertVerifyThrows(newCreatedOutput(DataType.INT, DataType.STRING), null, - "Invalid expression 'SimpleExpression': Expected int output, got string"); - } - @Test public void requireThatEqualsMethodWorks() { assertTrue(Expression.equals(null, null)); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java index 14e1fdbe268f..c1d298a438de 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java @@ -239,17 +239,24 @@ public void requireThatNullLeftOrRightHandSideEvaluatesToNull() { @Test public void testRequiredInputType() { - var ifExpression = new IfThenExpression(new InputExpression("field1"), + var ifExpression = new IfThenExpression(new InputExpression("int1"), Comparator.EQ, new ConstantExpression(new IntegerFieldValue(0)), wrapLikeTheParser(new ConstantExpression(new StringFieldValue("true"))), wrapLikeTheParser(new ConstantExpression(new StringFieldValue("false")))); - assertNull(ifExpression.requiredInputType()); + + SimpleTestAdapter adapter = new SimpleTestAdapter(); + adapter.createField(new Field("int1", DataType.INT)); + adapter.createField(new Field("string1", DataType.STRING)); + + ifExpression.verify(adapter); + assertNull(ifExpression.getInputType(new VerificationContext(adapter))); assertEquals(DataType.STRING, ifExpression.createdOutputType()); var expression = new ScriptExpression(new StatementExpression(ifExpression, - new AttributeExpression(null))); - assertNull(expression.requiredInputType()); + new AttributeExpression("string1"))); + expression.verify(adapter); + assertNull(expression.getInputType(new VerificationContext(adapter))); } private Expression wrapLikeTheParser(Expression expression) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java index 182823ee51de..dc06b08b4893 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java @@ -13,19 +13,15 @@ final class SimpleExpression extends Expression { private boolean hasVerifyValue = false; private FieldValue executeValue; private DataType verifyValue; + private final DataType requiredInput; private DataType createdOutput; public SimpleExpression() { - super(null); + this(null); } public SimpleExpression(DataType requiredInput) { super(requiredInput); - } - - public SimpleExpression setExecuteValue(FieldValue executeValue) { - this.hasExecuteValue = true; - this.executeValue = executeValue; - return this; + this.requiredInput = requiredInput; } public SimpleExpression setVerifyValue(DataType verifyValue) { @@ -34,16 +30,27 @@ public SimpleExpression setVerifyValue(DataType verifyValue) { return this; } + public SimpleExpression setExecuteValue(FieldValue executeValue) { + this.hasExecuteValue = true; + this.executeValue = executeValue; + return this; + } + public SimpleExpression setCreatedOutput(DataType createdOutput) { this.createdOutput = createdOutput; return this; } @Override - protected void doExecute(ExecutionContext context) { - if (hasExecuteValue) { - context.setCurrentValue(executeValue); - } + public DataType setInputType(DataType inputType, VerificationContext context) { + super.setInputType(inputType, requiredInput, context); + return createdOutput; + } + + @Override + public DataType setOutputType(DataType outputType, VerificationContext context) { + super.setOutputType(createdOutput, outputType, null, context); + return requiredInput; } @Override @@ -53,6 +60,13 @@ protected void doVerify(VerificationContext context) { } } + @Override + protected void doExecute(ExecutionContext context) { + if (hasExecuteValue) { + context.setCurrentValue(executeValue); + } + } + @Override public DataType createdOutputType() { return createdOutput; @@ -60,7 +74,7 @@ public DataType createdOutputType() { @Override public int hashCode() { - return hashCode(executeValue) + hashCode(verifyValue) + hashCode(requiredInputType()) + hashCode(createdOutput); + return hashCode(executeValue) + hashCode(verifyValue) + hashCode(createdOutput); } @Override @@ -70,7 +84,6 @@ public boolean equals(Object o) { if (!equals(executeValue, other.executeValue)) return false; if (hasVerifyValue != other.hasVerifyValue) return false; if (!equals(verifyValue, other.verifyValue)) return false; - if (!equals(requiredInputType(), other.requiredInputType())) return false; if (!equals(createdOutput, other.createdOutput)) return false; return true; } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java index 20f85cfa863d..81858130a17c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java @@ -15,12 +15,10 @@ public class SimpleExpressionTestCase { @Test public void requireThatAccessorsWork() { SimpleExpression exp = new SimpleExpression(); - assertNull(exp.requiredInputType()); assertNull(exp.createdOutputType()); assertNull(exp.execute()); assertNull(exp.verify()); - assertEquals(DataType.INT, new SimpleExpression(DataType.INT).requiredInputType()); assertEquals(DataType.INT, new SimpleExpression().setCreatedOutput(DataType.INT).createdOutputType()); assertEquals(DataType.INT, new SimpleExpression().setVerifyValue(DataType.INT).verify()); assertEquals(new IntegerFieldValue(69), @@ -51,7 +49,6 @@ public void requireThatHashCodeAndEqualsAreImplemented() { assertEquals(exp, new SimpleExpression().setVerifyValue(DataType.INT)); exp = new SimpleExpression(DataType.INT); - assertFalse(exp.equals(new SimpleExpression(DataType.STRING))); assertEquals(exp, new SimpleExpression(DataType.INT)); exp = new SimpleExpression().setCreatedOutput(DataType.INT); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java index 8dea0126d566..236d541bbd31 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java @@ -64,21 +64,6 @@ public void requireThatStatementIsFlattened() { assertEquals(newStatement(foo, bar), newStatement(newStatement(foo, bar))); } - @Test - public void requireThatRequiredInputIsDeterminedByFirstNonNullRequiredInput() { - assertEquals(DataType.INT, newStatement(SimpleExpression.newRequired(DataType.INT)).requiredInputType()); - assertEquals(DataType.INT, newStatement(new SimpleExpression(), - SimpleExpression.newRequired(DataType.INT)).requiredInputType()); - assertEquals(DataType.INT, newStatement(SimpleExpression.newRequired(DataType.INT), - SimpleExpression.newRequired(DataType.INT)).requiredInputType()); - } - - @Test - public void requireThatRequiredInputIsNullIfAnyOutputIsCreatedFirst() { - assertNull(newStatement(new SimpleExpression().setCreatedOutput(DataType.INT), - new SimpleExpression(DataType.INT)).requiredInputType()); - } - @Test public void requireThatCreatedOutputIsDeterminedByLastNonNullCreatedOutput() { assertEquals(DataType.STRING, newStatement(SimpleExpression.newOutput(DataType.STRING)).createdOutputType()); diff --git a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/IndexingLanguageResolver.java b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/IndexingLanguageResolver.java index 4b60a9a91fe7..2e38909ec467 100644 --- a/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/IndexingLanguageResolver.java +++ b/integration/schema-language-server/language-server/src/main/java/ai/vespa/schemals/schemadocument/resolvers/IndexingLanguageResolver.java @@ -58,12 +58,11 @@ public static void resolveIndexingLanguage(ParseContext context, SchemaNode inde if (indexingLanguageNode.isASTInstance(indexingElm.class)) { var expression = ((indexingElm)indexingLanguageNode.getOriginalSchemaNode()).expression; - if (expression != null && expression.requiredInputType() != null && !context.fieldIndex().getIsInsideDoc(fieldDefinitionSymbol)) { + if (expression != null && expression.requiresInput() && !context.fieldIndex().getIsInsideDoc(fieldDefinitionSymbol)) { diagnostics.add(new SchemaDiagnostic.Builder() .setRange(indexingLanguageNode.get(0).getRange()) .setMessage( - "Expected " + expression.requiredInputType().getName() + " input, but no input is specified. " + - "Fields defined outside the document must start with indexing statements explicitly collecting input.") + "Fields defined outside the document must start with an expression creating a value (e.g 'input ')") .setSeverity(DiagnosticSeverity.Error) .build()); } @@ -127,10 +126,10 @@ private void traverse(SchemaNode node, List diagnostics) { statement originalNode = (statement)node.getOriginalIndexingNode(); StatementExpression expression = originalNode.expression; - if (expression != null && expression.requiredInputType() != null && !context.fieldIndex().getIsInsideDoc(containingFieldDefinition)) { + if (expression != null && expression.requiresInput() && !context.fieldIndex().getIsInsideDoc(containingFieldDefinition)) { diagnostics.add(new SchemaDiagnostic.Builder() .setRange(node.getRange()) - .setMessage("Expected " + expression.requiredInputType().getName() + " input, but no input is specified. Fields defined outside the document must start with indexing statements explicitly collecting input.") + .setMessage("Fields defined outside the document must start with an expression creating a value (e.g 'input ')") .setSeverity(DiagnosticSeverity.Error) .build()); } From a1a404d70e0e7d4ba8644b0c903029e517cff5e7 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 28 Nov 2024 20:39:41 +0100 Subject: [PATCH 2/8] Expect type checking, not execution errors --- .../expressions/ScriptExpression.java | 1 - .../indexinglanguage/ScriptTestCase.java | 20 +++++++++++++------ .../expressions/CatTestCase.java | 16 +++++++++++---- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java index e41515c7d77d..1c4e097b1f8a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java @@ -45,7 +45,6 @@ public ScriptExpression convertChildren(ExpressionConverter converter) { @Override public DataType setInputType(DataType inputType, VerificationContext context) { - System.out.println("Scripts input type " + inputType); super.setInputType(inputType, context); DataType currentOutput = null; for (var expression : expressions()) diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java index 40516270de0d..2abf8e52553a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -11,14 +11,22 @@ import com.yahoo.document.datatypes.FloatFieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.LongFieldValue; -import com.yahoo.document.datatypes.MapFieldValue; import com.yahoo.document.datatypes.StringFieldValue; -import com.yahoo.document.datatypes.Struct; -import com.yahoo.vespa.indexinglanguage.expressions.*; +import com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression; +import com.yahoo.vespa.indexinglanguage.expressions.ExecutionContext; +import com.yahoo.vespa.indexinglanguage.expressions.Expression; +import com.yahoo.vespa.indexinglanguage.expressions.InputExpression; +import com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression; +import com.yahoo.vespa.indexinglanguage.expressions.StatementExpression; +import com.yahoo.vespa.indexinglanguage.expressions.VerificationContext; +import com.yahoo.vespa.indexinglanguage.expressions.VerificationException; import com.yahoo.vespa.indexinglanguage.parser.ParseException; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -64,7 +72,7 @@ public void failsWhenOneStatementIsMissingInput() { fail("Expected exception"); } catch (VerificationException e) { assertEquals(e.getExpressionType(), ScriptExpression.class); - assertEquals("Invalid expression '{ input in-1 | attribute out-1; attribute out-2; }': Missing an input", e.getMessage()); + assertEquals("Invalid expression '{ input in-1 | attribute out-1; attribute out-2; }': Expected any input, but no input is specified", e.getMessage()); } } @@ -80,7 +88,7 @@ public void failsWhenAllStatementIsMissingInput() { fail("Expected exception"); } catch (VerificationException e) { assertEquals(e.getExpressionType(), ScriptExpression.class); - assertEquals("Invalid expression '{ attribute out-2; }': Missing an input", e.getMessage()); + assertEquals("Invalid expression '{ attribute out-2; }': Expected any input, but no input is specified", e.getMessage()); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java index 8cc2d4daa72d..b16fa63a12b1 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java @@ -3,14 +3,22 @@ import com.yahoo.document.DataType; import com.yahoo.document.Field; -import com.yahoo.document.datatypes.*; +import com.yahoo.document.datatypes.Array; +import com.yahoo.document.datatypes.FieldValue; +import com.yahoo.document.datatypes.IntegerFieldValue; +import com.yahoo.document.datatypes.StringFieldValue; +import com.yahoo.document.datatypes.WeightedSet; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; - import java.util.List; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -57,7 +65,7 @@ public void requireThatExpressionCanBeVerified() { "Invalid expression of type 'CatExpression': Operands require conflicting input types, string vs int"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), null, - "Invalid expression 'SimpleExpression . SimpleExpression': In SimpleExpression: Attempting to concatenate a null value"); + "Invalid expression 'SimpleExpression . SimpleExpression': Expected string input, but no input is specified"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), DataType.INT, "Invalid expression 'SimpleExpression . SimpleExpression': Expected string input, got int"); From 644c565bf0c5b77c1a74b5983a614db372b1c7fd Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 28 Nov 2024 23:07:54 +0100 Subject: [PATCH 3/8] Use requiredInputType less --- .../expressions/ArithmeticExpression.java | 11 +++++- .../expressions/CatExpression.java | 11 ++++-- .../expressions/Expression.java | 17 ++++++--- .../expressions/ExpressionList.java | 3 ++ .../expressions/GuardExpression.java | 37 ++++++++++--------- .../expressions/IfThenExpression.java | 5 +++ .../expressions/ParenthesisExpression.java | 35 ++++++++++-------- .../expressions/SelectInputExpression.java | 3 ++ .../indexinglanguage/ScriptTestCase.java | 5 +-- .../expressions/Base64DecodeTestCase.java | 2 +- .../expressions/Base64EncodeTestCase.java | 2 +- .../expressions/CatTestCase.java | 4 +- .../expressions/EchoTestCase.java | 2 +- .../expressions/ExactTestCase.java | 2 +- .../expressions/ExpressionTestCase.java | 2 +- .../expressions/FlattenTestCase.java | 2 +- .../expressions/ForEachTestCase.java | 2 +- .../expressions/GetFieldTestCase.java | 2 +- .../expressions/GuardTestCase.java | 2 +- .../expressions/HexDecodeTestCase.java | 2 +- .../expressions/HexEncodeTestCase.java | 2 +- .../expressions/IfThenTestCase.java | 4 +- .../expressions/JoinTestCase.java | 2 +- .../expressions/LowerCaseTestCase.java | 2 +- .../expressions/NGramTestCase.java | 2 +- .../expressions/NormalizeTestCase.java | 2 +- .../OptimizePredicateTestCase.java | 2 +- .../expressions/OutputAssert.java | 6 ++- .../expressions/ParenthesisTestCase.java | 2 +- .../expressions/ScriptTestCase.java | 2 +- .../expressions/SetLanguageTestCase.java | 2 +- .../expressions/SetVarTestCase.java | 2 +- .../expressions/SimpleExpression.java | 3 ++ .../expressions/SplitTestCase.java | 2 +- .../expressions/SubstringTestCase.java | 2 +- .../expressions/SwitchTestCase.java | 2 +- .../expressions/ThisTestCase.java | 2 +- .../expressions/ToArrayTestCase.java | 2 +- .../expressions/ToBoolTestCase.java | 2 +- .../expressions/ToByteTestCase.java | 2 +- .../expressions/ToDoubleTestCase.java | 2 +- .../ToEpochSecondExpressionTestCase.java | 2 +- .../expressions/ToFloatTestCase.java | 2 +- .../expressions/ToIntegerTestCase.java | 2 +- .../expressions/ToLongTestCase.java | 2 +- .../expressions/ToPositionTestCase.java | 2 +- .../expressions/ToStringTestCase.java | 2 +- .../expressions/ToWsetTestCase.java | 2 +- .../expressions/TokenizeTestCase.java | 2 +- .../expressions/TrimTestCase.java | 2 +- .../expressions/ZCurveTestCase.java | 2 +- 51 files changed, 130 insertions(+), 90 deletions(-) diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java index dd7ccd360937..738566eb885e 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java @@ -3,7 +3,13 @@ import com.yahoo.document.DataType; import com.yahoo.document.NumericDataType; -import com.yahoo.document.datatypes.*; +import com.yahoo.document.datatypes.ByteFieldValue; +import com.yahoo.document.datatypes.DoubleFieldValue; +import com.yahoo.document.datatypes.FieldValue; +import com.yahoo.document.datatypes.FloatFieldValue; +import com.yahoo.document.datatypes.IntegerFieldValue; +import com.yahoo.document.datatypes.LongFieldValue; +import com.yahoo.document.datatypes.NumericFieldValue; import com.yahoo.vespa.indexinglanguage.ExpressionConverter; import com.yahoo.vespa.objects.ObjectOperation; import com.yahoo.vespa.objects.ObjectPredicate; @@ -54,6 +60,9 @@ public ArithmeticExpression(Expression left, Operator op, Expression right) { this.right = Objects.requireNonNull(right); } + @Override + public boolean requiresInput() { return false; } + public Expression getLeftHandSide() { return left; } public Operator getOperator() { return op; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java index b8df92b9c1b6..1a58c3f7c437 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java @@ -4,7 +4,6 @@ import com.yahoo.document.ArrayDataType; import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; -import com.yahoo.document.TensorDataType; import com.yahoo.document.WeightedSetDataType; import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.FieldValue; @@ -12,13 +11,16 @@ import com.yahoo.document.datatypes.WeightedSet; import com.yahoo.vespa.indexinglanguage.ExpressionConverter; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; /** * @author Simon Thoresen Hult */ -// TODO: Support Map in addition to Array and Wighted Set (doc just says "collection type") +// TODO: Support Map in addition to Array and Weghted Set (doc just says "collection type") public final class CatExpression extends ExpressionList { public CatExpression(Expression... expressions) { @@ -29,6 +31,9 @@ public CatExpression(Collection expressions) { super(expressions, resolveInputType(expressions)); } + @Override + public boolean requiresInput() { return false; } + @Override public CatExpression convertChildren(ExpressionConverter converter) { return new CatExpression(convertChildList(converter)); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java index e315016545c6..30be368c533f 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java @@ -10,7 +10,14 @@ import com.yahoo.language.Linguistics; import com.yahoo.language.process.Embedder; import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.vespa.indexinglanguage.*; +import com.yahoo.vespa.indexinglanguage.AdapterFactory; +import com.yahoo.vespa.indexinglanguage.DocumentAdapter; +import com.yahoo.vespa.indexinglanguage.DocumentTypeAdapter; +import com.yahoo.vespa.indexinglanguage.ExpressionConverter; +import com.yahoo.vespa.indexinglanguage.ScriptParser; +import com.yahoo.vespa.indexinglanguage.ScriptParserContext; +import com.yahoo.vespa.indexinglanguage.SimpleAdapterFactory; +import com.yahoo.vespa.indexinglanguage.UpdateAdapter; import com.yahoo.vespa.indexinglanguage.parser.IndexingInput; import com.yahoo.vespa.indexinglanguage.parser.ParseException; import com.yahoo.vespa.objects.Selectable; @@ -210,17 +217,15 @@ public final DataType verify(FieldTypeAdapter adapter) { } public final DataType verify(VerificationContext context) { - //if (requiresInput() && context.getCurrentType() == null) (My try, but since scriptexpression bafflingly requires input ... - // throw new VerificationException(this, "Missing an input"); - if (requiredInputType != null) { + if (requiresInput()) { DataType input = context.getCurrentType(); if (input == null) { - throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, but no input is specified"); + throw new VerificationException(this, "Expected input, but no input is specified"); } if (input != null && input.getPrimitiveType() == UnresolvedDataType.INSTANCE) { throw new VerificationException(this, "Failed to resolve input type"); } - if (input != null && !requiredInputType.isAssignableFrom(input)) { + if (input != null && requiredInputType != null && !requiredInputType.isAssignableFrom(input)) { throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, got " + input.getName()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java index a31e09e59e1e..929d53177b6c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java @@ -28,6 +28,9 @@ protected ExpressionList(Iterable expressions, DataType inputType) } } + @Override + public boolean requiresInput() { return !expressions.isEmpty() && expressions.get(0).requiresInput(); } + public List expressions() { return expressions; } protected List convertChildList(ExpressionConverter converter) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java index 58037e3927d5..50a1b4cb9bd7 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java @@ -15,37 +15,40 @@ */ public final class GuardExpression extends CompositeExpression { - private final Expression expression; + private final Expression innerExpression; private final boolean shouldExecute; - public GuardExpression(Expression expression) { - super(expression.requiredInputType()); - this.expression = expression; - shouldExecute = shouldExecute(expression); + public GuardExpression(Expression innerExpression) { + super(innerExpression.requiredInputType()); + this.innerExpression = innerExpression; + shouldExecute = shouldExecute(innerExpression); } - public Expression getInnerExpression() { return expression; } + @Override + public boolean requiresInput() { return innerExpression.requiresInput(); } + + public Expression getInnerExpression() { return innerExpression; } @Override public GuardExpression convertChildren(ExpressionConverter converter) { - return new GuardExpression(converter.convert(expression)); + return new GuardExpression(converter.convert(innerExpression)); } @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); - return expression.setInputType(inputType, context); + return innerExpression.setInputType(inputType, context); } @Override public DataType setOutputType(DataType outputType, VerificationContext context) { super.setOutputType(outputType, context); - return expression.setOutputType(outputType, context); + return innerExpression.setOutputType(outputType, context); } @Override protected void doVerify(VerificationContext context) { - expression.verify(context); + innerExpression.verify(context); } @Override @@ -53,40 +56,40 @@ protected void doExecute(ExecutionContext context) { if (!shouldExecute && context.getFieldValue() instanceof UpdateAdapter) { context.setCurrentValue(null); } else { - expression.execute(context); + innerExpression.execute(context); } } @Override public void setStatementOutput(DocumentType documentType, Field field) { - expression.setStatementOutput(documentType, field); + innerExpression.setStatementOutput(documentType, field); } @Override public DataType createdOutputType() { - return expression.createdOutputType(); + return innerExpression.createdOutputType(); } @Override public String toString() { - return "guard " + toScriptBlock(expression); + return "guard " + toScriptBlock(innerExpression); } @Override public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) { - select(expression, predicate, operation); + select(innerExpression, predicate, operation); } @Override public boolean equals(Object obj) { if (!(obj instanceof GuardExpression rhs)) return false; - if (!expression.equals(rhs.expression)) return false; + if (!innerExpression.equals(rhs.innerExpression)) return false; return true; } @Override public int hashCode() { - return getClass().hashCode() + expression.hashCode(); + return getClass().hashCode() + innerExpression.hashCode(); } private static boolean shouldExecute(Expression exp) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java index 75754b51fb79..c9d37a4002fc 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java @@ -57,6 +57,11 @@ public IfThenExpression(Expression lhs, Comparator cmp, Expression right, Expres this.ifFalse = ifFalse; } + @Override + public boolean requiresInput() { + return left.requiresInput() || right.requiresInput() || ifFalse.requiresInput() || ifFalse.requiresInput(); + } + @Override public IfThenExpression convertChildren(ExpressionConverter converter) { return new IfThenExpression(converter.branch().convert(left), diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java index 1c24ecf02369..9ec94ad939b9 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java @@ -13,72 +13,75 @@ */ public class ParenthesisExpression extends CompositeExpression { - private final Expression innerExp; + private final Expression innerExpression; - public ParenthesisExpression(Expression innerExp) { - super(innerExp.requiredInputType()); - this.innerExp = innerExp; + public ParenthesisExpression(Expression innerExpression) { + super(innerExpression.requiredInputType()); + this.innerExpression = innerExpression; } - public Expression getInnerExpression() { return innerExp; } + @Override + public boolean requiresInput() { return innerExpression.requiresInput(); } + + public Expression getInnerExpression() { return innerExpression; } @Override public ParenthesisExpression convertChildren(ExpressionConverter converter) { - return new ParenthesisExpression(converter.convert(innerExp)); + return new ParenthesisExpression(converter.convert(innerExpression)); } @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); - return innerExp.setInputType(inputType, context); + return innerExpression.setInputType(inputType, context); } @Override public DataType setOutputType(DataType outputType, VerificationContext context) { super.setOutputType(outputType, context); - return innerExp.setInputType(outputType, context); + return innerExpression.setInputType(outputType, context); } @Override public void setStatementOutput(DocumentType documentType, Field field) { - innerExp.setStatementOutput(documentType, field); + innerExpression.setStatementOutput(documentType, field); } @Override protected void doVerify(VerificationContext context) { - innerExp.verify(context); + innerExpression.verify(context); } @Override protected void doExecute(ExecutionContext context) { - innerExp.execute(context); + innerExpression.execute(context); } @Override public DataType createdOutputType() { - return innerExp.createdOutputType(); + return innerExpression.createdOutputType(); } @Override public String toString() { - return "(" + innerExp + ")"; + return "(" + innerExpression + ")"; } @Override public boolean equals(Object obj) { if (!(obj instanceof ParenthesisExpression rhs)) return false; - if (!innerExp.equals(rhs.innerExp)) return false; + if (!innerExpression.equals(rhs.innerExpression)) return false; return true; } @Override public int hashCode() { - return getClass().hashCode() + innerExp.hashCode(); + return getClass().hashCode() + innerExpression.hashCode(); } @Override public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) { - select(innerExp, predicate, operation); + select(innerExpression, predicate, operation); } } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java index 3239be6daa35..4c2e568baa6e 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java @@ -31,6 +31,9 @@ public SelectInputExpression(List> cases) { this.cases = cases; } + @Override + public boolean requiresInput() { return false; } + @Override public SelectInputExpression convertChildren(ExpressionConverter converter) { return new SelectInputExpression(cases.stream() diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java index 2abf8e52553a..0e605d64d946 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -71,8 +71,7 @@ public void failsWhenOneStatementIsMissingInput() { exp.verify(input); fail("Expected exception"); } catch (VerificationException e) { - assertEquals(e.getExpressionType(), ScriptExpression.class); - assertEquals("Invalid expression '{ input in-1 | attribute out-1; attribute out-2; }': Expected any input, but no input is specified", e.getMessage()); + assertEquals("Invalid expression 'attribute out-2': Expected input, but no input is specified", e.getMessage()); } } @@ -88,7 +87,7 @@ public void failsWhenAllStatementIsMissingInput() { fail("Expected exception"); } catch (VerificationException e) { assertEquals(e.getExpressionType(), ScriptExpression.class); - assertEquals("Invalid expression '{ attribute out-2; }': Expected any input, but no input is specified", e.getMessage()); + assertEquals("Invalid expression '{ attribute out-2; }': Expected input, but no input is specified", e.getMessage()); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java index 01eed5fdc8bf..d05b30cc35cb 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java @@ -66,7 +66,7 @@ public void requireThatIllegalInputThrows() { public void requireThatExpressionCanBeVerified() { Expression exp = new Base64DecodeExpression(); assertVerify(DataType.STRING, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'base64decode': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'base64decode': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'base64decode': Expected string input, got long", DataType.LONG, exp); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java index 4cc017113b85..093dc3420d1f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java @@ -40,7 +40,7 @@ public void requireThatInputIsEncoded() { public void requireThatExpressionCanBeVerified() { Expression exp = new Base64EncodeExpression(); assertVerify(DataType.LONG, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'base64encode': Expected long input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'base64encode': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'base64encode': Expected long input, got string", DataType.STRING, exp); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java index b16fa63a12b1..9edb7c4071f4 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java @@ -65,10 +65,10 @@ public void requireThatExpressionCanBeVerified() { "Invalid expression of type 'CatExpression': Operands require conflicting input types, string vs int"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), null, - "Invalid expression 'SimpleExpression . SimpleExpression': Expected string input, but no input is specified"); + "Invalid expression 'SimpleExpression': Expected input, but no input is specified"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), DataType.INT, - "Invalid expression 'SimpleExpression . SimpleExpression': Expected string input, got int"); + "Invalid expression 'SimpleExpression': Expected string input, got int"); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java index 4d197527ec11..781493392576 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java @@ -53,6 +53,6 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new EchoExpression(); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'echo': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'echo': Expected input, but no input is specified", null, exp); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java index 7a861a8e5904..3befaa9f0a66 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java @@ -84,7 +84,7 @@ public void requireThatEmptyStringsAreNotAnnotated() { public void requireThatExpressionCanBeVerified() { Expression exp = new ExactExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'exact': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'exact': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'exact': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java index 6c1ffab9e73f..168919065403 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java @@ -34,7 +34,7 @@ public void requireThatOutputTypeIsCheckedAfterExecute() { public void requireThatInputTypeIsCheckedBeforeVerify() { assertVerify(newRequiredInput(DataType.INT), DataType.INT); assertVerifyThrows(newRequiredInput(DataType.INT), null, - "Invalid expression 'SimpleExpression': Expected int input, but no input is specified"); + "Invalid expression 'SimpleExpression': Expected input, but no input is specified"); assertVerifyThrows(newRequiredInput(DataType.INT), UnresolvedDataType.INSTANCE, "Invalid expression 'SimpleExpression': Failed to resolve input type"); assertVerifyThrows(newRequiredInput(DataType.INT), DataType.STRING, diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java index 5f0cc0818140..9373dd3b52ed 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java @@ -87,7 +87,7 @@ public void requireThatAnnotationsWithoutFieldValueUseOriginalSpan() { public void requireThatExpressionCanBeVerified() { Expression exp = new FlattenExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'flatten': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'flatten': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'flatten': Expected string input, got int", DataType.INT, exp); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java index e5f5a737b9dd..c7566b5a573a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java @@ -53,7 +53,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ForEachExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)); assertVerify(DataType.getArray(DataType.INT), exp, DataType.getArray(DataType.STRING)); - assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Expected Array, Struct, WeightedSet or Map input, got int", DataType.INT, exp); assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.getArray(DataType.STRING), exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java index a95fa7646220..e1366d4b7b90 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java @@ -38,7 +38,7 @@ public void requireThatExpressionCanBeVerified() { type.addField(new Field("foo", DataType.STRING)); Expression exp = new GetFieldExpression("foo"); assertVerify(type, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'get_field foo': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'get_field foo': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'get_field foo': Expected a struct or map, but got an int", DataType.INT, exp); assertVerifyThrows("Invalid expression 'get_field bar': Field 'bar' not found in struct type 'my_struct'", type, new GetFieldExpression("bar")); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java index 19f0ef96a489..188c9990963a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java @@ -46,7 +46,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new GuardExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)); assertVerify(DataType.INT, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'guard { SimpleExpression; }': Expected int input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'guard { SimpleExpression; }': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'guard { SimpleExpression; }': Expected int input, got string", DataType.STRING, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java index 3d90e49722a0..b692e6e8085d 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java @@ -29,7 +29,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new HexDecodeExpression(); assertVerify(DataType.STRING, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'hexdecode': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'hexdecode': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'hexdecode': Expected string input, got long", DataType.LONG, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java index 416d5cff37a7..1c6d01513876 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java @@ -29,7 +29,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new HexEncodeExpression(); assertVerify(DataType.LONG, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'hexencode': Expected long input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'hexencode': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'hexencode': Expected long input, got string", DataType.STRING, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java index c1d298a438de..0331c1397a6e 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java @@ -42,7 +42,7 @@ public void requireThatRequiredInputTypeCompatibilityIsVerified() { DataType.STRING, DataType.STRING); assertVerify(DataType.STRING, exp, DataType.STRING); String prefix = "Invalid expression 'if (SimpleExpression == SimpleExpression) { SimpleExpression; } else { SimpleExpression; }': "; - assertVerifyThrows(prefix + "Expected string input, but no input is specified", null, exp); + assertVerifyThrows(prefix + "Expected input, but no input is specified", null, exp); assertVerifyThrows(prefix + "Expected string input, got int", DataType.INT, exp); assertVerifyThrows("Invalid expression of type 'IfThenExpression': Operands require conflicting input types, int vs string", null, () -> newRequiredInput(DataType.INT, Comparator.EQ, DataType.STRING, DataType.STRING, DataType.STRING) @@ -61,7 +61,7 @@ public void requireThatRequiredInputTypeCompatibilityIsVerified() { @Test public void requireThatExpressionCanBeVerified() { assertVerify(DataType.STRING, new FlattenExpression(), DataType.STRING); - assertVerifyThrows("Invalid expression 'flatten': Expected string input, but no input is specified", null, new FlattenExpression() + assertVerifyThrows("Invalid expression 'flatten': Expected input, but no input is specified", null, new FlattenExpression() ); assertVerifyThrows("Invalid expression 'flatten': Expected string input, got int", DataType.INT, new FlattenExpression() ); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java index d2ca020d05ae..2d1aa7d4897a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java @@ -36,7 +36,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new JoinExpression(";"); assertVerify(DataType.getArray(DataType.INT), exp, DataType.STRING); assertVerify(DataType.getArray(DataType.STRING), exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'join \";\"': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'join \";\"': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'join \";\"': Expected Array input, got type int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java index b3ed2f5a5a31..267efa32996f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java @@ -28,7 +28,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new LowerCaseExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'lowercase': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'lowercase': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'lowercase': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java index d5db120b6356..ee4cefeed9c9 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java @@ -46,7 +46,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new NGramExpression(new SimpleLinguistics(), 69); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'ngram 69': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'ngram 69': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'ngram 69': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java index f89b838464bb..bfd8e9b0855a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java @@ -43,7 +43,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new NormalizeExpression(new SimpleLinguistics()); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'normalize': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'normalize': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'normalize': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java index 040308f52b48..09902d9257b4 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java @@ -77,7 +77,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new OptimizePredicateExpression(); String prefix = "Invalid expression 'optimize_predicate': "; - assertVerifyThrows(prefix + "Expected predicate input, but no input is specified", null, exp); + assertVerifyThrows(prefix + "Expected input, but no input is specified", null, exp); assertVerifyThrows(prefix + "Expected predicate input, got int", DataType.INT, exp); assertVerifyThrows(prefix + "Variable 'arity' must be set", DataType.PREDICATE, exp); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java index a4b19163dcd8..2fd3a1def29c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java @@ -7,7 +7,9 @@ import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -27,7 +29,7 @@ public static void assertExecute(OutputExpression exp) { public static void assertVerify(OutputExpression exp) { assertVerify(new MyAdapter(null), DataType.INT, exp); assertVerify(new MyAdapter(null), DataType.STRING, exp); - assertVerifyThrows(new MyAdapter(null), null, exp, "Invalid expression '" + exp + "': Expected any input, but no input is specified"); + assertVerifyThrows(new MyAdapter(null), null, exp, "Invalid expression '" + exp + "': Expected input, but no input is specified"); assertVerifyThrows(new MyAdapter(new VerificationException((Expression) null, "foo")), DataType.INT, exp, "Invalid expression 'null': foo"); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java index 6c997356bbfd..ac6bb63ab879 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java @@ -37,7 +37,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ParenthesisExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)); assertVerify(DataType.INT, exp, DataType.STRING); - assertVerifyThrows("Invalid expression '(SimpleExpression)': Expected int input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression '(SimpleExpression)': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression '(SimpleExpression)': Expected int input, got string", DataType.STRING, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java index 41f910a9ccb1..098e4171d9c8 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java @@ -65,7 +65,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = newScript(newStatement(SimpleExpression.newConversion(DataType.INT, DataType.STRING))); assertVerify(DataType.INT, exp, DataType.STRING); - assertVerifyThrows("Invalid expression '{ SimpleExpression; }': Expected int input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression '{ SimpleExpression; }': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression '{ SimpleExpression; }': Expected int input, got string", DataType.STRING, exp); assertVerifyThrows("Invalid expression of type 'ScriptExpression': Statements require conflicting input types, int vs string", null, () -> newScript(newStatement(SimpleExpression.newConversion(DataType.INT, DataType.STRING)), diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java index 5878f89e463b..09bad7582302 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java @@ -29,7 +29,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new SetLanguageExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'set_language': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'set_language': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'set_language': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java index 261ecd797d3a..9fe94509aa63 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java @@ -36,7 +36,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new SetVarExpression("foo"); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'set_var foo': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'set_var foo': Expected input, but no input is specified", null, exp); try { new VerificationContext().setVariable("foo", DataType.INT).setCurrentType(DataType.STRING).verify(exp); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java index dc06b08b4893..1cea04acca3b 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java @@ -24,6 +24,9 @@ public SimpleExpression(DataType requiredInput) { this.requiredInput = requiredInput; } + @Override + public boolean requiresInput() { return requiredInput != null; } + public SimpleExpression setVerifyValue(DataType verifyValue) { this.hasVerifyValue = true; this.verifyValue = verifyValue; diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java index 79dd93985488..b914ed7d77c4 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java @@ -37,7 +37,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new SplitExpression(";"); assertVerify(DataType.STRING, exp, DataType.getArray(DataType.STRING)); - assertVerifyThrows("Invalid expression 'split \";\"': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'split \";\"': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'split \";\"': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java index 2c3a2ee4df88..93c3c61e264a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java @@ -37,7 +37,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new SubstringExpression(6, 9); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'substring 6 9': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'substring 6 9': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'substring 6 9': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java index 05f597ed563d..9050704be6ec 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java @@ -57,7 +57,7 @@ public void requireThatExpressionCanBeVerified() { Expression foo = SimpleExpression.newConversion(DataType.STRING, DataType.INT); Expression exp = new SwitchExpression(Map.of("foo", foo)); assertVerify(DataType.STRING, exp, DataType.STRING); // does not touch output - assertVerifyThrows("Invalid expression 'switch { case \"foo\": SimpleExpression; }': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'switch { case \"foo\": SimpleExpression; }': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'switch { case \"foo\": SimpleExpression; }': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java index 02e9335e90e5..1bef3c716f98 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java @@ -29,7 +29,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ThisExpression(); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'this': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'this': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java index e249b0e8b6de..dd0d6995e022 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java @@ -33,7 +33,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToArrayExpression(); assertVerify(DataType.INT, exp, DataType.getArray(DataType.INT)); assertVerify(DataType.STRING, exp, DataType.getArray(DataType.STRING)); - assertVerifyThrows("Invalid expression 'to_array': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_array': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java index fc1d148b502b..a0fea4ad33e9 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java @@ -33,7 +33,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToBoolExpression(); assertVerify(DataType.INT, exp, DataType.BOOL); assertVerify(DataType.STRING, exp, DataType.BOOL); - assertVerifyThrows("Invalid expression 'to_bool': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_bool': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java index 5bb083bfa835..3a02b237fd2c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java @@ -30,7 +30,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToByteExpression(); assertVerify(DataType.INT, exp, DataType.BYTE); assertVerify(DataType.STRING, exp, DataType.BYTE); - assertVerifyThrows("Invalid expression 'to_byte': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_byte': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java index f83f1b41b627..ed67eba39cfa 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java @@ -30,7 +30,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToDoubleExpression(); assertVerify(DataType.INT, exp, DataType.DOUBLE); assertVerify(DataType.STRING, exp, DataType.DOUBLE); - assertVerifyThrows("Invalid expression 'to_double': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_double': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java index 3a5ee328c172..57839d9d59bf 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java @@ -28,7 +28,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToEpochSecondExpression(); assertVerify(DataType.STRING, exp, DataType.LONG); assertVerifyThrows("Invalid expression 'to_epoch_second': Expected string input, got int", DataType.INT, exp); - assertVerifyThrows("Invalid expression 'to_epoch_second': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_epoch_second': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java index c1c8d7601468..3d1b9c6ab778 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java @@ -30,7 +30,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToFloatExpression(); assertVerify(DataType.INT, exp, DataType.FLOAT); assertVerify(DataType.STRING, exp, DataType.FLOAT); - assertVerifyThrows("Invalid expression 'to_float': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_float': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java index c611c4780fcd..db9e8fec11a5 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java @@ -30,7 +30,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToIntegerExpression(); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.INT); - assertVerifyThrows("Invalid expression 'to_int': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_int': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java index 79b3036e1f9e..9497c81eeaea 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java @@ -30,7 +30,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToLongExpression(); assertVerify(DataType.INT, exp, DataType.LONG); assertVerify(DataType.STRING, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'to_long': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_long': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java index 6c0a5259e205..106cc3d949d7 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java @@ -31,7 +31,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ToPositionExpression(); assertVerify(DataType.STRING, exp, PositionDataType.INSTANCE); - assertVerifyThrows("Invalid expression 'to_pos': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_pos': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'to_pos': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java index ed41629ae9c3..6b92540fdadf 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java @@ -30,7 +30,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToStringExpression(); assertVerify(DataType.INT, exp, DataType.STRING); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'to_string': Expected any input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_string': Expected input, but no input is specified", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java index a6f04d1e841c..031dd926ab5c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java @@ -61,7 +61,7 @@ private static void assertVerify(boolean createIfNonExistent, boolean removeIfZe ExpressionAssert.assertVerify(DataType.STRING, expression, DataType.getWeightedSet(DataType.STRING, createIfNonExistent, removeIfZero)); assertVerifyThrows("Invalid expression '" + expression + "': " + - "Expected any input, but no input is specified", null, expression); + "Expected input, but no input is specified", null, expression); } private static void assertConvert(boolean createIfNonExistent, boolean removeIfZero) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java index 3d09d19295d5..e05d9487cee8 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java @@ -48,7 +48,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'tokenize': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'tokenize': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'tokenize': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java index 024e2f17b382..ac0726e936bc 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java @@ -28,7 +28,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new TrimExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'trim': Expected string input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'trim': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'trim': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java index 33c255d3f1da..cc2cca2ecb58 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java @@ -30,7 +30,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ZCurveExpression(); assertVerify(PositionDataType.INSTANCE, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'zcurve': Expected position input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'zcurve': Expected input, but no input is specified", null, exp); assertVerifyThrows("Invalid expression 'zcurve': Expected position input, got int", DataType.INT, exp); } From 68f88963bf6f6c8f6ef40ebd4096eaaf675a351a Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 4 Dec 2024 20:52:02 +0100 Subject: [PATCH 4/8] Depend less on requiredInputType --- .../expressions/CatExpression.java | 19 +++++--- .../expressions/ConstantExpression.java | 2 +- .../expressions/Expression.java | 18 +++---- .../expressions/ForEachExpression.java | 17 +++++-- .../expressions/GetFieldExpression.java | 3 +- .../expressions/IfThenExpression.java | 2 +- .../expressions/JoinExpression.java | 1 + .../expressions/StatementExpression.java | 13 +++-- .../expressions/ToArrayExpression.java | 1 + .../expressions/ToBoolExpression.java | 2 +- .../expressions/ToWsetExpression.java | 1 + .../expressions/UnresolvedDataType.java | 2 +- .../expressions/VerificationContext.java | 7 +-- .../expressions/ZCurveExpression.java | 1 + .../expressions/ArithmeticTestCase.java | 12 +++-- .../AttributeExpressionTestCase.java | 12 ----- .../expressions/Base64DecodeTestCase.java | 7 ++- .../expressions/Base64EncodeTestCase.java | 6 ++- .../expressions/CatTestCase.java | 47 ++++++++++--------- .../expressions/ClearStateTestCase.java | 9 +++- .../expressions/ExactTestCase.java | 14 ++++-- .../expressions/ExpressionAssert.java | 10 ++-- .../expressions/ExpressionTestCase.java | 18 ++++--- .../expressions/FlattenTestCase.java | 8 +++- .../expressions/ForEachTestCase.java | 2 +- .../expressions/GetFieldTestCase.java | 12 +++-- .../expressions/GetVarTestCase.java | 7 ++- .../expressions/GuardTestCase.java | 21 ++++++--- .../expressions/HexDecodeTestCase.java | 7 ++- .../expressions/HexEncodeTestCase.java | 6 ++- .../expressions/IfThenTestCase.java | 22 ++++++--- .../expressions/IndexExpressionTestCase.java | 11 ----- .../expressions/LowerCaseTestCase.java | 6 ++- .../expressions/NGramTestCase.java | 17 +++++-- .../expressions/NormalizeTestCase.java | 8 ++-- .../OptimizePredicateTestCase.java | 12 +++-- .../expressions/OutputAssert.java | 4 +- .../expressions/ParenthesisTestCase.java | 9 ++-- .../expressions/ScriptTestCase.java | 6 +-- .../expressions/SetLanguageTestCase.java | 2 +- .../expressions/SetVarTestCase.java | 7 ++- .../expressions/SimpleExpressionTestCase.java | 9 ++-- .../expressions/SplitTestCase.java | 7 ++- .../expressions/StatementTestCase.java | 9 ++-- .../expressions/SubstringTestCase.java | 7 ++- .../SummaryExpressionTestCase.java | 11 ----- .../expressions/SwitchTestCase.java | 10 +++- .../ToEpochSecondExpressionTestCase.java | 4 +- .../expressions/ToPositionTestCase.java | 6 ++- .../expressions/TokenizeTestCase.java | 9 +++- .../expressions/TrimTestCase.java | 6 ++- .../VerificationContextTestCase.java | 9 ++-- .../expressions/ZCurveTestCase.java | 3 +- .../parser/PrecedenceTestCase.java | 10 +++- 54 files changed, 297 insertions(+), 194 deletions(-) diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java index 1a58c3f7c437..ba39ad62d2ef 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java @@ -47,7 +47,9 @@ public DataType setInputType(DataType inputType, VerificationContext context) { for (var expression : expressions()) outputTypes.add(expression.setInputType(inputType, context)); DataType outputType = resolveOutputType(outputTypes); - return outputType != null ? outputType : getOutputType(context); + if (outputType == null) outputType = getOutputType(context); // TODO: Remove this line + super.setOutputType(outputType, context); + return outputType; } @Override @@ -82,14 +84,14 @@ protected void doVerify(VerificationContext context) { protected void doExecute(ExecutionContext context) { FieldValue input = context.getCurrentValue(); DataType inputType = input != null ? input.getDataType() : null; - VerificationContext verificationContext = new VerificationContext(context.getFieldValue()); - context.fillVariableTypes(verificationContext); +// VerificationContext verificationContext = new VerificationContext(context.getFieldValue()); +// context.fillVariableTypes(verificationContext); List values = new LinkedList<>(); - List types = new LinkedList<>(); +// List types = new LinkedList<>(); for (Expression expression : this) { FieldValue val = context.setCurrentValue(input).execute(expression).getCurrentValue(); values.add(val); - +/* DataType type; if (val != null) { type = val.getDataType(); @@ -97,8 +99,13 @@ protected void doExecute(ExecutionContext context) { type = verificationContext.setCurrentType(inputType).verify(this).getCurrentType(); } types.add(type); + + */ } - DataType type = resolveOutputType(types); +// DataType type = resolveOutputType(types); + DataType type = getOutputType(); + if (type == null) + throw new RuntimeException("Output type is not resolved in " + this); context.setCurrentValue(type == DataType.STRING ? asString(values) : asCollection(type, values)); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java index ea45fead1eab..00a761c1a39a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java @@ -34,7 +34,7 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - if ( ! value.getDataType().isAssignableTo(outputType)) + if (outputType != null && ! value.getDataType().isAssignableTo(outputType)) throw new VerificationException(this, "Produces type " + value.getDataType().getName() + ", but type " + outputType.getName() + " is required"); return super.setOutputType(outputType, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java index 30be368c533f..16307fa4ded1 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java @@ -81,8 +81,10 @@ public void setStatementOutput(DocumentType documentType, Field field) {} * @throws IllegalArgumentException if inputType isn't assignable to requiredType */ protected final DataType setInputType(DataType inputType, DataType requiredType, VerificationContext context) { - if ( requiredType != null && ! (inputType.isAssignableTo(requiredType))) - throw new VerificationException(this, "This requires type " + requiredType.getName() + ", but gets " + inputType.getName()); + if (requiredType != null && inputType == null) + throw new VerificationException(this, "Expected " + requiredType.getName() + " input, but no input is provided"); + if (requiredType != null && ! (inputType.isAssignableTo(requiredType))) + throw new VerificationException(this, "Expected " + requiredType.getName() + " input, got " + inputType.getName()); return assignInputType(inputType); } @@ -163,18 +165,10 @@ private DataType assignOutputType(DataType outputType) { /** Implementations that don't change the type should implement this to do verification. */ protected void doVerify(VerificationContext context) {} - public final DataType verify() { - return verify(new VerificationContext()); - } - public final void verify(DocumentType type) { verify(new DocumentTypeAdapter(type)); } - public final DataType verify(DataType val) { - return verify(new VerificationContext().setCurrentType(val)); - } - public final Document verify(Document doc) { return verify(new SimpleAdapterFactory(), doc); } @@ -225,10 +219,11 @@ public final DataType verify(VerificationContext context) { if (input != null && input.getPrimitiveType() == UnresolvedDataType.INSTANCE) { throw new VerificationException(this, "Failed to resolve input type"); } + /* if (input != null && requiredInputType != null && !requiredInputType.isAssignableFrom(input)) { throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, got " + input.getName()); - } + }*/ } doVerify(context); return context.getCurrentType(); @@ -325,6 +320,7 @@ protected static boolean equals(Object lhs, Object rhs) { // Convenience For testing public static Document execute(Expression expression, Document doc) { + expression.verify(doc); return expression.execute(new SimpleAdapterFactory(), doc); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java index f0fabf052992..ac282efaa651 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java @@ -1,7 +1,13 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.*; +import com.yahoo.document.ArrayDataType; +import com.yahoo.document.DataType; +import com.yahoo.document.DocumentType; +import com.yahoo.document.Field; +import com.yahoo.document.MapDataType; +import com.yahoo.document.StructDataType; +import com.yahoo.document.WeightedSetDataType; import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.MapFieldValue; @@ -43,6 +49,7 @@ public void setStatementOutput(DocumentType documentType, Field field) { @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); + if (inputType == null) return null; if (inputType instanceof ArrayDataType || inputType instanceof WeightedSetDataType) { // Value type outside block becomes the collection type having the block output type as argument @@ -104,12 +111,12 @@ private DataType verifyStructFields(StructDataType struct, VerificationContext c DataType fieldType = field.getDataType(); DataType fieldOutputType = expression.setInputType(fieldType, context); if (fieldOutputType != null && ! fieldOutputType.isAssignableTo(fieldType)) - throw new VerificationException(this, "Struct field " + field.getName() + " has type " + fieldType.getName() + - " but expression produces " + fieldOutputType); + throw new VerificationException(this, "Struct field '" + field.getName() + "' has type " + fieldType.getName() + + " but expression produces " + fieldOutputType.getName()); DataType fieldInputType = expression.setOutputType(fieldType, context); if (fieldOutputType != null && ! fieldType.isAssignableTo(fieldInputType)) - throw new VerificationException(this, "Struct field " + field.getName() + " has type " + fieldType.getName() + - " but expression requires " + fieldInputType); + throw new VerificationException(this, "Struct field '" + field.getName() + "' has type " + fieldType.getName() + + " but expression requires " + fieldInputType.getName()); if (fieldOutputType == null && fieldInputType == null) return null; // Neither direction could be inferred } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java index e84a19e29239..a20e15968943 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java @@ -31,6 +31,7 @@ public GetFieldExpression(String structFieldName) { @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); + if (inputType == null) return null; return getFieldType(inputType, context); } @@ -57,7 +58,7 @@ else if (entryInput.getValueType() instanceof StructuredDataType structInput) else if (input instanceof StructuredDataType structInput) { return getStructFieldType(structInput); } - throw new VerificationException(this, "Expected a struct or map, but got an " + input.getName()); + throw new VerificationException(this, "Expected a struct or map, but got " + input.getName()); } private DataType getStructFieldType(StructuredDataType structInput) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java index c9d37a4002fc..9e4dc54a37ad 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java @@ -59,7 +59,7 @@ public IfThenExpression(Expression lhs, Comparator cmp, Expression right, Expres @Override public boolean requiresInput() { - return left.requiresInput() || right.requiresInput() || ifFalse.requiresInput() || ifFalse.requiresInput(); + return left.requiresInput() || right.requiresInput() || ifTrue.requiresInput() || (ifFalse != null && ifFalse.requiresInput()); } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java index 7d3e8bd46198..efa64b91c93a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java @@ -27,6 +27,7 @@ public JoinExpression(String delimiter) { @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); + if (inputType == null) return null; if ( ! (inputType instanceof ArrayDataType)) throw new VerificationException(this, "Expected Array input, got type " + inputType.getName()); return DataType.STRING; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java index 1e16f6e52646..7db7295c8371 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java @@ -74,12 +74,11 @@ public DataType setOutputType(DataType output, VerificationContext context) { /** Resolves types forward and returns the final output, or null if resolution could not progress to the end. */ private DataType resolveForwards(VerificationContext context) { - int i = 0; - var inputType = getInputType(context); // A nested statement; input imposed from above - if (inputType == null) // otherwise the first expression will be an input deciding the type - inputType = expressions().get(i++).getOutputType(context); - while (i < expressions().size() && inputType != null) - inputType = expressions().get(i++).setInputType(inputType, context); + var inputType = getInputType(context); + for (var expression : expressions()) { + inputType = expression.setInputType(inputType, context); + if (inputType == null) break; + } return inputType; } @@ -89,7 +88,7 @@ private DataType resolveBackwards(VerificationContext context) { var outputType = getOutputType(context); // A nested statement; output imposed from above if (outputType == null) // otherwise the last expression will be an output deciding the type outputType = expressions().get(--i).getInputType(context); - while (--i >= 0 && outputType != null) + while (--i >= 0) outputType = expressions().get(i).setOutputType(outputType, context); return outputType; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java index 351cf450046f..00af8f6071e7 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java @@ -18,6 +18,7 @@ public ToArrayExpression() { @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); + if (input == null) return null; return new ArrayDataType(input); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java index fcb7b5311544..4b7a82293835 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.ArrayDataType; import com.yahoo.document.DataType; import com.yahoo.document.NumericDataType; import com.yahoo.document.datatypes.BoolFieldValue; @@ -21,6 +20,7 @@ public ToBoolExpression() { @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); + if (input == null) return null; if ( ! (input.isAssignableTo(DataType.STRING) && ! (input instanceof NumericDataType))) throw new VerificationException(this, "Input must be a string or number, but got " + input.getName()); return DataType.BOOL; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java index b165d51c7208..083ee584fc76 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java @@ -27,6 +27,7 @@ public ToWsetExpression(boolean createIfNonExistent, boolean removeIfZero) { @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); + if (input == null) return null; return outputType(input); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedDataType.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedDataType.java index 0fd475b689f4..b3b880cfb0cd 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedDataType.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedDataType.java @@ -12,7 +12,7 @@ final class UnresolvedDataType extends PrimitiveDataType { public static final UnresolvedDataType INSTANCE = new UnresolvedDataType(); private UnresolvedDataType() { - super("any", -69, UnresolvedFieldValue.class, UnresolvedFieldValue.getFactory()); + super("unresolved", -69, UnresolvedFieldValue.class, UnresolvedFieldValue.getFactory()); } @Override 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 6de7a2c3ede9..64ea7c0af434 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 @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * @author Simon Thoresen Hult @@ -16,12 +17,8 @@ public class VerificationContext { private DataType currentType; private String outputField; - public VerificationContext() { - this(null); - } - public VerificationContext(FieldTypeAdapter fieldTypes) { - this.fieldTypes = fieldTypes; + this.fieldTypes = Objects.requireNonNull(fieldTypes); } public VerificationContext verify(Expression expression) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java index 2eff85e49d34..445bc330baa4 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java @@ -20,6 +20,7 @@ public ZCurveExpression() { @Override public DataType setInputType(DataType input, VerificationContext context) { + if (input == null) return null; if ( ! (input instanceof StructDataType struct)) throw new VerificationException(this, "This requires a struct as input, but got " + input.getName()); requireIntegerField(PositionDataType.FIELD_X, struct); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java index e1f8d7c16b07..7cf0fc9b06fe 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java @@ -10,8 +10,10 @@ import org.junit.Test; import static com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression.Operator; -import static org.junit.Assert.*; -import static org.mockito.Mockito.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -144,7 +146,7 @@ private void assertResult(FieldValue lhs, Operator op, FieldValue rhs, FieldValu private void assertType(DataType lhs, Operator op, DataType rhs, DataType expected) { assertEquals(expected, newArithmetic(SimpleExpression.newOutput(lhs), op, - SimpleExpression.newOutput(rhs)).verify()); + SimpleExpression.newOutput(rhs)).verify(new VerificationContext(new SimpleTestAdapter()))); assertEquals(expected, newArithmetic(lhs.createFieldValue(6), op, rhs.createFieldValue(9)).execute().getDataType()); } @@ -179,7 +181,7 @@ private static ConstantExpression newLong(long val) { } private static void assertVerify(Expression lhs, Operator op, Expression rhs, DataType val) { - new ArithmeticExpression(lhs, op, rhs).verify(val); + new ArithmeticExpression(lhs, op, rhs).verify(new VerificationContext(new SimpleTestAdapter()).setCurrentType(val)); } private static void assertVerifyThrows(Expression lhs, Operator op, Expression rhs, DataType val, @@ -187,7 +189,7 @@ private static void assertVerifyThrows(Expression lhs, Operator op, Expression r ArithmeticExpression expression = null; try { expression = new ArithmeticExpression(lhs, op, rhs); - expression.verify(val); + expression.verify(new VerificationContext(new SimpleTestAdapter()).setCurrentType(val)); fail("Expected exception"); } catch (VerificationException e) { String expressionString = expression == null ? "of type '" + ArithmeticExpression.class.getSimpleName() + "'" diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpressionTestCase.java index 6f33d66965c9..f6323bd7e127 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpressionTestCase.java @@ -3,8 +3,6 @@ import org.junit.Test; -import static com.yahoo.vespa.indexinglanguage.expressions.OutputAssert.assertExecute; -import static com.yahoo.vespa.indexinglanguage.expressions.OutputAssert.assertVerify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -29,14 +27,4 @@ public void requireThatHashCodeAndEqualsAreImplemented() { assertEquals(exp.hashCode(), new AttributeExpression("foo").hashCode()); } - @Test - public void requireThatExpressionCanBeVerified() { - assertVerify(new AttributeExpression("foo")); - } - - @Test - public void requireThatExpressionCanBeExecuted() { - assertExecute(new AttributeExpression("foo")); - } - } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java index d05b30cc35cb..c4cfe1815028 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeTestCase.java @@ -10,7 +10,10 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -66,7 +69,7 @@ public void requireThatIllegalInputThrows() { public void requireThatExpressionCanBeVerified() { Expression exp = new Base64DecodeExpression(); assertVerify(DataType.STRING, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'base64decode': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'base64decode': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'base64decode': Expected string input, got long", DataType.LONG, exp); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java index 093dc3420d1f..723677f64b86 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -40,7 +42,7 @@ public void requireThatInputIsEncoded() { public void requireThatExpressionCanBeVerified() { Expression exp = new Base64EncodeExpression(); assertVerify(DataType.LONG, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'base64encode': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'base64encode': Expected long input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'base64encode': Expected long input, got string", DataType.STRING, exp); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java index 9edb7c4071f4..d7c313b9485a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java @@ -52,11 +52,9 @@ public void requireThatHashCodeAndEqualsAreImplemented() { } @Test - public void requireThatExpressionCanBeVerified() { + public void expressionCanBeVerified() { assertVerify(new ConstantExpression(new StringFieldValue("foo")), new ConstantExpression(new StringFieldValue("bar")), null); - assertVerify(new SimpleExpression(DataType.STRING), - new SimpleExpression(DataType.STRING), DataType.STRING); assertVerifyThrows(new SimpleExpression().setCreatedOutput(null), new SimpleExpression().setCreatedOutput(DataType.STRING), null, "Invalid expression 'SimpleExpression . SimpleExpression': In SimpleExpression: Attempting to concatenate a null value"); @@ -65,7 +63,7 @@ public void requireThatExpressionCanBeVerified() { "Invalid expression of type 'CatExpression': Operands require conflicting input types, string vs int"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), null, - "Invalid expression 'SimpleExpression': Expected input, but no input is specified"); + "Invalid expression 'SimpleExpression': Expected string input, but no input is provided"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), DataType.INT, "Invalid expression 'SimpleExpression': Expected string input, got int"); @@ -96,22 +94,23 @@ public void requireThatPrimitiveVerificationWorks() { } @Test - public void requireThatInputValueIsAvailableToAllInnerExpressions() { - assertEquals(new StringFieldValue("foobarfoo"), - new StatementExpression(new ConstantExpression(new StringFieldValue("foo")), - new CatExpression(new ThisExpression(), - new ConstantExpression(new StringFieldValue("bar")), - new ThisExpression())).execute()); + public void inputValueIsAvailableToAllInnerExpressions() { + var expression = new StatementExpression(new ConstantExpression(new StringFieldValue("foo")), + new CatExpression(new ThisExpression(), + new ConstantExpression(new StringFieldValue("bar")), + new ThisExpression())); + expression.verify(new SimpleTestAdapter()); + assertEquals(new StringFieldValue("foobarfoo"), expression.execute()); } @Test - public void requiredThatRequiredInputTypeAllowsNull() { + public void requiredInputTypeAllowsNull() { assertVerify(new ConstantExpression(new StringFieldValue("foo")), new TrimExpression(), DataType.STRING); assertVerify(new TrimExpression(), new ConstantExpression(new StringFieldValue("foo")), DataType.STRING); } @Test - public void requireThatArraysAreConcatenated() { + public void arraysAreConcatenated() { Array lhs = new Array<>(DataType.getArray(DataType.STRING)); lhs.add(new StringFieldValue("6")); Array rhs = new Array<>(DataType.getArray(DataType.STRING)); @@ -221,13 +220,16 @@ public void requireThatCollectionValuesMustBeCompatible() { } private static void assertVerify(Expression expA, Expression expB, DataType val) { - new CatExpression(expA, expB).verify(val); + new CatExpression(expA, expB).verify(new VerificationContext(new SimpleTestAdapter()).setCurrentType(val)); } private static void assertVerifyThrows(Expression expA, Expression expB, DataType val, String expectedException) { try { - new CatExpression(expA, expB).verify(val); - fail(); + var expression = new CatExpression(expA, expB); + var context = new VerificationContext(new SimpleTestAdapter()).setCurrentType(val); + expression.setInputType(val, context); + expression.verify(context); + fail("Expected exception"); } catch (VerificationException e) { if (!e.getMessage().startsWith(expectedException)) { assertEquals(expectedException, e.getMessage()); @@ -240,12 +242,15 @@ private static FieldValue evaluate(FieldValue valA, FieldValue valB) { } private static FieldValue evaluate(DataType typeA, FieldValue valA, DataType typeB, FieldValue valB) { - ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field("a", typeA), - new Field("b", typeB))); - ctx.setFieldValue("a", valA, null); - ctx.setFieldValue("b", valB, null); - new CatExpression(new InputExpression("a"), new InputExpression("b")).execute(ctx); - return ctx.getCurrentValue(); + var adapter = new SimpleTestAdapter(new Field("a", typeA), + new Field("b", typeB)); + var expression = new CatExpression(new InputExpression("a"), new InputExpression("b")); + expression.setInputType(null, new VerificationContext(adapter)); + ExecutionContext context = new ExecutionContext(adapter); + context.setFieldValue("a", valA, null); + context.setFieldValue("b", valB, null); + expression.execute(context); + return context.getCurrentValue(); } private static DataType evaluate(DataType typeA, DataType typeB) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java index cb480a36bf4d..ee09313f8e86 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java @@ -2,10 +2,13 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; +import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -57,6 +60,10 @@ private static class MyVerification extends VerificationContext { boolean cleared = false; + MyVerification() { + super(new SimpleTestAdapter()); + } + @Override public VerificationContext clear() { cleared = true; diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java index 3befaa9f0a66..a23e8705cf0e 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExactTestCase.java @@ -2,7 +2,11 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; -import com.yahoo.document.annotation.*; +import com.yahoo.document.annotation.Annotation; +import com.yahoo.document.annotation.SpanList; +import com.yahoo.document.annotation.SpanNode; +import com.yahoo.document.annotation.SpanTree; +import com.yahoo.document.annotation.SpanTrees; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; @@ -11,7 +15,11 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -84,7 +92,7 @@ public void requireThatEmptyStringsAreNotAnnotated() { public void requireThatExpressionCanBeVerified() { Expression exp = new ExactExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'exact': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'exact': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'exact': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java index b20c737d6565..79f08f49ca80 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java @@ -2,8 +2,7 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; - -import java.util.regex.Pattern; +import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -18,18 +17,18 @@ public static void assertVerifyCtx(Expression expression, DataType expectedValue } public static void assertVerify(DataType valueBefore, Expression expression, DataType expectedValueAfter) { - assertVerifyCtx(expression, expectedValueAfter, new VerificationContext().setCurrentType(valueBefore)); + assertVerifyCtx(expression, expectedValueAfter, new VerificationContext(new SimpleTestAdapter()).setCurrentType(valueBefore)); } public static void assertVerifyThrows(String expectedMessage, DataType valueBefore, Expression expression) { - assertVerifyThrows(expectedMessage, expression, new VerificationContext().setCurrentType(valueBefore)); + assertVerifyThrows(expectedMessage, expression, new VerificationContext(new SimpleTestAdapter()).setCurrentType(valueBefore)); } interface CreateExpression { Expression create(); } public static void assertVerifyThrows(String expectedMessage, DataType valueBefore, CreateExpression createExpression) { - assertVerifyThrows(expectedMessage, createExpression, new VerificationContext().setCurrentType(valueBefore)); + assertVerifyThrows(expectedMessage, createExpression, new VerificationContext(new SimpleTestAdapter()).setCurrentType(valueBefore)); } public static void assertVerifyThrows(String expectedMessage, CreateExpression createExp, VerificationContext context) { @@ -43,6 +42,7 @@ public static void assertVerifyThrows(String expectedMessage, CreateExpression c } public static void assertVerifyThrows(String expectedMessage, Expression expression, VerificationContext context) { try { + expression.setInputType(context.getCurrentType(), context); expression.verify(context); fail("Expected exception"); } catch (VerificationException e) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java index 168919065403..c70e220194b8 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java @@ -5,9 +5,13 @@ import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.StringFieldValue; +import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -34,9 +38,9 @@ public void requireThatOutputTypeIsCheckedAfterExecute() { public void requireThatInputTypeIsCheckedBeforeVerify() { assertVerify(newRequiredInput(DataType.INT), DataType.INT); assertVerifyThrows(newRequiredInput(DataType.INT), null, - "Invalid expression 'SimpleExpression': Expected input, but no input is specified"); + "Invalid expression 'SimpleExpression': Expected int input, but no input is provided"); assertVerifyThrows(newRequiredInput(DataType.INT), UnresolvedDataType.INSTANCE, - "Invalid expression 'SimpleExpression': Failed to resolve input type"); + "Invalid expression 'SimpleExpression': Expected int input, got unresolved"); assertVerifyThrows(newRequiredInput(DataType.INT), DataType.STRING, "Invalid expression 'SimpleExpression': Expected int input, got string"); } @@ -77,13 +81,15 @@ private static void assertExecuteThrows(Expression exp, FieldValue val, Exceptio } private static void assertVerify(Expression exp, DataType val) { - exp.verify(val); + var context = new VerificationContext(new SimpleTestAdapter()).setCurrentType(val); + exp.setInputType(val, context); + exp.verify(context); } private static void assertVerifyThrows(Expression exp, DataType val, String expectedException) { try { - exp.verify(val); - fail(); + assertVerify(exp, val); + fail("Expected exception"); } catch (VerificationException e) { assertEquals(expectedException, e.getMessage()); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java index 9373dd3b52ed..f5399f2cd212 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenTestCase.java @@ -2,7 +2,11 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; -import com.yahoo.document.annotation.*; +import com.yahoo.document.annotation.Annotation; +import com.yahoo.document.annotation.AnnotationTypes; +import com.yahoo.document.annotation.Span; +import com.yahoo.document.annotation.SpanTree; +import com.yahoo.document.annotation.SpanTrees; import com.yahoo.document.datatypes.StringFieldValue; import org.junit.Test; @@ -87,7 +91,7 @@ public void requireThatAnnotationsWithoutFieldValueUseOriginalSpan() { public void requireThatExpressionCanBeVerified() { Expression exp = new FlattenExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'flatten': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'flatten': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'flatten': Expected string input, got int", DataType.INT, exp); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java index c7566b5a573a..42df0bbefb8e 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java @@ -64,7 +64,7 @@ public void requireThatStructFieldCompatibilityIsVerified() { type.addField(new Field("foo", DataType.INT)); assertVerify(type, new ForEachExpression(new SimpleExpression()), type); assertVerifyThrows("Invalid expression 'SimpleExpression': Expected string input, got int", type, new ForEachExpression(SimpleExpression.newConversion(DataType.STRING, DataType.INT))); - assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Expected int output, got string", type, new ForEachExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING))); + assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Struct field 'foo' has type int but expression produces string", type, new ForEachExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING))); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java index e1366d4b7b90..79e74a82efc2 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java @@ -1,7 +1,11 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.*; +import com.yahoo.document.DataType; +import com.yahoo.document.Document; +import com.yahoo.document.DocumentType; +import com.yahoo.document.Field; +import com.yahoo.document.StructDataType; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; @@ -10,7 +14,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -39,7 +45,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new GetFieldExpression("foo"); assertVerify(type, exp, DataType.STRING); assertVerifyThrows("Invalid expression 'get_field foo': Expected input, but no input is specified", null, exp); - assertVerifyThrows("Invalid expression 'get_field foo': Expected a struct or map, but got an int", DataType.INT, exp); + assertVerifyThrows("Invalid expression 'get_field foo': Expected a struct or map, but got int", DataType.INT, exp); assertVerifyThrows("Invalid expression 'get_field bar': Field 'bar' not found in struct type 'my_struct'", type, new GetFieldExpression("bar")); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarTestCase.java index f7f665947096..89be7daaeef7 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarTestCase.java @@ -9,7 +9,10 @@ import com.yahoo.vespa.indexinglanguage.parser.ParseException; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -33,7 +36,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { @Test public void requireThatExpressionCanBeVerified() { - VerificationContext ctx = new VerificationContext(); + VerificationContext ctx = new VerificationContext(new SimpleTestAdapter()); ctx.setVariable("foo", DataType.STRING); assertEquals(DataType.STRING, new GetVarExpression("foo").verify(ctx)); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java index 188c9990963a..b772c4a0157c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java @@ -1,7 +1,11 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.*; +import com.yahoo.document.DataType; +import com.yahoo.document.Document; +import com.yahoo.document.DocumentType; +import com.yahoo.document.DocumentUpdate; +import com.yahoo.document.Field; import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.update.AssignValueUpdate; @@ -17,7 +21,12 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -46,8 +55,8 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new GuardExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)); assertVerify(DataType.INT, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'guard { SimpleExpression; }': Expected input, but no input is specified", null, exp); - assertVerifyThrows("Invalid expression 'guard { SimpleExpression; }': Expected int input, got string", DataType.STRING, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, but no input is provided", null, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.STRING, exp); } @Test @@ -58,7 +67,7 @@ public void requireThatInputFieldsAreIncludedByDocument() throws ParseException Document doc = new Document(docType, "id:scheme:my_input::"); doc.setFieldValue("my_str", new StringFieldValue("69")); - assertNotNull(doc = Expression.execute(Expression.fromString("guard { input my_str | to_int | attribute my_lng }"), doc)); + assertNotNull(doc = Expression.execute(Expression.fromString("guard { input my_str | to_long | attribute my_lng }"), doc)); assertEquals(new LongFieldValue(69), doc.getFieldValue("my_lng")); } @@ -70,7 +79,7 @@ public void requireThatInputFieldsAreIncludedByUpdate() throws ParseException { DocumentUpdate docUpdate = new DocumentUpdate(docType, "id:scheme:my_input::"); docUpdate.addFieldUpdate(FieldUpdate.createAssign(docType.getField("my_str"), new StringFieldValue("69"))); - assertNotNull(docUpdate = Expression.execute(Expression.fromString("guard { input my_str | to_int | attribute my_lng }"), docUpdate)); + assertNotNull(docUpdate = Expression.execute(Expression.fromString("guard { input my_str | to_long | attribute my_lng }"), docUpdate)); assertEquals(0, docUpdate.fieldPathUpdates().size()); assertEquals(1, docUpdate.fieldUpdates().size()); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java index b692e6e8085d..93a132e0afcd 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeTestCase.java @@ -10,7 +10,10 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -29,7 +32,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new HexDecodeExpression(); assertVerify(DataType.STRING, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'hexdecode': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'hexdecode': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'hexdecode': Expected string input, got long", DataType.LONG, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java index 1c6d01513876..39ef0963c949 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -29,7 +31,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new HexEncodeExpression(); assertVerify(DataType.LONG, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'hexencode': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'hexencode': Expected long input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'hexencode': Expected long input, got string", DataType.STRING, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java index 0331c1397a6e..d94cb9913004 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java @@ -3,7 +3,14 @@ import com.yahoo.document.DataType; import com.yahoo.document.Field; -import com.yahoo.document.datatypes.*; +import com.yahoo.document.datatypes.ByteFieldValue; +import com.yahoo.document.datatypes.DoubleFieldValue; +import com.yahoo.document.datatypes.FieldValue; +import com.yahoo.document.datatypes.FloatFieldValue; +import com.yahoo.document.datatypes.IntegerFieldValue; +import com.yahoo.document.datatypes.LongFieldValue; +import com.yahoo.document.datatypes.NumericFieldValue; +import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.serialization.FieldReader; import com.yahoo.document.serialization.FieldWriter; import com.yahoo.document.serialization.XmlStream; @@ -15,7 +22,11 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; import static com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression.Comparator; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -41,9 +52,8 @@ public void requireThatRequiredInputTypeCompatibilityIsVerified() { Expression exp = newRequiredInput(DataType.STRING, Comparator.EQ, DataType.STRING, DataType.STRING, DataType.STRING); assertVerify(DataType.STRING, exp, DataType.STRING); - String prefix = "Invalid expression 'if (SimpleExpression == SimpleExpression) { SimpleExpression; } else { SimpleExpression; }': "; - assertVerifyThrows(prefix + "Expected input, but no input is specified", null, exp); - assertVerifyThrows(prefix + "Expected string input, got int", DataType.INT, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected string input, but no input is provided", null, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected string input, got int", DataType.INT, exp); assertVerifyThrows("Invalid expression of type 'IfThenExpression': Operands require conflicting input types, int vs string", null, () -> newRequiredInput(DataType.INT, Comparator.EQ, DataType.STRING, DataType.STRING, DataType.STRING) ); @@ -61,7 +71,7 @@ public void requireThatRequiredInputTypeCompatibilityIsVerified() { @Test public void requireThatExpressionCanBeVerified() { assertVerify(DataType.STRING, new FlattenExpression(), DataType.STRING); - assertVerifyThrows("Invalid expression 'flatten': Expected input, but no input is specified", null, new FlattenExpression() + assertVerifyThrows("Invalid expression 'flatten': Expected string input, but no input is provided", null, new FlattenExpression() ); assertVerifyThrows("Invalid expression 'flatten': Expected string input, got int", DataType.INT, new FlattenExpression() ); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IndexExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IndexExpressionTestCase.java index 298d414d6678..c7ae3e55dcfd 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IndexExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IndexExpressionTestCase.java @@ -3,8 +3,6 @@ import org.junit.Test; -import static com.yahoo.vespa.indexinglanguage.expressions.OutputAssert.assertExecute; -import static com.yahoo.vespa.indexinglanguage.expressions.OutputAssert.assertVerify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -29,13 +27,4 @@ public void requireThatHashCodeAndEqualsAreImplemented() { assertEquals(lhs.hashCode(), new IndexExpression("foo").hashCode()); } - @Test - public void requireThatExpressionCanBeVerified() { - assertVerify(new IndexExpression("foo")); - } - - @Test - public void requireThatExpressionCanBeExecuted() { - assertExecute(new IndexExpression("foo")); - } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java index 267efa32996f..e2ea1425f472 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseTestCase.java @@ -9,7 +9,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -28,7 +30,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new LowerCaseExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'lowercase': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'lowercase': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'lowercase': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java index ee4cefeed9c9..f246e498dcc8 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NGramTestCase.java @@ -2,7 +2,12 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; -import com.yahoo.document.annotation.*; +import com.yahoo.document.annotation.Annotation; +import com.yahoo.document.annotation.AnnotationTypes; +import com.yahoo.document.annotation.SpanList; +import com.yahoo.document.annotation.SpanNode; +import com.yahoo.document.annotation.SpanTree; +import com.yahoo.document.annotation.SpanTrees; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.language.Linguistics; @@ -16,7 +21,13 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author bratseth @@ -46,7 +57,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new NGramExpression(new SimpleLinguistics(), 69); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'ngram 69': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'ngram 69': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'ngram 69': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java index bfd8e9b0855a..eb29387f16c2 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeTestCase.java @@ -9,13 +9,15 @@ import com.yahoo.language.process.Transformer; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; - import org.junit.Test; import org.mockito.Mockito; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -43,7 +45,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new NormalizeExpression(new SimpleLinguistics()); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'normalize': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'normalize': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'normalize': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java index 09902d9257b4..89e0de62fa54 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateTestCase.java @@ -7,13 +7,17 @@ import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.PredicateFieldValue; import com.yahoo.document.predicate.Predicate; +import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; import org.mockito.Mockito; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtx; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -77,11 +81,11 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new OptimizePredicateExpression(); String prefix = "Invalid expression 'optimize_predicate': "; - assertVerifyThrows(prefix + "Expected input, but no input is specified", null, exp); + assertVerifyThrows(prefix + "Expected predicate input, but no input is provided", null, exp); assertVerifyThrows(prefix + "Expected predicate input, got int", DataType.INT, exp); assertVerifyThrows(prefix + "Variable 'arity' must be set", DataType.PREDICATE, exp); - VerificationContext context = new VerificationContext().setCurrentType(DataType.PREDICATE); + VerificationContext context = new VerificationContext(new SimpleTestAdapter()).setCurrentType(DataType.PREDICATE); context.setVariable("arity", DataType.STRING); ExpressionAssert.assertVerifyThrows(prefix + "Variable 'arity' must have type int", exp, context); context.setVariable("arity", DataType.INT); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java index 2fd3a1def29c..897240535ed7 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java @@ -34,7 +34,9 @@ public static void assertVerify(OutputExpression exp) { } public static void assertVerify(FieldTypeAdapter adapter, DataType value, Expression exp) { - assertEquals(value, new VerificationContext(adapter).setCurrentType(value).verify(exp).getCurrentType()); + var context = new VerificationContext(adapter).setCurrentType(value); + assertEquals(value, exp.setInputType(value, context)); + assertEquals(value, context.verify(exp).getCurrentType()); } public static void assertVerifyThrows(FieldTypeAdapter adapter, DataType value, Expression exp, diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java index ac6bb63ab879..7c07a69d5abf 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisTestCase.java @@ -9,7 +9,10 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -37,8 +40,8 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ParenthesisExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)); assertVerify(DataType.INT, exp, DataType.STRING); - assertVerifyThrows("Invalid expression '(SimpleExpression)': Expected input, but no input is specified", null, exp); - assertVerifyThrows("Invalid expression '(SimpleExpression)': Expected int input, got string", DataType.STRING, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, but no input is provided", null, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.STRING, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java index 098e4171d9c8..5c58927a3d93 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java @@ -16,7 +16,6 @@ import java.util.List; -import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -64,9 +63,8 @@ public void requireThatHashCodeAndEqualsAreImplemented() { @Test public void requireThatExpressionCanBeVerified() { Expression exp = newScript(newStatement(SimpleExpression.newConversion(DataType.INT, DataType.STRING))); - assertVerify(DataType.INT, exp, DataType.STRING); - assertVerifyThrows("Invalid expression '{ SimpleExpression; }': Expected input, but no input is specified", null, exp); - assertVerifyThrows("Invalid expression '{ SimpleExpression; }': Expected int input, got string", DataType.STRING, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, but no input is provided", null, exp); + assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.STRING, exp); assertVerifyThrows("Invalid expression of type 'ScriptExpression': Statements require conflicting input types, int vs string", null, () -> newScript(newStatement(SimpleExpression.newConversion(DataType.INT, DataType.STRING)), newStatement(SimpleExpression.newConversion(DataType.STRING, DataType.INT))) diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java index 09bad7582302..505456393da1 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageTestCase.java @@ -29,7 +29,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new SetLanguageExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'set_language': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'set_language': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'set_language': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java index 9fe94509aa63..6af111cf96f8 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java @@ -9,7 +9,10 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -39,7 +42,7 @@ public void requireThatExpressionCanBeVerified() { assertVerifyThrows("Invalid expression 'set_var foo': Expected input, but no input is specified", null, exp); try { - new VerificationContext().setVariable("foo", DataType.INT).setCurrentType(DataType.STRING).verify(exp); + new VerificationContext(new SimpleTestAdapter()).setVariable("foo", DataType.INT).setCurrentType(DataType.STRING).verify(exp); fail(); } catch (VerificationException e) { assertEquals("Invalid expression 'set_var foo': Cannot set variable 'foo' to type string: It is already set to type int", e.getMessage()); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java index 81858130a17c..f01400957e71 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpressionTestCase.java @@ -3,9 +3,12 @@ import com.yahoo.document.DataType; import com.yahoo.document.datatypes.IntegerFieldValue; +import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; /** * @author Simon Thoresen Hult @@ -17,10 +20,10 @@ public void requireThatAccessorsWork() { SimpleExpression exp = new SimpleExpression(); assertNull(exp.createdOutputType()); assertNull(exp.execute()); - assertNull(exp.verify()); + assertNull(exp.verify(new SimpleTestAdapter())); assertEquals(DataType.INT, new SimpleExpression().setCreatedOutput(DataType.INT).createdOutputType()); - assertEquals(DataType.INT, new SimpleExpression().setVerifyValue(DataType.INT).verify()); + assertEquals(DataType.INT, new SimpleExpression().setVerifyValue(DataType.INT).verify(new SimpleTestAdapter())); assertEquals(new IntegerFieldValue(69), new SimpleExpression().setExecuteValue(new IntegerFieldValue(69)).execute()); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java index b914ed7d77c4..4c21c12d5aa3 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java @@ -10,7 +10,10 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -37,7 +40,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new SplitExpression(";"); assertVerify(DataType.STRING, exp, DataType.getArray(DataType.STRING)); - assertVerifyThrows("Invalid expression 'split \";\"': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'split \";\"': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'split \";\"': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java index 236d541bbd31..5aada78f6f72 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java @@ -4,16 +4,18 @@ import com.yahoo.document.DataType; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; -import com.yahoo.vespa.indexinglanguage.ScriptTester; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; - import java.util.List; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -77,7 +79,6 @@ public void requireThatCreatedOutputIsDeterminedByLastNonNullCreatedOutput() { public void requireThatInternalVerificationIsPerformed() { Expression exp = newStatement(SimpleExpression.newOutput(DataType.STRING), SimpleExpression.newConversion(DataType.INT, DataType.STRING)); - assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", null, exp); assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.INT, exp); assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.STRING, exp); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java index 93c3c61e264a..74b4f4dc5153 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringTestCase.java @@ -9,7 +9,10 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -37,7 +40,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new SubstringExpression(6, 9); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'substring 6 9': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'substring 6 9': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'substring 6 9': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SummaryExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SummaryExpressionTestCase.java index 063bfdb92446..d854a86a599c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SummaryExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SummaryExpressionTestCase.java @@ -3,8 +3,6 @@ import org.junit.Test; -import static com.yahoo.vespa.indexinglanguage.expressions.OutputAssert.assertExecute; -import static com.yahoo.vespa.indexinglanguage.expressions.OutputAssert.assertVerify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -29,13 +27,4 @@ public void requireThatHashCodeAndEqualsAreImplemented() { assertEquals(exp.hashCode(), new SummaryExpression("foo").hashCode()); } - @Test - public void requireThatExpressionCanBeVerified() { - assertVerify(new SummaryExpression("foo")); - } - - @Test - public void requireThatExpressionCanBeExecuted() { - assertExecute(new SummaryExpression("foo")); - } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java index 9050704be6ec..8827d9c6fc75 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java @@ -12,7 +12,13 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -57,7 +63,7 @@ public void requireThatExpressionCanBeVerified() { Expression foo = SimpleExpression.newConversion(DataType.STRING, DataType.INT); Expression exp = new SwitchExpression(Map.of("foo", foo)); assertVerify(DataType.STRING, exp, DataType.STRING); // does not touch output - assertVerifyThrows("Invalid expression 'switch { case \"foo\": SimpleExpression; }': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'switch { case \"foo\": SimpleExpression; }': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'switch { case \"foo\": SimpleExpression; }': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java index 57839d9d59bf..edfd6b6d9a19 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpressionTestCase.java @@ -11,8 +11,8 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class ToEpochSecondExpressionTestCase { @Test @@ -28,7 +28,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToEpochSecondExpression(); assertVerify(DataType.STRING, exp, DataType.LONG); assertVerifyThrows("Invalid expression 'to_epoch_second': Expected string input, got int", DataType.INT, exp); - assertVerifyThrows("Invalid expression 'to_epoch_second': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_epoch_second': Expected string input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java index 106cc3d949d7..526727b70e40 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionTestCase.java @@ -12,7 +12,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -31,7 +33,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ToPositionExpression(); assertVerify(DataType.STRING, exp, PositionDataType.INSTANCE); - assertVerifyThrows("Invalid expression 'to_pos': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_pos': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'to_pos': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java index e05d9487cee8..8c4c328ed9c0 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeTestCase.java @@ -15,7 +15,12 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -48,7 +53,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'tokenize': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'tokenize': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'tokenize': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java index ac0726e936bc..fef53ea92b38 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/TrimTestCase.java @@ -9,7 +9,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -28,7 +30,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new TrimExpression(); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'trim': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'trim': Expected string input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'trim': Expected string input, got int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java index a24ba1343bc0..2f821907d943 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; +import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; import static org.junit.Assert.assertNull; @@ -14,7 +15,7 @@ public class VerificationContextTestCase { @Test public void requireThatValueCanBeSet() { - VerificationContext ctx = new VerificationContext(); + VerificationContext ctx = new VerificationContext(new SimpleTestAdapter()); DataType val = DataType.STRING; ctx.setCurrentType(val); assertSame(val, ctx.getCurrentType()); @@ -22,7 +23,7 @@ public void requireThatValueCanBeSet() { @Test public void requireThatVariablesCanBeSet() { - VerificationContext ctx = new VerificationContext(); + VerificationContext ctx = new VerificationContext(new SimpleTestAdapter()); DataType val = DataType.STRING; ctx.setVariable("foo", val); assertSame(val, ctx.getVariable("foo")); @@ -30,7 +31,7 @@ public void requireThatVariablesCanBeSet() { @Test public void requireThatClearRemovesValue() { - VerificationContext ctx = new VerificationContext(); + VerificationContext ctx = new VerificationContext(new SimpleTestAdapter()); ctx.setCurrentType(DataType.STRING); ctx.clear(); assertNull(ctx.getCurrentType()); @@ -38,7 +39,7 @@ public void requireThatClearRemovesValue() { @Test public void requireThatClearRemovesVariables() { - VerificationContext ctx = new VerificationContext(); + VerificationContext ctx = new VerificationContext(new SimpleTestAdapter()); ctx.setVariable("foo", DataType.STRING); ctx.clear(); assertNull(ctx.getVariable("foo")); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java index cc2cca2ecb58..11c012d162de 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java @@ -10,7 +10,6 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertFalse; /** @@ -31,7 +30,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ZCurveExpression(); assertVerify(PositionDataType.INSTANCE, exp, DataType.LONG); assertVerifyThrows("Invalid expression 'zcurve': Expected input, but no input is specified", null, exp); - assertVerifyThrows("Invalid expression 'zcurve': Expected position input, got int", DataType.INT, exp); + assertVerifyThrows("Invalid expression 'zcurve': This requires a struct as input, but got int", DataType.INT, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/parser/PrecedenceTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/parser/PrecedenceTestCase.java index 7c371404c102..6857dd697241 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/parser/PrecedenceTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/parser/PrecedenceTestCase.java @@ -1,7 +1,9 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.parser; +import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import com.yahoo.vespa.indexinglanguage.expressions.Expression; +import com.yahoo.vespa.indexinglanguage.expressions.VerificationContext; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -17,7 +19,11 @@ public void requireThatMathPrecedesConcat() throws ParseException { assertEquals("33", evaluate("1 + 2 . 3")); } - private static String evaluate(String script) throws ParseException { - return String.valueOf(Expression.fromString(script).execute()); + private static String evaluate(String expressionString) throws ParseException { + var expression = Expression.fromString(expressionString); + // TODO: Move setInputType propagation from StatementExpression to Expression to force type resolution also when no statement? + expression.setInputType(null, new VerificationContext(new SimpleTestAdapter())); + return String.valueOf(expression.execute()); } + } From e62aba3839f9b6d722edbb8331a53286f7de204b Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 4 Dec 2024 22:23:06 +0100 Subject: [PATCH 5/8] Pull verification down --- .../expressions/Expression.java | 19 ++----------------- .../expressions/ForEachExpression.java | 2 +- .../expressions/GetFieldExpression.java | 2 +- .../expressions/JoinExpression.java | 5 ++--- .../expressions/SetVarExpression.java | 2 ++ .../expressions/ThisExpression.java | 3 ++- .../expressions/ToArrayExpression.java | 2 ++ .../expressions/ToBoolExpression.java | 2 ++ .../expressions/ToByteExpression.java | 3 ++- .../expressions/ToDoubleExpression.java | 2 ++ .../expressions/ToFloatExpression.java | 2 ++ .../expressions/ToIntegerExpression.java | 2 ++ .../expressions/ToLongExpression.java | 2 ++ .../expressions/ToStringExpression.java | 2 ++ .../expressions/ToWsetExpression.java | 2 ++ .../expressions/ZCurveExpression.java | 2 ++ .../indexinglanguage/ScriptTestCase.java | 6 +++--- .../expressions/EchoTestCase.java | 7 ++++--- .../expressions/ForEachTestCase.java | 2 +- .../expressions/GetFieldTestCase.java | 2 +- .../expressions/JoinTestCase.java | 6 ++++-- .../expressions/SetVarTestCase.java | 2 +- .../expressions/ThisTestCase.java | 2 +- .../expressions/ToArrayTestCase.java | 2 +- .../expressions/ToBoolTestCase.java | 2 +- .../expressions/ToByteTestCase.java | 6 ++++-- .../expressions/ToDoubleTestCase.java | 6 ++++-- .../expressions/ToFloatTestCase.java | 6 ++++-- .../expressions/ToIntegerTestCase.java | 6 ++++-- .../expressions/ToLongTestCase.java | 6 ++++-- .../expressions/ToStringTestCase.java | 6 ++++-- .../expressions/ToWsetTestCase.java | 2 +- .../expressions/ZCurveTestCase.java | 2 +- 33 files changed, 73 insertions(+), 52 deletions(-) diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java index 16307fa4ded1..194f2ee61877 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java @@ -162,9 +162,6 @@ private DataType assignOutputType(DataType outputType) { public abstract DataType createdOutputType(); - /** Implementations that don't change the type should implement this to do verification. */ - protected void doVerify(VerificationContext context) {} - public final void verify(DocumentType type) { verify(new DocumentTypeAdapter(type)); } @@ -211,24 +208,12 @@ public final DataType verify(FieldTypeAdapter adapter) { } public final DataType verify(VerificationContext context) { - if (requiresInput()) { - DataType input = context.getCurrentType(); - if (input == null) { - throw new VerificationException(this, "Expected input, but no input is specified"); - } - if (input != null && input.getPrimitiveType() == UnresolvedDataType.INSTANCE) { - throw new VerificationException(this, "Failed to resolve input type"); - } - /* - if (input != null && requiredInputType != null && !requiredInputType.isAssignableFrom(input)) { - throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, got " + - input.getName()); - }*/ - } doVerify(context); return context.getCurrentType(); } + protected void doVerify(VerificationContext context) {} + public final FieldValue execute(FieldValue val) { return execute(new ExecutionContext().setCurrentValue(val)); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java index ac282efaa651..0bb85449a04f 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java @@ -158,7 +158,7 @@ else if (valueType instanceof MapDataType) { } else { throw new VerificationException(this, "Expected Array, Struct, WeightedSet or Map input, got " + - valueType.getName()); + (valueType == null ? "no value" : valueType.getName())); } } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java index a20e15968943..1aa88c591610 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java @@ -58,7 +58,7 @@ else if (entryInput.getValueType() instanceof StructuredDataType structInput) else if (input instanceof StructuredDataType structInput) { return getStructFieldType(structInput); } - throw new VerificationException(this, "Expected a struct or map, but got " + input.getName()); + throw new VerificationException(this, "Expected a struct or map, but got " + (input == null ? "no value": input.getName())); } private DataType getStructFieldType(StructuredDataType structInput) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java index efa64b91c93a..4273c82c6b16 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java @@ -42,9 +42,8 @@ public DataType setOutputType(DataType outputType, VerificationContext context) @Override protected void doVerify(VerificationContext context) { DataType input = context.getCurrentType(); - if (!(input instanceof ArrayDataType)) { - throw new VerificationException(this, "Expected Array input, got type " + input.getName()); - } + if (!(input instanceof ArrayDataType)) + throw new VerificationException(this, "Expected Array input, got " + (input == null ? "no value" : input.getName())); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java index 3169563818cb..85f2e6d90943 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java @@ -31,6 +31,8 @@ public DataType setOutputType(DataType outputType, VerificationContext context) @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); setVariableType(context.getCurrentType(), context); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java index b3e5e5c23f82..0065c398abd5 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java @@ -14,7 +14,8 @@ public ThisExpression() { @Override protected void doVerify(VerificationContext context) { - // empty + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java index 00af8f6071e7..377ca7741a70 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java @@ -35,6 +35,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(DataType.getArray(context.getCurrentType())); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java index 4b7a82293835..38c211bf6320 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java @@ -34,6 +34,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java index a3326e9189fe..9670c3ae1a84 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; -import com.yahoo.document.NumericDataType; import com.yahoo.document.datatypes.ByteFieldValue; /** @@ -28,6 +27,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java index 11a7c8d49db7..1e4dc3909cd5 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java @@ -27,6 +27,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java index 11cf1a447b31..0331bef4acdf 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java @@ -27,6 +27,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java index 53fa9210711c..6fbe01c6cc28 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java @@ -27,6 +27,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java index fd611047ab98..0c4d2ba9f95d 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java @@ -27,6 +27,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java index e290680e32d4..268ccc2d91fd 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java @@ -27,6 +27,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java index 083ee584fc76..2fea3e8410a5 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java @@ -41,6 +41,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(outputType(context.getCurrentType())); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java index 445bc330baa4..2430b2da74f6 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java @@ -45,6 +45,8 @@ public DataType setOutputType(DataType output, VerificationContext context) { @Override protected void doVerify(VerificationContext context) { + if (context.getCurrentType() == null) + throw new VerificationException(this, "Expected input, but no input is provided"); context.setCurrentType(createdOutputType()); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java index 0e605d64d946..c529b7d4fc1f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -71,7 +71,7 @@ public void failsWhenOneStatementIsMissingInput() { exp.verify(input); fail("Expected exception"); } catch (VerificationException e) { - assertEquals("Invalid expression 'attribute out-2': Expected input, but no input is specified", e.getMessage()); + assertEquals("Invalid expression 'attribute out-2': Expected string input, but no input is provided", e.getMessage()); } } @@ -86,8 +86,8 @@ public void failsWhenAllStatementIsMissingInput() { exp.verify(input); fail("Expected exception"); } catch (VerificationException e) { - assertEquals(e.getExpressionType(), ScriptExpression.class); - assertEquals("Invalid expression '{ attribute out-2; }': Expected input, but no input is specified", e.getMessage()); + assertEquals(AttributeExpression.class, e.getExpressionType()); + assertEquals("Invalid expression 'attribute out-2': Expected string input, but no input is provided", e.getMessage()); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java index 781493392576..a210def9b2cc 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/EchoTestCase.java @@ -10,8 +10,9 @@ import java.io.PrintStream; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; -import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; /** * @author Simon Thoresen Hult @@ -53,6 +54,6 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new EchoExpression(); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'echo': Expected input, but no input is specified", null, exp); } + } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java index 42df0bbefb8e..58f09e7bab5e 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java @@ -53,7 +53,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ForEachExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)); assertVerify(DataType.getArray(DataType.INT), exp, DataType.getArray(DataType.STRING)); - assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Expected Array, Struct, WeightedSet or Map input, got no value", null, exp); assertVerifyThrows("Invalid expression 'for_each { SimpleExpression }': Expected Array, Struct, WeightedSet or Map input, got int", DataType.INT, exp); assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.getArray(DataType.STRING), exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java index 79e74a82efc2..c715b08e59b9 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldTestCase.java @@ -44,7 +44,7 @@ public void requireThatExpressionCanBeVerified() { type.addField(new Field("foo", DataType.STRING)); Expression exp = new GetFieldExpression("foo"); assertVerify(type, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'get_field foo': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'get_field foo': Expected a struct or map, but got no value", null, exp); assertVerifyThrows("Invalid expression 'get_field foo': Expected a struct or map, but got int", DataType.INT, exp); assertVerifyThrows("Invalid expression 'get_field bar': Field 'bar' not found in struct type 'my_struct'", type, new GetFieldExpression("bar")); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java index 2d1aa7d4897a..72e58f4e57bc 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/JoinTestCase.java @@ -9,7 +9,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult @@ -36,7 +38,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new JoinExpression(";"); assertVerify(DataType.getArray(DataType.INT), exp, DataType.STRING); assertVerify(DataType.getArray(DataType.STRING), exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'join \";\"': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'join \";\"': Expected Array input, got no value", null, exp); assertVerifyThrows("Invalid expression 'join \";\"': Expected Array input, got type int", DataType.INT, exp); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java index 6af111cf96f8..66b34e5109dc 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java @@ -39,7 +39,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new SetVarExpression("foo"); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'set_var foo': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'set_var foo': Expected input, but no input is provided", null, exp); try { new VerificationContext(new SimpleTestAdapter()).setVariable("foo", DataType.INT).setCurrentType(DataType.STRING).verify(exp); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java index 1bef3c716f98..a01d200e1ce1 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ThisTestCase.java @@ -29,7 +29,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ThisExpression(); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'this': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'this': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java index dd0d6995e022..916d9ea7dfed 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayTestCase.java @@ -33,7 +33,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToArrayExpression(); assertVerify(DataType.INT, exp, DataType.getArray(DataType.INT)); assertVerify(DataType.STRING, exp, DataType.getArray(DataType.STRING)); - assertVerifyThrows("Invalid expression 'to_array': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_array': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java index a0fea4ad33e9..3fe5dd8778d8 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolTestCase.java @@ -33,7 +33,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToBoolExpression(); assertVerify(DataType.INT, exp, DataType.BOOL); assertVerify(DataType.STRING, exp, DataType.BOOL); - assertVerifyThrows("Invalid expression 'to_bool': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_bool': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java index 3a02b237fd2c..341f1e9c92ff 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -30,7 +32,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToByteExpression(); assertVerify(DataType.INT, exp, DataType.BYTE); assertVerify(DataType.STRING, exp, DataType.BYTE); - assertVerifyThrows("Invalid expression 'to_byte': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_byte': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java index ed67eba39cfa..07d5b0ddeb5f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -30,7 +32,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToDoubleExpression(); assertVerify(DataType.INT, exp, DataType.DOUBLE); assertVerify(DataType.STRING, exp, DataType.DOUBLE); - assertVerifyThrows("Invalid expression 'to_double': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_double': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java index 3d1b9c6ab778..cf9a124128e1 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -30,7 +32,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToFloatExpression(); assertVerify(DataType.INT, exp, DataType.FLOAT); assertVerify(DataType.STRING, exp, DataType.FLOAT); - assertVerifyThrows("Invalid expression 'to_float': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_float': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java index db9e8fec11a5..a182f40e829a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -30,7 +32,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToIntegerExpression(); assertVerify(DataType.INT, exp, DataType.INT); assertVerify(DataType.STRING, exp, DataType.INT); - assertVerifyThrows("Invalid expression 'to_int': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_int': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java index 9497c81eeaea..b047edc0eb12 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -30,7 +32,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToLongExpression(); assertVerify(DataType.INT, exp, DataType.LONG); assertVerify(DataType.STRING, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'to_long': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_long': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java index 6b92540fdadf..e73e604c1cc4 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringTestCase.java @@ -10,7 +10,9 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult @@ -30,7 +32,7 @@ public void requireThatExpressionCanBeVerified() { Expression exp = new ToStringExpression(); assertVerify(DataType.INT, exp, DataType.STRING); assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'to_string': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'to_string': Expected input, but no input is provided", null, exp); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java index 031dd926ab5c..ca5c207a7b86 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetTestCase.java @@ -61,7 +61,7 @@ private static void assertVerify(boolean createIfNonExistent, boolean removeIfZe ExpressionAssert.assertVerify(DataType.STRING, expression, DataType.getWeightedSet(DataType.STRING, createIfNonExistent, removeIfZero)); assertVerifyThrows("Invalid expression '" + expression + "': " + - "Expected input, but no input is specified", null, expression); + "Expected input, but no input is provided", null, expression); } private static void assertConvert(boolean createIfNonExistent, boolean removeIfZero) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java index 11c012d162de..c14b74694a45 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveTestCase.java @@ -29,7 +29,7 @@ public void requireThatHashCodeAndEqualsAreImplemented() { public void requireThatExpressionCanBeVerified() { Expression exp = new ZCurveExpression(); assertVerify(PositionDataType.INSTANCE, exp, DataType.LONG); - assertVerifyThrows("Invalid expression 'zcurve': Expected input, but no input is specified", null, exp); + assertVerifyThrows("Invalid expression 'zcurve': Expected input, but no input is provided", null, exp); assertVerifyThrows("Invalid expression 'zcurve': This requires a struct as input, but got int", DataType.INT, exp); } From b64ce9d34e20dff618b4247f880b552c9f665b8f Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 5 Dec 2024 00:01:41 +0100 Subject: [PATCH 6/8] Remove construction time type checking --- .../expressions/ArithmeticExpression.java | 12 ----- .../expressions/Base64DecodeExpression.java | 5 -- .../expressions/Base64EncodeExpression.java | 4 -- .../expressions/BinarizeExpression.java | 1 - .../expressions/BusyWaitExpression.java | 4 -- .../expressions/CatExpression.java | 39 ++-------------- .../expressions/ChoiceExpression.java | 25 +--------- .../expressions/ClearStateExpression.java | 4 -- .../expressions/CompositeExpression.java | 5 -- .../expressions/ConstantExpression.java | 1 - .../expressions/EchoExpression.java | 1 - .../expressions/EmbedExpression.java | 1 - .../expressions/ExactExpression.java | 1 - .../expressions/ExecutionValueExpression.java | 12 ----- .../expressions/Expression.java | 33 ++++--------- .../expressions/ExpressionList.java | 7 +-- .../expressions/FlattenExpression.java | 4 -- .../expressions/ForEachExpression.java | 1 - .../expressions/GetFieldExpression.java | 1 - .../expressions/GetVarExpression.java | 1 - .../expressions/GuardExpression.java | 1 - .../expressions/HashExpression.java | 4 -- .../expressions/HexDecodeExpression.java | 4 -- .../expressions/HexEncodeExpression.java | 4 -- .../expressions/HostNameExpression.java | 5 +- .../expressions/IfThenExpression.java | 46 ++++--------------- .../expressions/InputExpression.java | 1 - .../expressions/JoinExpression.java | 1 - .../expressions/LiteralBoolExpression.java | 2 - .../expressions/LowerCaseExpression.java | 4 -- .../expressions/NGramExpression.java | 1 - .../expressions/NormalizeExpression.java | 3 +- .../expressions/NowExpression.java | 1 - .../OptimizePredicateExpression.java | 1 - .../expressions/OutputExpression.java | 1 - .../expressions/PackBitsExpression.java | 5 -- .../expressions/ParenthesisExpression.java | 1 - .../expressions/RandomExpression.java | 1 - .../expressions/ScriptExpression.java | 16 +------ .../expressions/SelectInputExpression.java | 1 - .../expressions/SetLanguageExpression.java | 4 -- .../expressions/SetVarExpression.java | 1 - .../expressions/SleepExpression.java | 4 -- .../expressions/SplitExpression.java | 1 - .../expressions/StatementExpression.java | 13 +----- .../expressions/SubstringExpression.java | 1 - .../expressions/SwitchExpression.java | 1 - .../expressions/ThisExpression.java | 4 -- .../expressions/ToArrayExpression.java | 4 -- .../expressions/ToBoolExpression.java | 4 -- .../expressions/ToByteExpression.java | 4 -- .../expressions/ToDoubleExpression.java | 4 -- .../expressions/ToEpochSecondExpression.java | 5 +- .../expressions/ToFloatExpression.java | 4 -- .../expressions/ToIntegerExpression.java | 4 -- .../expressions/ToLongExpression.java | 4 -- .../expressions/ToPositionExpression.java | 5 -- .../expressions/ToStringExpression.java | 4 -- .../expressions/ToWsetExpression.java | 1 - .../expressions/TokenizeExpression.java | 1 - .../expressions/TrimExpression.java | 4 -- .../expressions/ZCurveExpression.java | 4 -- .../expressions/ArithmeticTestCase.java | 10 +--- .../expressions/CatTestCase.java | 3 -- .../expressions/ExpressionAssert.java | 2 + .../expressions/ExpressionTestCase.java | 8 ---- .../expressions/ForEachTestCase.java | 3 -- .../expressions/IfThenTestCase.java | 21 --------- .../expressions/ScriptTestCase.java | 18 -------- .../expressions/SimpleExpression.java | 2 +- .../expressions/SwitchTestCase.java | 1 - 71 files changed, 34 insertions(+), 380 deletions(-) diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java index 738566eb885e..93b809f2b7a6 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java @@ -54,7 +54,6 @@ public String toString() { private final Expression right; public ArithmeticExpression(Expression left, Operator op, Expression right) { - super(requiredInputType(left, right)); this.left = Objects.requireNonNull(left); this.op = Objects.requireNonNull(op); this.right = Objects.requireNonNull(right); @@ -127,17 +126,6 @@ protected void doExecute(ExecutionContext context) { context.setCurrentValue(input).execute(right).getCurrentValue())); } - private static DataType requiredInputType(Expression left, Expression right) { - DataType leftType = left.requiredInputType(); - DataType rightType = right.requiredInputType(); - if (leftType == null) return rightType; - if (rightType == null) return leftType; - if (!leftType.equals(rightType)) - throw new VerificationException(ArithmeticExpression.class, "Operands require conflicting input types, " + - leftType.getName() + " vs " + rightType.getName()); - return leftType; - } - @Override public DataType createdOutputType() { return UnresolvedDataType.INSTANCE; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeExpression.java index 4ffd3befed52..ebe61bcdf390 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeExpression.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; -import com.yahoo.document.TensorDataType; import com.yahoo.document.datatypes.LongFieldValue; import java.util.Base64; @@ -12,10 +11,6 @@ */ public final class Base64DecodeExpression extends Expression { - public Base64DecodeExpression() { - super(DataType.STRING); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, DataType.STRING, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeExpression.java index 9516833892be..e8a4621de9c2 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64EncodeExpression.java @@ -12,10 +12,6 @@ */ public final class Base64EncodeExpression extends Expression { - public Base64EncodeExpression() { - super(DataType.LONG); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, DataType.LONG, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BinarizeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BinarizeExpression.java index 22d2b2d883a0..a6401701afc2 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BinarizeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BinarizeExpression.java @@ -27,7 +27,6 @@ public class BinarizeExpression extends Expression { * @param threshold the value which the tensor cell value must be larger than to be set to 1 and not 0. */ public BinarizeExpression(double threshold) { - super(TensorDataType.any()); this.threshold = threshold; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BusyWaitExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BusyWaitExpression.java index a8d20866555a..6483dd62f238 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BusyWaitExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/BusyWaitExpression.java @@ -12,10 +12,6 @@ */ public final class BusyWaitExpression extends Expression { - public BusyWaitExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override protected void doExecute(ExecutionContext context) { FieldValue value = context.getCurrentValue(); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java index ba39ad62d2ef..09ba23d9c483 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java @@ -28,7 +28,7 @@ public CatExpression(Expression... expressions) { } public CatExpression(Collection expressions) { - super(expressions, resolveInputType(expressions)); + super(expressions); } @Override @@ -83,48 +83,15 @@ protected void doVerify(VerificationContext context) { @Override protected void doExecute(ExecutionContext context) { FieldValue input = context.getCurrentValue(); - DataType inputType = input != null ? input.getDataType() : null; -// VerificationContext verificationContext = new VerificationContext(context.getFieldValue()); -// context.fillVariableTypes(verificationContext); List values = new LinkedList<>(); -// List types = new LinkedList<>(); - for (Expression expression : this) { - FieldValue val = context.setCurrentValue(input).execute(expression).getCurrentValue(); - values.add(val); -/* - DataType type; - if (val != null) { - type = val.getDataType(); - } else { - type = verificationContext.setCurrentType(inputType).verify(this).getCurrentType(); - } - types.add(type); - - */ - } -// DataType type = resolveOutputType(types); + for (Expression expression : this) + values.add(context.setCurrentValue(input).execute(expression).getCurrentValue()); DataType type = getOutputType(); if (type == null) throw new RuntimeException("Output type is not resolved in " + this); context.setCurrentValue(type == DataType.STRING ? asString(values) : asCollection(type, values)); } - private static DataType resolveInputType(Collection list) { - DataType prev = null; - for (Expression exp : list) { - DataType next = exp.requiredInputType(); - if (next == null) { - // ignore - } else if (prev == null) { - prev = next; - } else if (!prev.isAssignableFrom(next)) { - throw new VerificationException(CatExpression.class, "Operands require conflicting input types, " + - prev.getName() + " vs " + next.getName()); - } - } - return prev; - } - @Override public DataType createdOutputType() { return UnresolvedDataType.INSTANCE; 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 ef362b527d6d..7a2f15d829af 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 @@ -1,12 +1,10 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.vespa.indexinglanguage.ExpressionConverter; -import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -30,7 +28,7 @@ public ChoiceExpression(Expression... choices) { } public ChoiceExpression(Collection choices) { - super(choices, resolveInputType(choices)); + super(choices); } @Override @@ -84,27 +82,6 @@ protected void doExecute(ExecutionContext context) { } } - private static DataType resolveInputType(Collection list) { - DataType previousInput = null; - DataType previousOutput = null; - for (Expression choice : list) { - DataType thisInput = choice.requiredInputType(); - if (previousInput == null) - previousInput = thisInput; - else if (thisInput != null && !previousInput.isAssignableFrom(thisInput)) - throw new VerificationException(ScriptExpression.class, "Choice expression require conflicting input types, " + - previousInput.getName() + " vs " + thisInput.getName()); - - DataType thisOutput = choice.createdOutputType(); - if (previousOutput == null) - previousOutput = thisOutput; - else if (thisOutput != null && !previousOutput.isAssignableFrom(thisOutput)) - throw new VerificationException(ScriptExpression.class, "Choice expression produce conflicting output types, " + - previousOutput.getName() + " vs " + thisOutput.getName()); - } - return previousInput; - } - @Override public DataType createdOutputType() { return UnresolvedDataType.INSTANCE; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java index 5c41ee3058c1..051888daa1ee 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java @@ -8,10 +8,6 @@ */ public final class ClearStateExpression extends Expression { - public ClearStateExpression() { - super(null); - } - @Override public boolean requiresInput() { return false; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java index df1ec9e39b44..ec4bb409e241 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.DataType; import com.yahoo.vespa.indexinglanguage.ExpressionConverter; /** @@ -12,10 +11,6 @@ public abstract class CompositeExpression extends Expression { @Override public abstract CompositeExpression convertChildren(ExpressionConverter converter); - protected CompositeExpression(DataType inputType) { - super(inputType); - } - protected static String toScriptBlock(Expression exp) { if (exp instanceof ScriptExpression) return exp.toString(); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java index 00a761c1a39a..792b84a524b8 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java @@ -17,7 +17,6 @@ public final class ConstantExpression extends Expression { private final FieldValue value; public ConstantExpression(FieldValue value) { - super(null); this.value = Objects.requireNonNull(value); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java index 173f086d9231..1f22989b21cf 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java @@ -17,7 +17,6 @@ public EchoExpression() { } public EchoExpression(PrintStream out) { - super(UnresolvedDataType.INSTANCE); this.out = out; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java index 71e471b03a66..a0bbad879d1b 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java @@ -39,7 +39,6 @@ public class EmbedExpression extends Expression { private TensorType targetType; public EmbedExpression(Linguistics linguistics, Map embedders, String embedderId, List embedderArguments) { - super(null); this.linguistics = linguistics; this.embedderId = embedderId; this.embedderArguments = List.copyOf(embedderArguments); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExactExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExactExpression.java index c0eaf8e5ede2..cb1df30983d7 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExactExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExactExpression.java @@ -26,7 +26,6 @@ public final class ExactExpression extends Expression { private final int maxTokenLength; private ExactExpression(OptionalInt maxTokenLength) { - super(DataType.STRING); this.maxTokenLength = maxTokenLength.isPresent() ? maxTokenLength.getAsInt() : AnnotatorConfig.getDefaultMaxTokenLength(); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java index 363f08ddb07e..0292b638f8f3 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java @@ -2,14 +2,6 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; -import com.yahoo.document.DocumentType; -import com.yahoo.document.FieldPath; -import com.yahoo.vespa.objects.ObjectOperation; -import com.yahoo.vespa.objects.ObjectPredicate; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; /** * Returns the current execution value, that is the value passed to this expression. @@ -20,10 +12,6 @@ */ public final class ExecutionValueExpression extends Expression { - public ExecutionValueExpression() { - super(null); - } - @Override protected void doExecute(ExecutionContext context) { // Noop: Set the output execution value to the current execution value diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java index 194f2ee61877..1320776cf8c9 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Expression.java @@ -36,23 +36,10 @@ */ public abstract class Expression extends Selectable { - private final DataType requiredInputType; - // Input and output types resolved during verification private DataType inputType; private DataType outputType; - /** - * Creates an expression - * - * @param requiredInputType the type of the input this expression can work with. - * UnresolvedDataType.INSTANCE if it works with any type, - * and null if it does not consume any input. - */ - protected Expression(DataType requiredInputType) { - this.requiredInputType = requiredInputType; - } - /** Returns whether this expression requires an input value. */ public boolean requiresInput() { return true; } @@ -65,8 +52,6 @@ protected Expression(DataType requiredInputType) { /** Sets the document type and field the statement this expression is part of will write to */ public void setStatementOutput(DocumentType documentType, Field field) {} - public final DataType requiredInputType() { return requiredInputType; } - public DataType getInputType(VerificationContext context) { return inputType; } /** @@ -255,15 +240,9 @@ public final FieldValue execute(FieldValueAdapter adapter) { } public final FieldValue execute(ExecutionContext context) { - DataType inputType = requiredInputType(); - if (inputType != null) { + if (requiresInput()) { FieldValue input = context.getCurrentValue(); if (input == null) return null; - - if (!inputType.isValueCompatible(input)) { - throw new IllegalArgumentException("Expression '" + this + "' expected " + inputType.getName() + - " input, got " + input.getDataType().getName()); - } } doExecute(context); DataType outputType = createdOutputType(); @@ -319,12 +298,18 @@ public final FieldValue execute() { protected DataType mostGeneralOf(DataType left, DataType right) { if (left == null || right == null) return null; - return left.isAssignableTo(right) ? right : left; + if (left.isAssignableTo(right)) return right; + if (right.isAssignableTo(left)) return left; + throw new VerificationException(this, "Argument types are incompatible. " + + "First " + left.getName() + ", second: " + right.getName()); } protected DataType leastGeneralOf(DataType left, DataType right) { if (left == null || right == null) return null; - return left.isAssignableTo(right) ? left : right; + if (left.isAssignableTo(right)) return left; + if (right.isAssignableTo(left)) return right; + throw new VerificationException(this, "Argument types are incompatible. " + + "First " + left.getName() + ", second: " + right.getName()); } } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java index 929d53177b6c..d6298edbdad4 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.DataType; import com.yahoo.document.DocumentType; import com.yahoo.document.Field; import com.yahoo.vespa.indexinglanguage.ExpressionConverter; @@ -21,11 +20,9 @@ public abstract class ExpressionList extends CompositeExpr private final List expressions = new ArrayList(); - protected ExpressionList(Iterable expressions, DataType inputType) { - super(inputType); - for (T exp : expressions) { + protected ExpressionList(Iterable expressions) { + for (T exp : expressions) this.expressions.add(exp); - } } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenExpression.java index 255f35b926e3..320f3abdf1d3 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FlattenExpression.java @@ -24,10 +24,6 @@ // TODO: Remove on Vespa 9 public final class FlattenExpression extends Expression { - public FlattenExpression() { - super(DataType.STRING); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { return super.setInputType(inputType, DataType.STRING, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java index 0bb85449a04f..f29661a902ab 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java @@ -29,7 +29,6 @@ public final class ForEachExpression extends CompositeExpression { private final Expression expression; public ForEachExpression(Expression expression) { - super(UnresolvedDataType.INSTANCE); this.expression = Objects.requireNonNull(expression); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java index 1aa88c591610..28fd1ac59b03 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetFieldExpression.java @@ -22,7 +22,6 @@ public final class GetFieldExpression extends Expression { private final String structFieldName; public GetFieldExpression(String structFieldName) { - super(UnresolvedDataType.INSTANCE); this.structFieldName = structFieldName; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java index 01f9fa13f17c..4e9f52f5c87a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GetVarExpression.java @@ -11,7 +11,6 @@ public final class GetVarExpression extends Expression { private final String variableName; public GetVarExpression(String variableName) { - super(null); this.variableName = variableName; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java index 50a1b4cb9bd7..e92dc4278af1 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java @@ -19,7 +19,6 @@ public final class GuardExpression extends CompositeExpression { private final boolean shouldExecute; public GuardExpression(Expression innerExpression) { - super(innerExpression.requiredInputType()); this.innerExpression = innerExpression; shouldExecute = shouldExecute(innerExpression); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java index fdebde6c4945..c6a52f986f7f 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java @@ -23,10 +23,6 @@ public class HashExpression extends Expression { private DataType targetType; - public HashExpression() { - super(DataType.STRING); - } - @Override public void setStatementOutput(DocumentType documentType, Field field) { targetType = field.getDataType(); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeExpression.java index 16d9487690f2..9092c4594211 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexDecodeExpression.java @@ -13,10 +13,6 @@ public final class HexDecodeExpression extends Expression { private static final BigInteger ULONG_MAX = new BigInteger("18446744073709551616"); - public HexDecodeExpression() { - super(DataType.STRING); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, DataType.STRING, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java index bb89ca144124..5754efab20c4 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HexEncodeExpression.java @@ -10,10 +10,6 @@ */ public final class HexEncodeExpression extends Expression { - public HexEncodeExpression() { - super(DataType.LONG); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, DataType.LONG, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java index 98ca6249a46e..53d650f60e22 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameExpression.java @@ -3,6 +3,7 @@ import com.yahoo.document.DataType; import com.yahoo.document.datatypes.StringFieldValue; + import static com.yahoo.vespa.defaults.Defaults.getDefaults; /** @@ -10,10 +11,6 @@ */ public final class HostNameExpression extends Expression { - public HostNameExpression() { - super(null); - } - @Override public boolean requiresInput() { return false; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java index 9e4dc54a37ad..a2af300a0de0 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenExpression.java @@ -49,7 +49,6 @@ public IfThenExpression(Expression lhs, Comparator cmp, Expression right, Expres } public IfThenExpression(Expression lhs, Comparator cmp, Expression right, Expression ifTrue, Expression ifFalse) { - super(resolveInputType(lhs, right, ifTrue, ifFalse)); this.left = lhs; this.comparator = cmp; this.right = right; @@ -76,21 +75,21 @@ public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); left.setInputType(inputType, context); right.setInputType(inputType, context); - var trueOutputType = ifTrue.setInputType(inputType, context); - var falseOutputType = ifFalse.setInputType(inputType, context); - DataType output = mostGeneralOf(trueOutputType, falseOutputType); - return output != null ? output : getOutputType(context); + var outputType = ifTrue.setInputType(inputType, context); + if (ifFalse != null) + outputType = mostGeneralOf(outputType, ifFalse.setInputType(inputType, context)); + return outputType != null ? outputType : getOutputType(context); } @Override public DataType setOutputType(DataType outputType, VerificationContext context) { super.setOutputType(outputType, context); - left.setOutputType(AnyDataType.instance, context); - right.setOutputType(AnyDataType.instance, context); - var trueInputType = ifTrue.setOutputType(outputType, context); - var falseInputType = ifFalse.setOutputType(outputType, context); - DataType input = leastGeneralOf(trueInputType, falseInputType); - return input != null ? input : getInputType(context); + var inputType = left.setOutputType(AnyDataType.instance, context); + inputType = leastGeneralOf(inputType, right.setOutputType(AnyDataType.instance, context)); + inputType = leastGeneralOf(inputType, ifTrue.setOutputType(outputType, context)); + if (ifFalse != null) + inputType = leastGeneralOf(inputType, ifFalse.setOutputType(outputType, context)); + return inputType != null ? inputType : getInputType(context); } @Override @@ -150,17 +149,6 @@ public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) select(ifFalse, predicate, operation); } - private static DataType resolveInputType(Expression lhs, Expression rhs, Expression ifTrue, Expression ifFalse) { - DataType input = null; - input = resolveRequiredInputType(input, lhs.requiredInputType()); - input = resolveRequiredInputType(input, rhs.requiredInputType()); - input = resolveRequiredInputType(input, ifTrue.requiredInputType()); - if (ifFalse != null) { - input = resolveRequiredInputType(input, ifFalse.requiredInputType()); - } - return input; - } - @Override public DataType createdOutputType() { DataType ifTrueType = ifTrue.createdOutputType(); @@ -203,20 +191,6 @@ public int hashCode() { return ret; } - private static DataType resolveRequiredInputType(DataType prev, DataType next) { - if (next == null) { - return prev; - } - if (prev == null) { - return next; - } - if (!prev.equals(next)) { - throw new VerificationException(IfThenExpression.class, "Operands require conflicting input types, " + - prev.getName() + " vs " + next.getName()); - } - return prev; - } - private static boolean isTrue(FieldValue left, Comparator comparator, FieldValue right) { int res; if (left instanceof NumericFieldValue && right instanceof NumericFieldValue) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java index e39b3a0f30b5..81d262808a4d 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/InputExpression.java @@ -19,7 +19,6 @@ public final class InputExpression extends Expression { private FieldPath fieldPath; public InputExpression(String fieldName) { - super(null); if (fieldName == null) throw new IllegalArgumentException("'input' must be given a field name as argument"); this.fieldName = fieldName; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java index 4273c82c6b16..a5e5e5479918 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/JoinExpression.java @@ -18,7 +18,6 @@ public final class JoinExpression extends Expression { private final String delimiter; public JoinExpression(String delimiter) { - super(UnresolvedDataType.INSTANCE); this.delimiter = delimiter; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java index 3c89c8fa352b..7fa1443aad67 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.indexinglanguage.expressions; -import com.yahoo.document.ArrayDataType; import com.yahoo.document.DataType; import com.yahoo.document.datatypes.BoolFieldValue; @@ -15,7 +14,6 @@ public class LiteralBoolExpression extends Expression { private final boolean value; public LiteralBoolExpression(boolean value) { - super(null); this.value = value; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseExpression.java index 66a9ac57038e..2a94f785a404 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LowerCaseExpression.java @@ -11,10 +11,6 @@ */ public final class LowerCaseExpression extends Expression { - public LowerCaseExpression() { - super(DataType.STRING); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { return super.setInputType(inputType, DataType.STRING, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NGramExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NGramExpression.java index 9abcc400d29c..7621906cfee5 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NGramExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NGramExpression.java @@ -34,7 +34,6 @@ public final class NGramExpression extends Expression { * @param gramSize the gram size */ public NGramExpression(Linguistics linguistics, int gramSize) { - super(DataType.STRING); this.linguistics = linguistics; this.gramSize = gramSize; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeExpression.java index f866f9142301..2c6b5d1953ff 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NormalizeExpression.java @@ -6,8 +6,8 @@ import com.yahoo.language.Linguistics; import com.yahoo.language.process.Transformer; -import java.util.logging.Logger; import java.util.logging.Level; +import java.util.logging.Logger; /** * @author Simon Thoresen Hult @@ -18,7 +18,6 @@ public final class NormalizeExpression extends Expression { private static final Logger logger = Logger.getLogger(NormalizeExpression.class.getName()); public NormalizeExpression(Linguistics linguistics) { - super(DataType.STRING); this.linguistics = linguistics; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java index 40bd820e8ef0..50ade192e4b9 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java @@ -16,7 +16,6 @@ public NowExpression() { } public NowExpression(Timer timer) { - super(null); this.timer = timer; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateExpression.java index bb4494e43a9f..4d1e60cc5a84 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OptimizePredicateExpression.java @@ -25,7 +25,6 @@ public OptimizePredicateExpression() { } OptimizePredicateExpression(PredicateProcessor optimizer) { - super(DataType.PREDICATE); this.optimizer = optimizer; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OutputExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OutputExpression.java index 19c8c451d657..e6682045366c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OutputExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/OutputExpression.java @@ -17,7 +17,6 @@ public abstract class OutputExpression extends Expression { private final String fieldName; public OutputExpression(String image, String fieldName) { - super(UnresolvedDataType.INSTANCE); this.image = image; this.fieldName = fieldName; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java index 9415cd2a1898..5c71cb24691a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java @@ -21,11 +21,6 @@ public class PackBitsExpression extends Expression { private TensorType outputTensorType; - /** Creates a pack_bits expression. */ - public PackBitsExpression() { - super(TensorDataType.any()); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java index 9ec94ad939b9..19b53074af04 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ParenthesisExpression.java @@ -16,7 +16,6 @@ public class ParenthesisExpression extends CompositeExpression { private final Expression innerExpression; public ParenthesisExpression(Expression innerExpression) { - super(innerExpression.requiredInputType()); this.innerExpression = innerExpression; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java index 565495e66665..ee60a16a0e7e 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java @@ -19,7 +19,6 @@ public RandomExpression() { } public RandomExpression(Integer max) { - super(null); this.max = max; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java index 1c4e097b1f8a..4d18287dfd69 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptExpression.java @@ -32,7 +32,7 @@ public ScriptExpression(StatementExpression... statements) { } public ScriptExpression(Collection statements) { - super(statements, resolveInputType(statements)); + super(statements); } @Override @@ -88,20 +88,6 @@ private boolean containsAtLeastOneInputFrom(List inputFields, ExecutionC return false; } - private static DataType resolveInputType(Collection list) { - DataType prev = null; - for (Expression exp : list) { - DataType next = exp.requiredInputType(); - if (prev == null) { - prev = next; - } else if (next != null && !prev.isAssignableFrom(next)) { - throw new VerificationException(ScriptExpression.class, "Statements require conflicting input types, " + - prev.getName() + " vs " + next.getName()); - } - } - return prev; - } - @Override public DataType createdOutputType() { var expressions = asList(); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java index 4c2e568baa6e..d370ece96031 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputExpression.java @@ -27,7 +27,6 @@ public SelectInputExpression(Pair... cases) { } public SelectInputExpression(List> cases) { - super(null); this.cases = cases; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageExpression.java index 48095eacead0..2e419db14348 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetLanguageExpression.java @@ -11,10 +11,6 @@ */ public final class SetLanguageExpression extends Expression { - public SetLanguageExpression() { - super(DataType.STRING); - } - @Override public DataType setInputType(DataType inputType, VerificationContext context) { return super.setInputType(inputType, DataType.STRING, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java index 85f2e6d90943..0e8e9bc6dd42 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java @@ -11,7 +11,6 @@ public final class SetVarExpression extends Expression { private final String varName; public SetVarExpression(String varName) { - super(UnresolvedDataType.INSTANCE); this.varName = varName; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java index cc43506539a1..54174868ba99 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java @@ -12,10 +12,6 @@ */ public final class SleepExpression extends Expression { - public SleepExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override protected void doVerify(VerificationContext context) { } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java index 3f2fe7d7b8e3..9ddf718f720b 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java @@ -17,7 +17,6 @@ public final class SplitExpression extends Expression { private final Pattern splitPattern; public SplitExpression(String splitString) { - super(DataType.STRING); this.splitPattern = Pattern.compile(splitString); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java index 7db7295c8371..d18b42f3e255 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/StatementExpression.java @@ -37,7 +37,7 @@ public StatementExpression(Iterable list) { } private StatementExpression(Iterable list, Object unused) { - super(list, resolveInputType(list)); + super(list); inputFields = List.copyOf(InputExpression.InputFieldNameExtractor.runOn(this)); } @@ -123,17 +123,6 @@ private String outputFieldName() { return null; } - private static DataType resolveInputType(Iterable expressions) { - for (Expression expression : expressions) { - DataType type = expression.requiredInputType(); - if (type != null) return type; - - type = expression.createdOutputType(); - if (type != null) return null; - } - return null; - } - @Override public DataType createdOutputType() { for (int i = size(); --i >= 0; ) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringExpression.java index 36a34c4f887e..fa239a13a9c8 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SubstringExpression.java @@ -14,7 +14,6 @@ public final class SubstringExpression extends Expression { private final int to; public SubstringExpression(int from, int to) { - super(DataType.STRING); if (from < 0 || to < 0 || to < from) { throw new IndexOutOfBoundsException(); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchExpression.java index 8bfd11681a16..38a7c720b4e8 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchExpression.java @@ -30,7 +30,6 @@ public SwitchExpression(Map cases) { } public SwitchExpression(Map cases, Expression defaultExp) { - super(null); this.defaultExp = defaultExp; this.cases.putAll(cases); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java index 0065c398abd5..31a0d862b9c5 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java @@ -8,10 +8,6 @@ */ public final class ThisExpression extends Expression { - public ThisExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override protected void doVerify(VerificationContext context) { if (context.getCurrentType() == null) diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java index 377ca7741a70..c89860474935 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java @@ -11,10 +11,6 @@ */ public final class ToArrayExpression extends Expression { - public ToArrayExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java index 38c211bf6320..2d388453ab8a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToBoolExpression.java @@ -13,10 +13,6 @@ */ public final class ToBoolExpression extends Expression { - public ToBoolExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java index 9670c3ae1a84..d50be545101c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToByteExpression.java @@ -9,10 +9,6 @@ */ public final class ToByteExpression extends Expression { - public ToByteExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java index 1e4dc3909cd5..627d6b3ca2f5 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToDoubleExpression.java @@ -9,10 +9,6 @@ */ public final class ToDoubleExpression extends Expression { - public ToDoubleExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpression.java index 88628879626a..03b00890407a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToEpochSecondExpression.java @@ -3,6 +3,7 @@ import com.yahoo.document.DataType; import com.yahoo.document.datatypes.LongFieldValue; + import java.time.Instant; /** @@ -12,10 +13,6 @@ */ public class ToEpochSecondExpression extends Expression { - public ToEpochSecondExpression() { - super(DataType.STRING); //only accept string input - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, DataType.STRING, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java index 0331bef4acdf..6b7ce8f5edec 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToFloatExpression.java @@ -9,10 +9,6 @@ */ public final class ToFloatExpression extends Expression { - public ToFloatExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java index 6fbe01c6cc28..11a4f433d09d 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToIntegerExpression.java @@ -9,10 +9,6 @@ */ public final class ToIntegerExpression extends Expression { - public ToIntegerExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java index 0c4d2ba9f95d..9acd89dec529 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToLongExpression.java @@ -9,10 +9,6 @@ */ public final class ToLongExpression extends Expression { - public ToLongExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionExpression.java index 776714db6eab..60fa8bfb38c8 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToPositionExpression.java @@ -3,17 +3,12 @@ import com.yahoo.document.DataType; import com.yahoo.document.PositionDataType; -import com.yahoo.document.PrimitiveDataType; /** * @author Simon Thoresen Hult */ public final class ToPositionExpression extends Expression { - public ToPositionExpression() { - super(DataType.STRING); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, DataType.STRING, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java index 268ccc2d91fd..60871a770aba 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToStringExpression.java @@ -9,10 +9,6 @@ */ public final class ToStringExpression extends Expression { - public ToStringExpression() { - super(UnresolvedDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { super.setInputType(input, context); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java index 2fea3e8410a5..66a1abf6aceb 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToWsetExpression.java @@ -15,7 +15,6 @@ public final class ToWsetExpression extends Expression { private final Boolean removeIfZero; public ToWsetExpression(boolean createIfNonExistent, boolean removeIfZero) { - super(UnresolvedDataType.INSTANCE); this.createIfNonExistent = createIfNonExistent; this.removeIfZero = removeIfZero; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeExpression.java index c993dff65974..f7e14887a508 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TokenizeExpression.java @@ -18,7 +18,6 @@ public final class TokenizeExpression extends Expression { private final AnnotatorConfig config; public TokenizeExpression(Linguistics linguistics, AnnotatorConfig config) { - super(DataType.STRING); this.linguistics = linguistics; this.config = config; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TrimExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TrimExpression.java index b22fcefda471..2fb8857ac478 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TrimExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/TrimExpression.java @@ -9,10 +9,6 @@ */ public final class TrimExpression extends Expression { - public TrimExpression() { - super(DataType.STRING); - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java index 2430b2da74f6..375b38aa0bdd 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ZCurveExpression.java @@ -14,10 +14,6 @@ */ public final class ZCurveExpression extends Expression { - public ZCurveExpression() { - super(PositionDataType.INSTANCE); - } - @Override public DataType setInputType(DataType input, VerificationContext context) { if (input == null) return null; diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java index 7cf0fc9b06fe..a2b2d960463c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticTestCase.java @@ -73,15 +73,6 @@ public void requireThatVerifyCallsAreForwarded() { "The first argument must be a number, but has type string"); } - @Test - public void requireThatOperandsAreInputCompatible() { - assertVerify(new SimpleExpression(DataType.INT), Operator.ADD, - new SimpleExpression(DataType.INT), DataType.INT); - assertVerifyThrows(new SimpleExpression(DataType.INT), Operator.ADD, - new SimpleExpression(DataType.STRING), null, - "Operands require conflicting input types, int vs string"); - } - @Test public void requireThatResultIsCalculated() { for (int i = 0; i < 50; ++i) { @@ -189,6 +180,7 @@ private static void assertVerifyThrows(Expression lhs, Operator op, Expression r ArithmeticExpression expression = null; try { expression = new ArithmeticExpression(lhs, op, rhs); + expression.setInputType(null, new VerificationContext(new SimpleTestAdapter())); expression.verify(new VerificationContext(new SimpleTestAdapter()).setCurrentType(val)); fail("Expected exception"); } catch (VerificationException e) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java index d7c313b9485a..a656bd5f756d 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/CatTestCase.java @@ -58,9 +58,6 @@ public void expressionCanBeVerified() { assertVerifyThrows(new SimpleExpression().setCreatedOutput(null), new SimpleExpression().setCreatedOutput(DataType.STRING), null, "Invalid expression 'SimpleExpression . SimpleExpression': In SimpleExpression: Attempting to concatenate a null value"); - assertVerifyThrows(new SimpleExpression(DataType.STRING), - new SimpleExpression(DataType.INT), null, - "Invalid expression of type 'CatExpression': Operands require conflicting input types, string vs int"); assertVerifyThrows(new SimpleExpression(DataType.STRING), new SimpleExpression(DataType.STRING), null, "Invalid expression 'SimpleExpression': Expected string input, but no input is provided"); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java index 79f08f49ca80..f75765567bea 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssert.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; +import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import static org.junit.Assert.assertEquals; @@ -34,6 +35,7 @@ public static void assertVerifyThrows(String expectedMessage, DataType valueBefo public static void assertVerifyThrows(String expectedMessage, CreateExpression createExp, VerificationContext context) { try { Expression exp = createExp.create(); + exp = new StatementExpression(new ConstantExpression(new StringFieldValue("test")), exp); exp.verify(context); fail("Expected exception"); } catch (VerificationException e) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java index c70e220194b8..ed862931c3e6 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionTestCase.java @@ -18,14 +18,6 @@ */ public class ExpressionTestCase { - @Test - public void requireThatInputTypeIsCheckedBeforeExecute() { - assertExecute(newRequiredInput(DataType.INT), null); - assertExecute(newRequiredInput(DataType.INT), new IntegerFieldValue(69)); - assertExecuteThrows(newRequiredInput(DataType.INT), new StringFieldValue("foo"), - new IllegalArgumentException("expected int input, got string")); - } - @Test public void requireThatOutputTypeIsCheckedAfterExecute() { assertExecute(newCreatedOutput(DataType.INT, (FieldValue)null), null); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java index 58f09e7bab5e..79f8c81a8c9b 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachTestCase.java @@ -240,9 +240,6 @@ private static class MyCollector extends Expression { List lst = new LinkedList<>(); - MyCollector() { - super(null); - } @Override protected void doExecute(ExecutionContext context) { lst.add(context.getCurrentValue()); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java index d94cb9913004..7c6074a10522 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/IfThenTestCase.java @@ -47,27 +47,6 @@ public void requireThatAccessorsWork() { assertSame(ifFalse, exp.getIfFalseExpression()); } - @Test - public void requireThatRequiredInputTypeCompatibilityIsVerified() { - Expression exp = newRequiredInput(DataType.STRING, Comparator.EQ, DataType.STRING, - DataType.STRING, DataType.STRING); - assertVerify(DataType.STRING, exp, DataType.STRING); - assertVerifyThrows("Invalid expression 'SimpleExpression': Expected string input, but no input is provided", null, exp); - assertVerifyThrows("Invalid expression 'SimpleExpression': Expected string input, got int", DataType.INT, exp); - assertVerifyThrows("Invalid expression of type 'IfThenExpression': Operands require conflicting input types, int vs string", null, () -> newRequiredInput(DataType.INT, Comparator.EQ, DataType.STRING, - DataType.STRING, DataType.STRING) - ); - assertVerifyThrows("Invalid expression of type 'IfThenExpression': Operands require conflicting input types, string vs int", null, () -> newRequiredInput(DataType.STRING, Comparator.EQ, DataType.INT, - DataType.STRING, DataType.STRING) - ); - assertVerifyThrows("Invalid expression of type 'IfThenExpression': Operands require conflicting input types, string vs int", null, () -> newRequiredInput(DataType.STRING, Comparator.EQ, DataType.STRING, - DataType.INT, DataType.STRING) - ); - assertVerifyThrows("Invalid expression of type 'IfThenExpression': Operands require conflicting input types, string vs int", null, () -> newRequiredInput(DataType.STRING, Comparator.EQ, DataType.STRING, - DataType.STRING, DataType.INT) - ); - } - @Test public void requireThatExpressionCanBeVerified() { assertVerify(DataType.STRING, new FlattenExpression(), DataType.STRING); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java index 5c58927a3d93..22d4c77c6497 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ScriptTestCase.java @@ -16,7 +16,6 @@ import java.util.List; -import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -60,17 +59,6 @@ public void requireThatHashCodeAndEqualsAreImplemented() { assertEquals(exp.hashCode(), newScript(foo, bar).hashCode()); } - @Test - public void requireThatExpressionCanBeVerified() { - Expression exp = newScript(newStatement(SimpleExpression.newConversion(DataType.INT, DataType.STRING))); - assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, but no input is provided", null, exp); - assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.STRING, exp); - - assertVerifyThrows("Invalid expression of type 'ScriptExpression': Statements require conflicting input types, int vs string", null, () -> newScript(newStatement(SimpleExpression.newConversion(DataType.INT, DataType.STRING)), - newStatement(SimpleExpression.newConversion(DataType.STRING, DataType.INT))) - ); - } - @Test public void requireThatInputValueIsAvailableToAllStatements() { SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out-1", DataType.INT), @@ -259,10 +247,6 @@ private static StatementExpression newStatement(Expression... args) { private static class ThrowingExpression extends Expression { - public ThrowingExpression() { - super(null); - } - @Override protected void doExecute(ExecutionContext context) { throw new RuntimeException(); @@ -282,7 +266,6 @@ private static class PutCacheExpression extends Expression { private final String valueToSet; public PutCacheExpression(String keyToSet, String valueToSet) { - super(null); this.keyToSet = keyToSet; this.valueToSet = valueToSet; } @@ -306,7 +289,6 @@ private static class AssertCacheExpression extends Expression { private final String expectedValue; public AssertCacheExpression(String expectedKey, String expectedValue) { - super(null); this.expectedKey = expectedKey; this.expectedValue = expectedValue; } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java index 1cea04acca3b..4f4f78b0d658 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java @@ -19,8 +19,8 @@ final class SimpleExpression extends Expression { public SimpleExpression() { this(null); } + public SimpleExpression(DataType requiredInput) { - super(requiredInput); this.requiredInput = requiredInput; } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java index 8827d9c6fc75..c82fc594d447 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java @@ -128,7 +128,6 @@ public void requireThatDefaultExpressionIsExecuted() { Expression exp = new SwitchExpression(cases, defaultExp); assertEvaluate(new StringFieldValue("foo"), exp, new StringFieldValue("bar")); assertEvaluate(new StringFieldValue("baz"), exp, new StringFieldValue("cox")); - assertEvaluate(null, exp, new StringFieldValue("cox")); } private static void assertEvaluate(FieldValue input, Expression exp, FieldValue expectedOutVar) { From 1f5c948a82d6aad7c5271638d9f991f453fdc273 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Fri, 6 Dec 2024 11:53:22 +0100 Subject: [PATCH 7/8] Handle unresolved output everywhere --- .../processing/IndexingInputsTestCase.java | 6 +-- .../expressions/ArithmeticExpression.java | 8 +++- .../expressions/CatExpression.java | 1 + .../expressions/ConstantExpression.java | 3 +- .../expressions/ForEachExpression.java | 1 + .../expressions/HashExpression.java | 2 +- .../expressions/PackBitsExpression.java | 2 +- .../expressions/SetVarExpression.java | 1 + .../expressions/SplitExpression.java | 8 ++-- .../expressions/ToArrayExpression.java | 11 +++--- .../huggingface/HuggingFaceEmbedder.java | 38 +++++++++---------- 11 files changed, 46 insertions(+), 35 deletions(-) diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java index f0e86e8b5826..dcb54f3ebb5b 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java @@ -57,7 +57,7 @@ void requireThatExtraFieldInputImplicitThrows() throws ParseException { } catch (IllegalArgumentException e) { assertEquals("For schema 'indexing_extra_field_input_implicit', field 'foo': " + - "Invalid expression '{ tokenize normalize stem:\"BEST\" | index foo; }': Expected string input, but no input is specified", + "Invalid expression 'tokenize normalize stem:\"BEST\"': Expected string input, but no input is provided", Exceptions.toMessageString(e)); } } @@ -156,8 +156,8 @@ void testNoInputInDerivedField() throws ParseException { fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'test', field 'derived1': Invalid expression '{ attribute derived1; }': " + - "Expected any input, but no input is specified", + assertEquals("For schema 'test', field 'derived1': Invalid expression 'attribute derived1': " + + "Expected int input, but no input is provided", Exceptions.toMessageString(e)); } } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java index 93b809f2b7a6..8016d3d0bf60 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ArithmeticExpression.java @@ -83,15 +83,21 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { + if (outputType == null) return null; super.setOutputType(outputType, context); DataType leftInput = left.setOutputType(AnyNumericDataType.instance, context); DataType rightInput = right.setOutputType(AnyNumericDataType.instance, context); + + if (leftInput == null) return getInputType(context); + if (rightInput == null) return getInputType(context); if (leftInput.isAssignableTo(rightInput)) return rightInput; else if (rightInput.isAssignableTo(leftInput)) return leftInput; else - return getInputType(context); + throw new VerificationException(this, "The left argument requires " + leftInput.getName() + + ", while the right argument requires " + rightInput.getName() + + ": These are incompatible"); } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java index 09ba23d9c483..c9fee28efa6b 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CatExpression.java @@ -54,6 +54,7 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { + if (outputType == null) return null; if (outputType != DataType.STRING && ! (outputType instanceof CollectionDataType)) throw new VerificationException(this, "Required to produce " + outputType.getName() + ", but this produces a string or collection"); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java index 792b84a524b8..1220576fe77a 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java @@ -36,7 +36,8 @@ public DataType setOutputType(DataType outputType, VerificationContext context) if (outputType != null && ! value.getDataType().isAssignableTo(outputType)) throw new VerificationException(this, "Produces type " + value.getDataType().getName() + ", but type " + outputType.getName() + " is required"); - return super.setOutputType(outputType, context); + super.setOutputType(outputType, context); + return null; } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java index f29661a902ab..8e23745e67be 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ForEachExpression.java @@ -71,6 +71,7 @@ else if (inputType instanceof StructDataType struct) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { + if (outputType == null) return null; super.setOutputType(outputType, context); if (outputType instanceof ArrayDataType || outputType instanceof WeightedSetDataType) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java index c6a52f986f7f..0734f99f4810 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/HashExpression.java @@ -37,7 +37,7 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { super.setOutputType(outputType, context); - if ( ! isHashCompatible(outputType)) + if (outputType != null && ! isHashCompatible(outputType)) throw new VerificationException(this, "An " + outputType.getName() + " output is required, but this produces int or long"); return DataType.STRING; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java index 5c71cb24691a..a51b69ec7a44 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java @@ -33,7 +33,7 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { super.setOutputType(outputType, context); - if ( ! validType(outputType)) + if (outputType != null && ! validType(outputType)) throw new VerificationException(this, "Required to produce " + outputType.getName() + " but this produces a tensor with one dense dimension"); outputTensorType = ((TensorDataType)outputType).getTensorType(); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java index 0e8e9bc6dd42..38356d0ef518 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java @@ -24,6 +24,7 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { + if (outputType == null) return null; setVariableType(outputType, context); return super.setOutputType(outputType, context); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java index 9ddf718f720b..6bd3be97e7ea 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java @@ -29,10 +29,10 @@ public DataType setInputType(DataType input, VerificationContext context) { } @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(output, context); - if ( ! (output instanceof ArrayDataType) && output.getNestedType() == DataType.STRING) - throw new VerificationException(this, "This produces a string array, but " + output.getName() + " is required"); + public DataType setOutputType(DataType outputType, VerificationContext context) { + super.setOutputType(outputType, context); + if (outputType != null && ! (outputType instanceof ArrayDataType) && outputType.getNestedType() == DataType.STRING) + throw new VerificationException(this, "This produces a string array, but " + outputType.getName() + " is required"); return DataType.STRING; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java index c89860474935..d2d730fec1d7 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ToArrayExpression.java @@ -19,14 +19,15 @@ public DataType setInputType(DataType input, VerificationContext context) { } @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(output, context); - if (output instanceof ArrayDataType arrayType) + public DataType setOutputType(DataType outputType, VerificationContext context) { + if (outputType == null) return null; + super.setOutputType(outputType, context); + if (outputType instanceof ArrayDataType arrayType) return arrayType.getNestedType(); - if (output instanceof AnyDataType) + if (outputType instanceof AnyDataType) return AnyDataType.instance; else - throw new VerificationException(this, "Produces an array, but " + output + " is required"); + throw new VerificationException(this, "Produces an array, but " + outputType + " is required"); } @Override diff --git a/model-integration/src/main/java/ai/vespa/embedding/huggingface/HuggingFaceEmbedder.java b/model-integration/src/main/java/ai/vespa/embedding/huggingface/HuggingFaceEmbedder.java index d54a17609bd8..c8694bb82a91 100644 --- a/model-integration/src/main/java/ai/vespa/embedding/huggingface/HuggingFaceEmbedder.java +++ b/model-integration/src/main/java/ai/vespa/embedding/huggingface/HuggingFaceEmbedder.java @@ -110,22 +110,21 @@ public void deconstruct() { tokenizer.close(); } - @SuppressWarnings("unchecked") @Override - public Tensor embed(String text, Context context, TensorType tensorType) { - if (tensorType.dimensions().size() != 1) { - throw new IllegalArgumentException("Error in embedding to type '" + tensorType + "': should only have one dimension."); + public Tensor embed(String text, Context context, TensorType targetType) { + if (targetType.dimensions().size() != 1) { + throw new IllegalArgumentException("Error in embedding to type '" + targetType + "': should only have one dimension."); } - if (!tensorType.dimensions().get(0).isIndexed()) { - throw new IllegalArgumentException("Error in embedding to type '" + tensorType + "': dimension should be indexed."); + if (!targetType.dimensions().get(0).isIndexed()) { + throw new IllegalArgumentException("Error in embedding to type '" + targetType + "': dimension should be indexed."); } var embeddingResult = lookupOrEvaluate(context, prependInstruction(text, context)); IndexedTensor tokenEmbeddings = embeddingResult.output; - if (tensorType.valueType() == TensorType.Value.INT8) { - return binaryQuantization(embeddingResult, tensorType); + if (targetType.valueType() == TensorType.Value.INT8) { + return binaryQuantization(embeddingResult, targetType); } else { - Tensor result = poolingStrategy.toSentenceEmbedding(tensorType, tokenEmbeddings, embeddingResult.attentionMask); - return normalize ? normalize(result, tensorType) : result; + Tensor result = poolingStrategy.toSentenceEmbedding(targetType, tokenEmbeddings, embeddingResult.attentionMask); + return normalize ? normalize(result, targetType) : result; } } @@ -192,21 +191,21 @@ private HuggingFaceEmbedder.HFEmbeddingResult evaluate(Context context, String t return new HFEmbeddingResult(tokenEmbeddings, attentionMask, context.getEmbedderId()); } - private Tensor binaryQuantization(HuggingFaceEmbedder.HFEmbeddingResult embeddingResult, TensorType tensorType) { + private Tensor binaryQuantization(HuggingFaceEmbedder.HFEmbeddingResult embeddingResult, TensorType targetType) { long outputDimensions = embeddingResult.output().shape()[2]; - long targetDim = tensorType.dimensions().get(0).size().get(); - //🪆 flexibility - packing only the first 8*targetDim float values from the model output - long floatDimensions = 8 * targetDim; - if(floatDimensions > outputDimensions) { - throw new IllegalArgumentException("Cannot pack " + outputDimensions + " into " + targetDim + " int8s"); + long targetDimensions = targetType.dimensions().get(0).size().get(); + //🪆 flexibility - packing only the first 8*targetDimension float values from the model output + long targetUnpackagedDimensions = 8 * targetDimensions; + if (targetUnpackagedDimensions > outputDimensions) { + throw new IllegalArgumentException("Cannot pack " + outputDimensions + " into " + targetDimensions + " int8's"); } //perform pooling and normalizing using float version before binary quantization TensorType poolingType = new TensorType.Builder(TensorType.Value.FLOAT). - indexed(tensorType.indexedSubtype().dimensions().get(0).name(), - floatDimensions).build(); + indexed(targetType.indexedSubtype().dimensions().get(0).name(), targetUnpackagedDimensions) + .build(); Tensor result = poolingStrategy.toSentenceEmbedding(poolingType, embeddingResult.output(), embeddingResult.attentionMask()); result = normalize? normalize(result, poolingType) : result; - result = binarize((IndexedTensor) result, tensorType); + result = binarize((IndexedTensor) result, targetType); return result; } @@ -248,5 +247,6 @@ private IndexedTensor createTensorRepresentation(List input, String dimens protected record HFEmbeddingResult(IndexedTensor output, Tensor attentionMask, String embedderId) {} protected record HFEmbedderCacheKey(String embedderId, Object embeddedValue) { } + } From af5bec0f036079e0d1dd4bbb384a1cffe6692155 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 9 Dec 2024 12:51:42 +0100 Subject: [PATCH 8/8] Handle unresolved input everywhere --- .../indexinglanguage/expressions/EmbedExpression.java | 11 ++++++----- .../expressions/PackBitsExpression.java | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java index a0bbad879d1b..e62aac1e52d0 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java @@ -64,12 +64,13 @@ else if ( ! embedders.containsKey(embedderId)) { } @Override - public DataType setInputType(DataType type, VerificationContext context) { - super.setInputType(type, context); - if ( ! (type == DataType.STRING) && - ! (type instanceof ArrayDataType array && array.getNestedType() == DataType.STRING)) + public DataType setInputType(DataType inputType, VerificationContext context) { + super.setInputType(inputType, context); + if ( inputType != null && + ! (inputType == DataType.STRING) && + ! (inputType instanceof ArrayDataType array && array.getNestedType() == DataType.STRING)) throw new VerificationException(this, "This requires either a string or array input type, but got " + - type.getName()); + inputType.getName()); return getOutputType(context); // embed cannot determine the output type from the input } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java index a51b69ec7a44..66602c403554 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java @@ -23,6 +23,7 @@ public class PackBitsExpression extends Expression { @Override public DataType setInputType(DataType inputType, VerificationContext context) { + if (inputType == null) return null; super.setInputType(inputType, context); if ( ! validType(inputType)) throw new VerificationException(this, "Require a tensor with one dense dimension, but got " + inputType.getName());