From bdd14955112ea19694ba0e5ebf47a56f1e35fb01 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Sun, 3 Nov 2024 07:56:52 -0800 Subject: [PATCH] Revert "Bratseth/indexing type inference" --- .../schema/processing/IndexingValidation.java | 2 +- .../processing/IndexingInputsTestCase.java | 4 +- .../processing/IndexingOutputsTestCase.java | 2 +- .../IndexingValidationTestCase.java | 8 +- document/abi-spec.json | 3 +- .../java/com/yahoo/document/DataType.java | 7 +- .../com/yahoo/document/NumericDataType.java | 3 +- .../expressions/AnyDataType.java | 13 +--- .../expressions/ArithmeticExpression.java | 74 +++++++----------- .../expressions/Base64DecodeExpression.java | 2 +- .../expressions/Base64EncodeExpression.java | 2 +- .../expressions/BinarizeExpression.java | 4 +- .../expressions/BusyWaitExpression.java | 1 - .../expressions/CatExpression.java | 34 +-------- .../expressions/ChoiceExpression.java | 30 -------- .../expressions/ConstantExpression.java | 4 +- .../expressions/EmbedExpression.java | 6 +- .../expressions/ExactExpression.java | 10 --- .../expressions/Expression.java | 69 +++++------------ .../expressions/FlattenExpression.java | 9 --- .../expressions/ForEachExpression.java | 75 +++---------------- .../expressions/GetFieldExpression.java | 13 ++-- .../expressions/GetVarExpression.java | 5 +- .../expressions/HashExpression.java | 41 ++++++---- .../expressions/HexDecodeExpression.java | 12 --- .../expressions/HexEncodeExpression.java | 12 --- .../expressions/HostNameExpression.java | 12 --- .../expressions/IfThenExpression.java | 62 +++++++-------- .../expressions/InputExpression.java | 24 +----- .../expressions/JoinExpression.java | 16 +--- .../expressions/LiteralBoolExpression.java | 13 ---- .../expressions/LowerCaseExpression.java | 10 --- .../expressions/MapEntryFieldValue.java | 4 + .../expressions/NGramExpression.java | 10 --- .../expressions/NormalizeExpression.java | 12 +-- .../expressions/NowExpression.java | 11 --- .../OptimizePredicateExpression.java | 10 --- .../expressions/OutputExpression.java | 11 --- .../expressions/PackBitsExpression.java | 7 +- .../expressions/ParenthesisExpression.java | 12 --- .../expressions/RandomExpression.java | 12 --- .../expressions/ScriptExpression.java | 18 ----- .../expressions/SelectInputExpression.java | 32 -------- .../expressions/SetLanguageExpression.java | 10 --- .../expressions/SetVarExpression.java | 27 ++----- .../expressions/SplitExpression.java | 7 +- .../expressions/StatementExpression.java | 59 +++++---------- .../expressions/SubstringExpression.java | 10 --- .../expressions/SwitchExpression.java | 32 -------- .../expressions/ToArrayExpression.java | 14 ---- .../expressions/ToBoolExpression.java | 16 ---- .../expressions/ToByteExpression.java | 13 ---- .../expressions/ToDoubleExpression.java | 12 --- .../expressions/ToEpochSecondExpression.java | 12 --- .../expressions/ToFloatExpression.java | 12 --- .../expressions/ToIntegerExpression.java | 12 --- .../expressions/ToLongExpression.java | 12 --- .../expressions/ToPositionExpression.java | 13 ---- .../expressions/ToStringExpression.java | 12 --- .../expressions/ToWsetExpression.java | 26 ++----- .../expressions/TokenizeExpression.java | 10 --- .../expressions/TrimExpression.java | 10 --- .../expressions/VerificationException.java | 28 +++---- .../expressions/ZCurveExpression.java | 25 ------- .../EmbeddingScriptTestCase.java | 6 +- .../indexinglanguage/ScriptTestCase.java | 31 +------- .../SimpleDocumentAdapterTestCase.java | 2 +- .../expressions/ArithmeticTestCase.java | 35 ++++----- .../AttributeExpressionTestCase.java | 1 - .../expressions/Base64DecodeTestCase.java | 4 +- .../expressions/Base64EncodeTestCase.java | 4 +- .../expressions/CatTestCase.java | 8 +- .../expressions/EchoTestCase.java | 2 +- .../expressions/ExactTestCase.java | 4 +- .../expressions/ExpressionAssert.java | 37 ++++----- .../expressions/ExpressionAssertTestCase.java | 8 +- .../expressions/ExpressionTestCase.java | 12 +-- .../expressions/FlattenTestCase.java | 4 +- .../expressions/ForEachTestCase.java | 14 ++-- .../expressions/GetFieldTestCase.java | 6 +- .../expressions/GetVarTestCase.java | 2 +- .../expressions/GuardTestCase.java | 4 +- .../expressions/HexDecodeTestCase.java | 4 +- .../expressions/HexEncodeTestCase.java | 4 +- .../expressions/IfThenTestCase.java | 37 +++++---- .../expressions/InputTestCase.java | 2 +- .../expressions/JoinTestCase.java | 4 +- .../expressions/LowerCaseTestCase.java | 4 +- .../expressions/NGramTestCase.java | 4 +- .../expressions/NormalizeTestCase.java | 4 +- .../OptimizePredicateTestCase.java | 22 +++--- .../expressions/OutputAssert.java | 4 +- .../expressions/ParenthesisTestCase.java | 4 +- .../expressions/ScriptTestCase.java | 11 +-- .../expressions/SelectInputTestCase.java | 4 +- .../expressions/SetLanguageTestCase.java | 4 +- .../expressions/SetVarTestCase.java | 6 +- .../expressions/SplitTestCase.java | 4 +- .../expressions/StatementTestCase.java | 6 +- .../expressions/SubstringTestCase.java | 4 +- .../expressions/SwitchTestCase.java | 12 +-- .../expressions/ThisTestCase.java | 2 +- .../expressions/ToArrayTestCase.java | 2 +- .../expressions/ToBoolTestCase.java | 2 +- .../expressions/ToByteTestCase.java | 2 +- .../expressions/ToDoubleTestCase.java | 2 +- .../ToEpochSecondExpressionTestCase.java | 4 +- .../expressions/ToFloatTestCase.java | 2 +- .../expressions/ToIntegerTestCase.java | 2 +- .../expressions/ToLongTestCase.java | 2 +- .../expressions/ToPositionTestCase.java | 4 +- .../expressions/ToStringTestCase.java | 2 +- .../expressions/ToWsetTestCase.java | 26 +++---- .../expressions/TokenizeTestCase.java | 4 +- .../expressions/TrimTestCase.java | 4 +- .../VerificationExceptionTestCase.java | 2 +- .../expressions/ZCurveTestCase.java | 4 +- 117 files changed, 384 insertions(+), 1103 deletions(-) diff --git a/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java b/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java index d17434dffaa7..eceffb1bc025 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java @@ -52,7 +52,7 @@ public void process(boolean validate, boolean documentsOnly) { converter.convert(exp); // TODO: stop doing this explicitly when visiting a script does not branch } } catch (VerificationException e) { - fail(schema, field, Exceptions.toMessageString(e)); + fail(schema, field, "For expression '" + e.getExpression() + "': " + Exceptions.toMessageString(e)); } } } 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..597b83908ecb 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", + "For expression '{ tokenize normalize stem:\"BEST\" | index foo; }': Expected string input, but no input is specified", Exceptions.toMessageString(e)); } } @@ -156,7 +156,7 @@ void testNoInputInDerivedField() throws ParseException { fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'test', field 'derived1': Invalid expression '{ attribute derived1; }': " + + assertEquals("For schema 'test', field 'derived1': For expression '{ attribute derived1; }': " + "Expected any input, but no input is specified", Exceptions.toMessageString(e)); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java index 53db3d7e512b..ebaa0ef37b0e 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java @@ -56,7 +56,7 @@ void requireThatOutputConflictThrows() throws ParseException { fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'indexing_output_confict', field 'bar': Invalid expression 'index bar': Attempting " + + assertEquals("For schema 'indexing_output_confict', field 'bar': For expression 'index bar': Attempting " + "to assign conflicting values to field 'bar'", Exceptions.toMessageString(e)); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java index c638c55a0314..898f3f5b23d7 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java @@ -35,7 +35,7 @@ void testAttributeChanged() throws ParseException { fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'indexing_attribute_changed', field 'foo': Invalid expression 'attribute foo': " + + assertEquals("For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " + "Attempting to assign conflicting values to field 'foo'", Exceptions.toMessageString(e)); } @@ -79,7 +79,7 @@ void testIndexChanged() throws ParseException { fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'indexing_index_changed', field 'foo': Invalid expression 'index foo': " + + assertEquals("For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " + "Attempting to assign conflicting values to field 'foo'", Exceptions.toMessageString(e)); } @@ -123,7 +123,7 @@ void testSummaryChanged() throws ParseException { fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'indexing_summary_fail', field 'foo': Invalid expression 'summary foo': Attempting " + + assertEquals("For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " + "to assign conflicting values to field 'foo'", Exceptions.toMessageString(e)); } @@ -185,7 +185,7 @@ void requireThatMultilineOutputConflictThrows() throws ParseException { fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'indexing_multiline_output_confict', field 'cox': Invalid expression 'index cox': " + + assertEquals("For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " + "Attempting to assign conflicting values to field 'cox'", Exceptions.toMessageString(e)); } diff --git a/document/abi-spec.json b/document/abi-spec.json index 51cbb6d6475d..ba2313dcf0b1 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -182,8 +182,7 @@ "public com.yahoo.document.datatypes.FieldValue createFieldValue(java.lang.Object)", "public abstract java.lang.Class getValueClass()", "public abstract boolean isValueCompatible(com.yahoo.document.datatypes.FieldValue)", - "public boolean isAssignableFrom(com.yahoo.document.DataType)", - "public boolean isAssignableTo(com.yahoo.document.DataType)", + "public final boolean isAssignableFrom(com.yahoo.document.DataType)", "public static com.yahoo.document.ArrayDataType getArray(com.yahoo.document.DataType)", "public static com.yahoo.document.MapDataType getMap(com.yahoo.document.DataType, com.yahoo.document.DataType)", "public static com.yahoo.document.WeightedSetDataType getWeightedSet(com.yahoo.document.DataType)", diff --git a/document/src/main/java/com/yahoo/document/DataType.java b/document/src/main/java/com/yahoo/document/DataType.java index 3b1277a39e75..7a49938334fa 100644 --- a/document/src/main/java/com/yahoo/document/DataType.java +++ b/document/src/main/java/com/yahoo/document/DataType.java @@ -159,16 +159,11 @@ public FieldValue createFieldValue(Object arg) { public abstract boolean isValueCompatible(FieldValue value); - public boolean isAssignableFrom(DataType dataType) { + public final boolean isAssignableFrom(DataType dataType) { // TODO: Reverse this so that isValueCompatible() uses this instead. return isValueCompatible(dataType.createFieldValue()); } - /** The reverse of isAssignableFrom */ - public boolean isAssignableTo(DataType dataType) { - return dataType.isAssignableFrom(this); - } - /** * Returns an array datatype, where the array elements are of the given type * diff --git a/document/src/main/java/com/yahoo/document/NumericDataType.java b/document/src/main/java/com/yahoo/document/NumericDataType.java index 1f27ceeba37b..828cf024045a 100644 --- a/document/src/main/java/com/yahoo/document/NumericDataType.java +++ b/document/src/main/java/com/yahoo/document/NumericDataType.java @@ -11,7 +11,6 @@ public class NumericDataType extends PrimitiveDataType { // The global class identifier shared with C++. public static int classId = registerClass(Ids.document + 52, NumericDataType.class); - /** * Creates a datatype * @@ -19,7 +18,7 @@ public class NumericDataType extends PrimitiveDataType { * @param code the code (id) of the type * @param type the field value used for this type */ - protected NumericDataType(String name, int code, Class type, Factory factory) { + protected NumericDataType(java.lang.String name, int code, Class type, Factory factory) { super(name, code, type, factory); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyDataType.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyDataType.java index e3996b228e1f..3b401ae40851 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyDataType.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyDataType.java @@ -18,22 +18,13 @@ private AnyDataType() { super("any", DataType.lastPredefinedDataTypeId() + 1); } - @Override - public boolean isAssignableFrom(DataType other) { return true; } - - @Override - public boolean isAssignableTo(DataType other) { - return other instanceof AnyDataType; - } - - @Override - public boolean isValueCompatible(FieldValue value) { return true; } - @Override public FieldValue createFieldValue() { throw new UnsupportedOperationException(); } @Override public Class getValueClass() { throw new UnsupportedOperationException(); } + @Override + public boolean isValueCompatible(FieldValue value) { return true; } } 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 d7bc6afff39c..1a5bda47b8be 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 @@ -66,48 +66,11 @@ public ArithmeticExpression convertChildren(ExpressionConverter converter) { return new ArithmeticExpression(converter.convert(left), op, converter.convert(right)); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - DataType leftOutput = left.setInputType(inputType, context); - DataType rightOutput = right.setInputType(inputType, context); - return resultingType(leftOutput, rightOutput); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - DataType leftInput = left.setOutputType(outputType, context); - DataType rightInput = right.setOutputType(outputType, context); - if (leftInput == rightInput) // TODO: Generalize - return leftInput; - else - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { DataType input = context.getCurrentType(); - context.setCurrentType(resultingType(context.setCurrentType(input).verify(left).getCurrentType(), - context.setCurrentType(input).verify(right).getCurrentType())); - } - - private DataType resultingType(DataType left, DataType right) { - if (left == null || right == null) - return null; - if (!(left instanceof NumericDataType)) - throw new VerificationException(this, "The first argument must be a number, but has type " + left.getName()); - if (!(right instanceof NumericDataType)) - throw new VerificationException(this, "The second argument must be a number, but has type " + right.getName()); - - if (left == DataType.FLOAT || left == DataType.DOUBLE || right == DataType.FLOAT || right == DataType.DOUBLE) { - if (left == DataType.DOUBLE || right == DataType.DOUBLE) - return DataType.DOUBLE; - return DataType.FLOAT; - } - if (left == DataType.LONG || right == DataType.LONG) - return DataType.LONG; - return DataType.INT; + context.setCurrentType(evaluate(context.setCurrentType(input).verify(left).getCurrentType(), + context.setCurrentType(input).verify(right).getCurrentType())); } @Override @@ -117,15 +80,15 @@ 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)) + private static DataType requiredInputType(Expression lhs, Expression rhs) { + DataType lhsType = lhs.requiredInputType(); + DataType rhsType = rhs.requiredInputType(); + if (lhsType == null) return rhsType; + if (rhsType == null) return lhsType; + if (!lhsType.equals(rhsType)) throw new VerificationException(ArithmeticExpression.class, "Operands require conflicting input types, " + - leftType.getName() + " vs " + rightType.getName()); - return leftType; + lhsType.getName() + " vs " + rhsType.getName()); + return lhsType; } @Override @@ -153,6 +116,23 @@ public int hashCode() { return getClass().hashCode() + left.hashCode() + op.hashCode() + right.hashCode(); } + private DataType evaluate(DataType lhs, DataType rhs) { + if (lhs == null || rhs == null) + throw new VerificationException(this, "Attempting to perform arithmetic on a null value"); + if (!(lhs instanceof NumericDataType) || !(rhs instanceof NumericDataType)) + throw new VerificationException(this, "Attempting to perform unsupported arithmetic: [" + + lhs.getName() + "] " + op + " [" + rhs.getName() + "]"); + + if (lhs == DataType.FLOAT || lhs == DataType.DOUBLE || rhs == DataType.FLOAT || rhs == DataType.DOUBLE) { + if (lhs == DataType.DOUBLE || rhs == DataType.DOUBLE) + return DataType.DOUBLE; + return DataType.FLOAT; + } + if (lhs == DataType.LONG || rhs == DataType.LONG) + return DataType.LONG; + return DataType.INT; + } + private FieldValue evaluate(FieldValue lhs, FieldValue rhs) { if (lhs == null || rhs == null) return null; if (!(lhs instanceof NumericFieldValue) || !(rhs instanceof NumericFieldValue)) 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..2ad8a2bac573 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 @@ -24,7 +24,7 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.LONG, outputType, null, context); + super.setOutputType(outputType, DataType.LONG, context); return DataType.STRING; } 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..e430d5ce8fb5 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 @@ -24,7 +24,7 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.STRING, outputType, null, context); + super.setOutputType(outputType, DataType.STRING, context); return DataType.LONG; } 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..8c28f53be8ed 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 @@ -38,14 +38,14 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(null, outputType, TensorDataType.any(), context); + return super.setOutputType(outputType, TensorDataType.any(), context); } @Override protected void doVerify(VerificationContext context) { type = context.getCurrentType(); if (! (type instanceof TensorDataType)) - throw new VerificationException(this, "Require a tensor, but got " + type); + throw new IllegalArgumentException("The 'binarize' function requires a tensor, but got " + type); } @Override 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..61fa94402032 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 @@ -41,5 +41,4 @@ private static double nihlakanta(int i) { @Override public String toString() { return "busy_wait"; } @Override public boolean equals(Object obj) { return obj instanceof BusyWaitExpression; } @Override public int hashCode() { return getClass().hashCode(); } - } 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..1fbf3d5412c3 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; @@ -13,12 +12,10 @@ import com.yahoo.vespa.indexinglanguage.ExpressionConverter; import java.util.*; -import java.util.List; /** * @author Simon Thoresen Hult */ -// TODO: Support Map in addition to Array and Wighted Set (doc just says "collection type") public final class CatExpression extends ExpressionList { public CatExpression(Expression... expressions) { @@ -34,32 +31,6 @@ public CatExpression convertChildren(ExpressionConverter converter) { return new CatExpression(convertChildList(converter)); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - - List outputTypes = new ArrayList<>(expressions().size()); - for (var expression : expressions()) - outputTypes.add(expression.setInputType(inputType, context)); - DataType outputType = resolveOutputType(outputTypes); - return outputType != null ? outputType : getOutputType(context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - if (outputType != DataType.STRING && ! (outputType instanceof CollectionDataType)) - throw new VerificationException(this, "Required to produce " + outputType.getName() + - ", but this produces a string or collection"); - super.setOutputType(outputType, context); - for (var expression : expressions()) - expression.setOutputType(AnyDataType.instance, context); // Any output is handled by converting to string - - if (outputType instanceof CollectionDataType) - return outputType; - else - return getInputType(context); // Cannot infer input type since we take the string value - } - @Override protected void doVerify(VerificationContext context) { DataType input = context.getCurrentType(); @@ -81,8 +52,8 @@ protected void doExecute(ExecutionContext context) { context.fillVariableTypes(verificationContext); List values = new LinkedList<>(); List types = new LinkedList<>(); - for (Expression expression : this) { - FieldValue val = context.setCurrentValue(input).execute(expression).getCurrentValue(); + for (Expression exp : this) { + FieldValue val = context.setCurrentValue(input).execute(exp).getCurrentValue(); values.add(val); DataType type; @@ -139,7 +110,6 @@ public boolean equals(Object obj) { private static DataType resolveOutputType(List types) { DataType resolved = null; for (DataType type : types) { - if (type == null) return null; if (!(type instanceof CollectionDataType)) return DataType.STRING; if (resolved == null) 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..02443ced8112 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; @@ -38,34 +36,6 @@ public ChoiceExpression convertChildren(ExpressionConverter converter) { return new ChoiceExpression(asList().stream().map(choice -> converter.branch().convert(choice)).toList()); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - - DataType resolvedType = null; - boolean resolvedTypeNeverAssigned = true; - for (var expression : expressions()) { - DataType outputType = expression.setInputType(inputType, context); - resolvedType = resolvedTypeNeverAssigned ? outputType : mostGeneralOf(resolvedType, outputType); - resolvedTypeNeverAssigned = false; - } - return resolvedType != null ? resolvedType : getOutputType(context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - - DataType resolvedType = null; - boolean resolvedTypeNeverAssigned = true; - for (var expression : expressions()) { - DataType inputType = expression.setOutputType(outputType, context); - resolvedType = resolvedTypeNeverAssigned ? inputType : mostGeneralOf(resolvedType, inputType); - resolvedTypeNeverAssigned = false; - } - return resolvedType != null ? resolvedType : getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { DataType input = context.getCurrentType(); 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 6576648ea5f2..986556a343f4 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 @@ -33,8 +33,8 @@ public DataType setInputType(DataType inputType, VerificationContext context) { public DataType setOutputType(DataType outputType, VerificationContext context) { // TODO: //if (outputType != value.getDataType()) - // throw new VerificationException(this, "Produces type " + value.getDataType() + ", but type " + - // outputType + " is required"); + // throw new IllegalArgumentException(this + " produces a " + value.getDataType() + ", but a " + + // outputType + " is required"); return super.setOutputType(outputType, context); } 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 87e07444765b..a51469a71f45 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 @@ -70,13 +70,13 @@ public DataType setInputType(DataType type, VerificationContext context) { // TODO: Activate type checking // if ( ! (type == DataType.STRING) // && ! (type instanceof ArrayDataType array && array.getNestedType() == DataType.STRING)) - // throw new VerificationException(this, "This requires either a string or array input type, but got " + type); - return getOutputType(context); // embed cannot determine the output type from the input + // throw new IllegalArgumentException("embed request either a string or array input type, but got " + type); + return null; // embed cannot determine the output type from the input } @Override public DataType setOutputType(DataType type, VerificationContext context) { - super.setOutputType(null, type, TensorDataType.any(), context); + super.setOutputType(type, TensorDataType.any(), context); return getInputType(context); // the input (string vs. array of string) cannot be determined from the output } 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..259a89e98032 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 @@ -38,16 +38,6 @@ public ExactExpression(int maxTokenLength) { this(OptionalInt.of(maxTokenLength)); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(DataType.STRING, outputType, null, context); - } - @Override protected void doExecute(ExecutionContext context) { StringFieldValue input = (StringFieldValue) context.getCurrentValue(); 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 545920735480..99d5e51c9eda 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 @@ -6,6 +6,7 @@ import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentUpdate; import com.yahoo.document.Field; +import com.yahoo.document.TensorDataType; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.language.Linguistics; import com.yahoo.language.process.Embedder; @@ -65,9 +66,10 @@ public void setStatementOutput(DocumentType documentType, Field field) {} */ protected final DataType setInputType(DataType inputType, DataType requiredType, VerificationContext context) { // TODO: Activate type checking - // if ( ! (inputType.isAssignableTo(requiredType)) - // throw new VerificationException(this, "This requires type " + requiredType.getName() + ", but gets " + inputType.getName()); - return assignInputType(inputType); + // if ( ! (inputType instanceof TensorDataType)) + // throw new IllegalArgumentException(this + " requires a " + requiredType + ", but gets " + inputType); + this.inputType = inputType; + return inputType; } /** @@ -76,14 +78,8 @@ protected final DataType setInputType(DataType inputType, DataType requiredType, * Subtypes may implement this by calling setInputType(inputType, requiredType, VerificationContext context). */ public DataType setInputType(DataType inputType, VerificationContext context) { - return assignInputType(inputType); - } - - private DataType assignInputType(DataType inputType) { - // Since we assign in both directions, in both orders, we may already know - if (this.inputType == null) - this.inputType = inputType; - return this.inputType; + this.inputType = inputType; + return inputType; } /** @@ -92,36 +88,23 @@ private DataType assignInputType(DataType inputType) { */ public DataType getOutputType(VerificationContext context) { return outputType; } - /** Returns the already assigned (during verification) output type, or throws an exception if no type is assigned. */ - public DataType requireOutputType() { - if (outputType == null) - throw new IllegalStateException("The output type of " + this + " is unresolved"); - return outputType; - } - /** * Sets the output type of this and returns the resulting input type, or null if it cannot be - * uniquely determined, with additional arguments for convenience type checking. + * uniquely determined. * This implementation returns the same type, which is appropriate for all statements * that do not change the type. * - * @param actualOutput the type actually produced by this, musyt be assignable to the requiredOutput, - * or null if not known - * @param requiredOutput the type required by the next expression, which actualOutput must be assignable to, - * or null if it cannot be uniquely determined. - * @param requiredType a type the required output must be assignable to, or null to not verify this + * @param outputType the type to set as the output type of this, or null if it cannot be determined + * @param requiredType the type the output type must be assignable to * @param context the context of this - * @return the actualOutput if set, requiredOutput otherwise - * @throws IllegalArgumentException if actualOutput + * @throws IllegalArgumentException if outputType isn't assignable to requiredType */ - protected final DataType setOutputType(DataType actualOutput, DataType requiredOutput, DataType requiredType, - VerificationContext context) { + protected final DataType setOutputType(DataType outputType, DataType requiredType, VerificationContext context) { // TODO: Activate type checking - // if (actualOutput != null && requiredOutput != null && ! actualOutput.isAssignableTo(requiredOutput)) - // throw new VerificationException(this, "This produces type " + actualOutput.getName() + " but " + requiredOutput.getName() + " is required"); - // if (requiredType != null && requiredOutput != null && ! requiredOutputOutput.isAssignableTo(requiredType)) - // throw new VerificationException(this, "This is required to produce type " + requiredOutput.getName() + " but is produces " + requiredType.getName());; - return assignOutputType(actualOutput != null ? actualOutput : requiredOutput); // Use the more precise type when known + // if (outputType != null && ! requiredType.isAssignableFrom(outputType)) + // throw new IllegalArgumentException(this + " produces a " + outputType + " but " + requiredType + " is required"); + this.outputType = outputType; + return outputType; } /** @@ -130,14 +113,8 @@ protected final DataType setOutputType(DataType actualOutput, DataType requiredO * Subtypes implement this by calling setOutputType(outputType, requiredType, VerificationContext context). */ public DataType setOutputType(DataType outputType, VerificationContext context) { - return assignOutputType(outputType); - } - - private DataType assignOutputType(DataType outputType) { - // Since we assign in both directions, in both orders, we may already know - if (this.outputType == null) - this.outputType = outputType; - return this.outputType; + this.outputType = outputType; + return outputType; } public abstract DataType createdOutputType(); @@ -327,14 +304,4 @@ public final FieldValue execute() { return execute(new ExecutionContext()); } - protected DataType mostGeneralOf(DataType left, DataType right) { - if (left == null || right == null) return null; - return left.isAssignableTo(right) ? right : left; - } - - protected DataType leastGeneralOf(DataType left, DataType right) { - if (left == null || right == null) return null; - return left.isAssignableTo(right) ? left : right; - } - } 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..6b44e4ef3cc3 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 @@ -28,15 +28,6 @@ public FlattenExpression() { super(DataType.STRING); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(DataType.STRING, outputType, null, context); - } @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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 06fff2fe0d5b..6805b0445f97 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 @@ -42,75 +42,20 @@ public void setStatementOutput(DocumentType documentType, Field field) { @Override public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - - if (inputType instanceof ArrayDataType || inputType instanceof WeightedSetDataType) { - // Value type outside block becomes the collection type having the block output type as argument - return withInnerType(expression.setInputType(inputType.getNestedType(), context), inputType); - } - else if (inputType instanceof StructDataType struct) { - return verifyStructFields(struct, context); - } - if (inputType instanceof MapDataType) { - // Inner value will be MapEntryFieldValue which has the same type as the map - DataType outputType = expression.setInputType(inputType, context); - if (outputType == null) return getOutputType(context); - return DataType.getArray(outputType); - } - else { - throw new VerificationException(this, "Expected Array, Struct, WeightedSet or Map input, got " + - inputType.getName()); - } + // TODO: Activate type checking + // if ( ! inputType.isMultivalue()) + // throw new IllegalArgumentException("for_each requires a multivalue type, but gets " + inputType); + expression.setInputType(inputType.getNestedType(), context); + return super.setInputType(inputType, context); } @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - - if (outputType instanceof ArrayDataType || outputType instanceof WeightedSetDataType) { - DataType innerInputType = expression.setOutputType(outputType.getNestedType(), context); - if (innerInputType instanceof MapDataType mapDataType) // A map converted to an array of entries - return mapDataType; - else - return withInnerType(innerInputType, outputType); - } - else if (outputType instanceof StructDataType struct) { - return verifyStructFields(struct, context); - } - else { - throw new VerificationException(this, "Expected Array, Struct, WeightedSet or Map input, got " + - outputType.getName()); - } - } - - private DataType withInnerType(DataType innerType, DataType collectionType) { - if (innerType == null) return null; - if (collectionType instanceof WeightedSetDataType wset) - return DataType.getWeightedSet(innerType, wset.createIfNonExistent(), wset.removeIfZero()); - else - return DataType.getArray(innerType); - } - - /** - * Verifies that each struct field is compatible with the expression. - * This is symmetric in both verification directions since the expression just need to be compatible with - * all the struct fields. - */ - private DataType verifyStructFields(StructDataType struct, VerificationContext context) { - for (Field field : struct.getFields()) { - 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); - 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); - if (fieldOutputType == null && fieldInputType == null) - return null; // Neither direction could be inferred - } - return struct; + // TODO: Activate type checking + // if ( ! outputType.isMultivalue()) + // throw new IllegalArgumentException("for_each produces a multivalue type, but " + outputType + " is required"); + expression.setOutputType(outputType.getNestedType(), context); + return super.setOutputType(outputType, context); } @Override 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..425eb90d6f8d 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,21 +31,22 @@ public GetFieldExpression(String structFieldName) { @Override public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); - return getFieldType(inputType, context); + return getFieldType(context); } @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - return getInputType(context); + super.setOutputType(getFieldType(context), outputType, context); + return AnyDataType.instance; } @Override protected void doVerify(VerificationContext context) { - context.setCurrentType(getFieldType(context.getCurrentType(), context)); + context.setCurrentType(getFieldType(context)); } - private DataType getFieldType(DataType input, VerificationContext context) { + private DataType getFieldType(VerificationContext context) { + DataType input = context.getCurrentType(); if (input instanceof MapDataType entryInput) { if (structFieldName.equals(keyName)) return entryInput.getKeyType(); @@ -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, bit got an " + input.getName()); } private DataType getStructFieldType(StructuredDataType structInput) { 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..1f5e1c4f5b9d 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 @@ -25,15 +25,16 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(context.getVariable(variableName), outputType, null, context); + super.setOutputType(context.getVariable(variableName), outputType, context); return AnyDataType.instance; } @Override protected void doVerify(VerificationContext context) { DataType input = context.getVariable(variableName); - if (input == null) + if (input == null) { throw new VerificationException(this, "Variable '" + variableName + "' not found"); + } context.setCurrentType(input); } 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 cea3e8181b23..bdfcd6155803 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 @@ -3,6 +3,7 @@ import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; +import com.yahoo.document.ArrayDataType; import com.yahoo.document.DataType; import com.yahoo.document.DocumentType; import com.yahoo.document.Field; @@ -21,36 +22,43 @@ public class HashExpression extends Expression { private final HashFunction hasher = Hashing.sipHash24(); + /** The target *primitive* type we are hashing into. */ + private DataType targetType; + public HashExpression() { super(DataType.STRING); } @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, DataType.STRING, context); - return getOutputType(context); // Can not infer int or long - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - if ( ! isHashCompatible(outputType)) - throw new VerificationException(this, "An " + outputType.getName() + - " output is required, but this produces int or long"); - return DataType.STRING; + public void setStatementOutput(DocumentType documentType, Field field) { + if ( ! canStoreHash(field.getDataType())) + throw new IllegalArgumentException("Cannot use the hash function on an indexing statement for " + + field.getName() + + ": The hash function can only be used when the target field " + + "is int or long or an array of int or long, not " + field.getDataType()); + targetType = field.getDataType().getPrimitiveType(); } @Override protected void doVerify(VerificationContext context) { + String outputField = context.getOutputField(); + if (outputField == null) + throw new VerificationException(this, "No output field in this statement: " + + "Don't know what value to hash to"); + DataType outputFieldType = context.getFieldType(this); + if ( ! canStoreHash(outputFieldType)) + throw new VerificationException(this, "The type of the output field " + outputField + + " is not int or long but " + outputFieldType); + targetType = outputFieldType.getPrimitiveType(); context.setCurrentType(createdOutputType()); } @Override protected void doExecute(ExecutionContext context) { StringFieldValue input = (StringFieldValue) context.getCurrentValue(); - if (requireOutputType().equals(DataType.INT)) + if (targetType.equals(DataType.INT)) context.setCurrentValue(new IntegerFieldValue(hashToInt(input.getString()))); - else if (requireOutputType().equals(DataType.LONG)) + else if (targetType.equals(DataType.LONG)) context.setCurrentValue(new LongFieldValue(hashToLong(input.getString()))); else throw new IllegalStateException(); // won't happen @@ -64,14 +72,15 @@ private long hashToLong(String value) { return hasher.hashString(value, StandardCharsets.UTF_8).asLong(); } - private boolean isHashCompatible(DataType type) { + private boolean canStoreHash(DataType type) { if (type.equals(DataType.INT)) return true; if (type.equals(DataType.LONG)) return true; + if (type instanceof ArrayDataType) return canStoreHash(((ArrayDataType)type).getNestedType()); return false; } @Override - public DataType createdOutputType() { return requireOutputType(); } + public DataType createdOutputType() { return targetType; } @Override public String toString() { return "hash"; } 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..a7d314ff45a4 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 @@ -17,18 +17,6 @@ public HexDecodeExpression() { super(DataType.STRING); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, DataType.STRING, context); - return DataType.LONG; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.LONG, outputType, null, context); - return DataType.STRING; - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..c32b08e12484 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 @@ -14,18 +14,6 @@ public HexEncodeExpression() { super(DataType.LONG); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, DataType.LONG, context); - return DataType.STRING; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.STRING, outputType, null, context); - return DataType.LONG; - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..550355c9d242 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,18 +14,6 @@ public HostNameExpression() { super(null); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return DataType.STRING; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.STRING, outputType, null, context); - return AnyDataType.instance; - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..eeaee3ff1355 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 @@ -66,28 +66,6 @@ public IfThenExpression convertChildren(ExpressionConverter converter) { converter.branch().convert(ifFalse)); } - @Override - 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); - } - - @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); - } - @Override public void setStatementOutput(DocumentType documentType, Field field) { left.setStatementOutput(documentType, field); @@ -113,7 +91,9 @@ protected void doVerify(VerificationContext context) { context.setCurrentType(input).verify(right); var trueValue = context.setCurrentType(input).verify(ifTrue); var falseValue = context.setCurrentType(input).verify(ifFalse); - context.setCurrentType(mostGeneralOf(trueValue.getCurrentType(), falseValue.getCurrentType())); + var valueType = trueValue.getCurrentType().isAssignableFrom(falseValue.getCurrentType()) ? + trueValue.getCurrentType() : falseValue.getCurrentType(); + context.setCurrentType(valueType); } @Override @@ -180,12 +160,24 @@ public String toString() { @Override public boolean equals(Object obj) { - if ( ! (obj instanceof IfThenExpression exp)) return false; - if ( ! left.equals(exp.left)) return false; - if ( ! comparator.equals(exp.comparator)) return false; - if ( ! right.equals(exp.right)) return false; - if ( ! ifTrue.equals(exp.ifTrue)) return false; - if ( ! equals(ifFalse, exp.ifFalse)) return false; + if (!(obj instanceof IfThenExpression exp)) { + return false; + } + if (!left.equals(exp.left)) { + return false; + } + if (!comparator.equals(exp.comparator)) { + return false; + } + if (!right.equals(exp.right)) { + return false; + } + if (!ifTrue.equals(exp.ifTrue)) { + return false; + } + if (!equals(ifFalse, exp.ifFalse)) { + return false; + } return true; } @@ -212,16 +204,16 @@ private static DataType resolveRequiredInputType(DataType prev, DataType next) { return prev; } - private static boolean isTrue(FieldValue left, Comparator comparator, FieldValue right) { + private static boolean isTrue(FieldValue lhs, Comparator cmp, FieldValue rhs) { int res; - if (left instanceof NumericFieldValue && right instanceof NumericFieldValue) { - BigDecimal lhsVal = ArithmeticExpression.asBigDecimal((NumericFieldValue)left); - BigDecimal rhsVal = ArithmeticExpression.asBigDecimal((NumericFieldValue)right); + if (lhs instanceof NumericFieldValue && rhs instanceof NumericFieldValue) { + BigDecimal lhsVal = ArithmeticExpression.asBigDecimal((NumericFieldValue)lhs); + BigDecimal rhsVal = ArithmeticExpression.asBigDecimal((NumericFieldValue)rhs); res = lhsVal.compareTo(rhsVal); } else { - res = left.compareTo(right); + res = lhs.compareTo(rhs); } - return switch (comparator) { + return switch (cmp) { case EQ -> res == 0; case NE -> res != 0; case GT -> res > 0; 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..48cf6ac237c3 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 @@ -27,28 +27,12 @@ public InputExpression(String fieldName) { public String getFieldName() { return fieldName; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return requireFieldType(context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(requireFieldType(context), outputType, null, context); - return AnyDataType.instance; - } - - private DataType requireFieldType(VerificationContext context) { - DataType fieldType = context.getFieldType(fieldName, this); - if (fieldType == null) - throw new VerificationException(this, "Field '" + fieldName + "' not found"); - return fieldType; - } - @Override protected void doVerify(VerificationContext context) { - context.setCurrentType(requireFieldType(context)); + DataType val = context.getFieldType(fieldName, this); + if (val == null) + throw new VerificationException(this, "Field '" + fieldName + "' not found"); + context.setCurrentType(val); } @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..d4640086a311 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 @@ -24,25 +24,11 @@ public JoinExpression(String delimiter) { public String getDelimiter() { return delimiter; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - if ( ! (inputType instanceof ArrayDataType)) - throw new VerificationException(this, "Expected Array input, got type " + inputType.getName()); - return DataType.STRING; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.STRING, outputType, null, context); - return getInputType(context); // Cannot deduce since any array type is accepted - } - @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()); + throw new VerificationException(this, "Expected Array input, got " + input.getName()); } context.setCurrentType(createdOutputType()); } 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..12fa802d59b1 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; @@ -19,18 +18,6 @@ public LiteralBoolExpression(boolean value) { this.value = value; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return DataType.BOOL; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.BOOL, outputType, null, context); - return AnyDataType.instance; - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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 a7d77c5342d4..8cf304043bed 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 @@ -15,16 +15,6 @@ public LowerCaseExpression() { super(DataType.STRING); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(DataType.STRING, outputType, null, context); - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MapEntryFieldValue.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MapEntryFieldValue.java index 150f9a23641c..9ed1480aec23 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MapEntryFieldValue.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MapEntryFieldValue.java @@ -21,6 +21,10 @@ class MapEntryFieldValue extends FieldValue { private FieldValue key = null; private FieldValue value = null; + MapEntryFieldValue(MapDataType type) { + this.type = type; + } + MapEntryFieldValue(FieldValue key, FieldValue value) { this.type = new MapDataType(key.getDataType(), value.getDataType()); this.key = key; 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..8954951ce462 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 @@ -43,16 +43,6 @@ public NGramExpression(Linguistics linguistics, int gramSize) { public int getGramSize() { return gramSize; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(DataType.STRING, outputType, null, context); - } - @Override protected void doVerify(VerificationContext context) { // empty 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..d269fa1fd4a9 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 @@ -23,17 +23,7 @@ public NormalizeExpression(Linguistics linguistics) { } public Linguistics getLinguistics() { return linguistics; } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(DataType.STRING, outputType, null, context); - } - + @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..b00b38454628 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 @@ -22,17 +22,6 @@ public NowExpression(Timer timer) { public Timer getTimer() { return timer; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.LONG, outputType, null, context); - return AnyDataType.instance; - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..56531b3aae94 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 @@ -29,16 +29,6 @@ public OptimizePredicateExpression() { this.optimizer = optimizer; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, DataType.PREDICATE, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(DataType.PREDICATE, outputType, null, context); - } - @Override protected void doVerify(VerificationContext context) { checkVariable(context, "arity", DataType.INT, true); 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..a050eee7413f 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 @@ -24,17 +24,6 @@ public OutputExpression(String image, String fieldName) { public String getFieldName() { return fieldName; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, context.getFieldType(fieldName, this), context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - return context.getFieldType(fieldName, this); - } - @Override protected void doVerify(VerificationContext context) { context.tryOutputType(fieldName, context.getCurrentType(), this); 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..078639a8071b 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 @@ -30,7 +30,8 @@ public PackBitsExpression() { public DataType setInputType(DataType inputType, VerificationContext context) { super.setInputType(inputType, context); if ( ! validType(inputType)) - throw new VerificationException(this, "Require a tensor with one dense dimension, but got " + inputType.getName()); + throw new IllegalArgumentException("pack_bits requires a tensor with one dense dimension, " + + "but got " + inputType); outputTensorType = outputType(((TensorDataType)inputType).getTensorType()); return new TensorDataType(outputTensorType); } @@ -39,8 +40,8 @@ public DataType setInputType(DataType inputType, VerificationContext context) { public DataType setOutputType(DataType outputType, VerificationContext context) { super.setOutputType(outputType, context); if ( ! validType(outputType)) - throw new VerificationException(this, "Required to produce " + outputType.getName() + - " but this produces a tensor with one dense dimension"); + throw new IllegalArgumentException("pack_bits produces a tensor with one dense dimension, " + + "but need " + outputType); outputTensorType = ((TensorDataType)outputType).getTensorType(); return new TensorDataType(inputType(outputTensorType)); } 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..ade7cc72d149 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 @@ -27,18 +27,6 @@ public ParenthesisExpression convertChildren(ExpressionConverter converter) { return new ParenthesisExpression(converter.convert(innerExp)); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return innerExp.setInputType(inputType, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - return innerExp.setInputType(outputType, context); - } - @Override public void setStatementOutput(DocumentType documentType, Field field) { innerExp.setStatementOutput(documentType, field); 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..31a44172a180 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 @@ -25,18 +25,6 @@ public RandomExpression(Integer max) { public Integer getMaxValue() { return max; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return DataType.INT; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(DataType.INT, outputType, null, context); - return AnyDataType.instance; - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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 311c7378b987..bf241cf61784 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 @@ -43,24 +43,6 @@ public ScriptExpression convertChildren(ExpressionConverter converter) { .toList()); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - DataType currentOutput = null; - for (var expression : expressions()) - currentOutput = expression.setInputType(inputType, context); - return currentOutput != null ? currentOutput : getOutputType(context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - DataType currentInput = null; - for (var expression : expressions()) - currentInput = expression.setInputType(outputType, context); - return currentInput != null ? currentInput : getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { DataType input = context.getCurrentType(); 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..d465d0aed66f 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 @@ -38,38 +38,6 @@ public SelectInputExpression convertChildren(ExpressionConverter converter) { .toList()); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - - DataType outputType = null; - boolean outputNeverAssigned = true; // Needed to separate this null case from the "cannot be inferred" case - for (Pair entry : cases) { - DataType fieldType = context.getFieldType(entry.getFirst(), this); - if (fieldType == null) - throw new VerificationException(this, "Field '" + entry.getFirst() + "' not found"); - var entryOutputType = entry.getSecond().setInputType(fieldType, context); - outputType = outputNeverAssigned ? entryOutputType : mostGeneralOf(outputType, entryOutputType); - outputNeverAssigned = false; - } - return outputType; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - - for (Pair entry : cases) { - DataType fieldType = context.getFieldType(entry.getFirst(), this); - if (fieldType == null) - throw new VerificationException(this, "Field '" + entry.getFirst() + "' not found"); - DataType inputType = entry.getSecond().setOutputType(outputType, context); - if ( ! fieldType.isAssignableTo(inputType)) - throw new VerificationException(this, "Field '" + entry.getFirst() + "' not found"); - } - return AnyDataType.instance; - } - @Override public void setStatementOutput(DocumentType documentType, Field field) { for (var casePair : 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..8dbbc0c974d6 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 @@ -15,16 +15,6 @@ public SetLanguageExpression() { super(DataType.STRING); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(outputType, context); - } - @Override protected void doVerify(VerificationContext context) { // empty 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 06342cbd03ed..b4c92fc695b1 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 @@ -17,30 +17,15 @@ public SetVarExpression(String varName) { public String getVariableName() { return varName; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - setVariableType(inputType, context); - return super.setInputType(inputType, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - setVariableType(outputType, context); - return super.setOutputType(outputType, context); - } - @Override protected void doVerify(VerificationContext context) { - setVariableType(context.getCurrentType(), context); - } - - private void setVariableType(DataType newType, VerificationContext context) { - DataType existingType = context.getVariable(varName); - if (existingType != null && ! newType.equals(existingType)) { - throw new VerificationException(this, "Cannot set variable '" + varName + "' to type " + newType.getName() + - ": It is already set to type " + existingType.getName()); + DataType next = context.getCurrentType(); + DataType prev = context.getVariable(varName); + if (prev != null && !prev.equals(next)) { + throw new VerificationException(this, "Attempting to assign conflicting types to variable '" + varName + + "', " + prev.getName() + " vs " + next.getName()); } - context.setVariable(varName, newType); + context.setVariable(varName, next); } @Override 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 7884e7632ddd..7d36455ebce6 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 @@ -25,7 +25,10 @@ public SplitExpression(String splitString) { @Override public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, DataType.STRING, context); + super.setInputType(input, context); + // TODO: Activate type checking + // if (input != DataType.STRING) + // throw new IllegalArgumentException("split requires a string input, but got " + input); return new ArrayDataType(DataType.STRING); } @@ -34,7 +37,7 @@ public DataType setOutputType(DataType output, VerificationContext context) { super.setOutputType(output, context); // TODO: Activate type checking // if ( ! (output instanceof ArrayDataType) && output.getNestedType() == DataType.STRING) - // throw new VerificationException(this, "This produces a string array, but needs type " + output.getName()); + // throw new IllegalArgumentException("split produces a string array, but needs " + output); 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..e8ed41df7b9c 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 @@ -28,6 +28,9 @@ public final class StatementExpression extends ExpressionList { /** The names of the fields consumed by this. */ private final List inputFields; + /** The name of the (last) output field this statement will write to, or null if none */ + private String outputField; + public StatementExpression(Expression... list) { this(Arrays.asList(list)); // TODO: Can contain null - necessary ? } @@ -53,57 +56,31 @@ public StatementExpression convertChildren(ExpressionConverter converter) { } @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - resolveBackwards(context); - return resolveForwards(context); - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(output, context); - resolveForwards(context); - return resolveBackwards(context); - } + protected void doVerify(VerificationContext context) { + if (expressions().isEmpty()) return; - // Result input and output types: - // Some expressions can only determine their input from their output, and others only their output from - // their input. Therefore, we try resolving in both directions, which should always meet up to produce - // uniquely determined inputs and outputs of all expressions. - // forward: + outputField = outputFieldName(); + if (outputField != null) + context.setOutputField(outputField); - /** Resolves types forward and returns the final output, or null if resolution could not progress to the end. */ - private DataType resolveForwards(VerificationContext context) { + // Result input and output types: + // Some expressions can only determine their input from their output, and others only their output from + // their input. Therefore, we try resolving in both directions, which should always meet up to produce + // uniquely determined inputs and outputs of all expressions. + // forward: 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); - return inputType; - } - - /** Resolves types backwards and returns the required input, or null if resolution could not progress to the start. */ - private DataType resolveBackwards(VerificationContext context) { - int i = expressions().size(); + // reverse: + int j = expressions().size(); 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) - outputType = expressions().get(i).setOutputType(outputType, context); - return outputType; - } - - @Override - protected void doVerify(VerificationContext context) { - if (expressions().isEmpty()) return; - - String outputField = outputFieldName(); - if (outputField != null) - context.setOutputField(outputField); - - resolveForwards(context); - resolveBackwards(context); + outputType = expressions().get(--j).getInputType(context); + while (--j >= 0 && outputType != null) + outputType = expressions().get(j).setOutputType(outputType, context); for (Expression expression : expressions()) context.verify(expression); 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..00765e0b263c 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 @@ -26,16 +26,6 @@ public SubstringExpression(int from, int to) { public int getTo() { return to; } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(DataType.STRING, outputType, null, context); - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..120f08847f5e 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 @@ -21,8 +21,6 @@ public final class SwitchExpression extends CompositeExpression { private final Map cases = new LinkedHashMap<>(); - - /** The default expression, or null if none */ private final Expression defaultExp; public SwitchExpression(Map cases) { @@ -56,36 +54,6 @@ public SwitchExpression convertChildren(ExpressionConverter converter) { return new SwitchExpression(convertedCases, converter.branch().convert(defaultExp)); } - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, DataType.STRING, context); - - DataType outputType = defaultExp == null ? null : defaultExp.setInputType(inputType, context); - boolean outputNeverAssigned = true; // Needed to separate this null case from the "cannot be inferred" case - for (Expression expression : cases.values()) { - DataType expressionOutputType = expression.setInputType(inputType, context); - outputType = outputNeverAssigned ? expressionOutputType : mostGeneralOf(outputType, expressionOutputType); - outputNeverAssigned = false; - } - return outputType; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - - setOutputType(outputType, defaultExp, context); - for (Expression expression : cases.values()) - setOutputType(outputType, expression, context); - return DataType.STRING; - } - - private void setOutputType(DataType outputType, Expression expression, VerificationContext context) { - DataType inputType = expression.setOutputType(outputType, context); - if (inputType != null && ! DataType.STRING.isAssignableTo(inputType)) - throw new VerificationException(this, "This inputs a string, but '" + expression + "' requires type " + inputType); - } - @Override public void setStatementOutput(DocumentType documentType, Field field) { defaultExp.setStatementOutput(documentType, field); 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 0b677ad23d69..303458a19ff7 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 @@ -15,20 +15,6 @@ public ToArrayExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return new ArrayDataType(input); - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(output, context); - if ( ! (output instanceof ArrayDataType arrayType)) - throw new VerificationException(this, "Produces an array, but " + output + " is required"); - return arrayType.getNestedType(); - } - @Override protected void doVerify(VerificationContext context) { 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 fcb7b5311544..3e0523995322 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,9 +1,7 @@ // 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; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.NumericFieldValue; @@ -18,20 +16,6 @@ public ToBoolExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - 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; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.BOOL, output, null, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { 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..1606a9a70f62 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; /** @@ -14,18 +13,6 @@ public ToByteExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return DataType.BYTE; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.BYTE, output, null, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { 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..4f0e75c3f770 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 @@ -13,18 +13,6 @@ public ToDoubleExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return DataType.DOUBLE; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.DOUBLE, output, null, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..37032852b92e 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 @@ -16,18 +16,6 @@ public ToEpochSecondExpression() { super(DataType.STRING); //only accept string input } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, DataType.STRING, context); - return DataType.LONG; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.LONG, output, null, context); - return DataType.STRING; - } - @Override protected void doVerify(VerificationContext context) { 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..91b51e8b7e34 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 @@ -13,18 +13,6 @@ public ToFloatExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return DataType.FLOAT; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.FLOAT, output, null, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { 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..cbf1ff949ce8 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 @@ -13,18 +13,6 @@ public ToIntegerExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return DataType.INT; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.INT, output, null, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { 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..dc601a9e2dd3 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 @@ -13,18 +13,6 @@ public ToLongExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return DataType.LONG; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.LONG, output, null, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); 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..0d4bafaf8ed5 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,7 +3,6 @@ import com.yahoo.document.DataType; import com.yahoo.document.PositionDataType; -import com.yahoo.document.PrimitiveDataType; /** * @author Simon Thoresen Hult @@ -14,18 +13,6 @@ public ToPositionExpression() { super(DataType.STRING); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, DataType.STRING, context); - return PositionDataType.INSTANCE; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(PositionDataType.INSTANCE, output, null, context); - return DataType.STRING; - } - @Override protected void doVerify(VerificationContext context) { 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..d1209e59710b 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 @@ -13,18 +13,6 @@ public ToStringExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return DataType.STRING; - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.STRING, output, null, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { 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 b165d51c7208..6ed50759e253 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 @@ -24,36 +24,22 @@ public ToWsetExpression(boolean createIfNonExistent, boolean removeIfZero) { public boolean getRemoveIfZero() { return removeIfZero; } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - return outputType(input); - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - if ( ! (output instanceof WeightedSetDataType)) - throw new VerificationException(this, "This creates a WeightedSet, but type " + output.getName() + " is needed"); - super.setOutputType(output, context); - return getInputType(context); - } - @Override protected void doVerify(VerificationContext context) { - context.setCurrentType(outputType(context.getCurrentType())); + context.setCurrentType(DataType.getWeightedSet(context.getCurrentType(), createIfNonExistent, removeIfZero)); } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void doExecute(ExecutionContext context) { FieldValue input = context.getCurrentValue(); - WeightedSet output = outputType(input.getDataType()).createFieldValue(); + DataType inputType = input.getDataType(); + + WeightedSetDataType outputType = DataType.getWeightedSet(inputType, createIfNonExistent, removeIfZero); + WeightedSet output = outputType.createFieldValue(); output.add(input); - context.setCurrentValue(output); - } - private WeightedSetDataType outputType(DataType inputType) { - return DataType.getWeightedSet(inputType, createIfNonExistent, removeIfZero); + context.setCurrentValue(output); } @Override 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..64d6c0a5a199 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 @@ -27,16 +27,6 @@ public TokenizeExpression(Linguistics linguistics, AnnotatorConfig config) { public AnnotatorConfig getConfig() { return config; } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - return super.setInputType(input, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - return super.setOutputType(DataType.STRING, output, null, context); - } - @Override protected void doVerify(VerificationContext context) { // empty 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..78f89fabe460 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 @@ -18,16 +18,6 @@ protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - return super.setInputType(input, DataType.STRING, context); - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - return super.setOutputType(DataType.STRING, output, null, context); - } - @Override protected void doExecute(ExecutionContext context) { context.setCurrentValue(new StringFieldValue(String.valueOf(context.getCurrentValue()).trim())); diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationException.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationException.java index fb69a1a13ef5..cfc7273d0901 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationException.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationException.java @@ -4,35 +4,35 @@ /** * @author Simon Thoresen Hult */ -public class VerificationException extends IllegalArgumentException { +public class VerificationException extends RuntimeException { private final Class type; - private final String expression; + private final String exp; - public VerificationException(Expression expression, String message) { - super("Invalid expression '" + expression + "': " + message); - if (expression != null) { - this.type = expression.getClass(); - this.expression = expression.toString(); + public VerificationException(Expression exp, String msg) { + super(msg); + if (exp != null) { + this.type = exp.getClass(); + this.exp = exp.toString(); } else { this.type = null; - this.expression = "null"; + this.exp = "null"; } } - public VerificationException(Class expression, String message) { - super("Invalid expression of type '" + expression.getSimpleName() + "': " + message); - this.type = expression; - this.expression = expression.getName(); + public VerificationException(Class exp, String msg) { + super(msg); + this.type = exp; + this.exp = exp.getName(); } - public String getExpression() { return expression; } + public String getExpression() { return exp; } public Class getExpressionType() { return type; } @Override public String toString() { - return getClass().getName() + ": " + getMessage(); + return getClass().getName() + ": For expression '" + exp + "': " + getMessage(); } } 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 e9fb5ace622e..9d6826ba2535 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 @@ -3,7 +3,6 @@ import com.yahoo.document.DataType; import com.yahoo.document.PositionDataType; -import com.yahoo.document.StructDataType; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.Struct; @@ -18,30 +17,6 @@ public ZCurveExpression() { super(PositionDataType.INSTANCE); } - @Override - public DataType setInputType(DataType input, VerificationContext context) { - if ( ! (input instanceof StructDataType struct)) - throw new VerificationException(this, "This requires a struct as input, but got " + input.getName()); - requireIntegerField(PositionDataType.FIELD_X, struct); - requireIntegerField(PositionDataType.FIELD_Y, struct); - - super.setInputType(input, context); - return DataType.LONG; - } - - private void requireIntegerField(String fieldName, StructDataType struct) { - var field = struct.getField(fieldName); - if (field == null || field.getDataType() != DataType.INT) - throw new VerificationException(this, "The struct '" + struct.getName() + - "' does not have an integer field named '" + fieldName + "'"); - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(DataType.LONG, output, null, context); - return null; // There's no 'any' struct - } - @Override protected void doVerify(VerificationContext context) { context.setCurrentType(createdOutputType()); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTestCase.java index 03afa347aa26..b46232f0f2e1 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTestCase.java @@ -246,7 +246,7 @@ public void testArrayEmbedTo3dMixedTensor_missingDimensionArgument() { fail("Expected exception"); } catch (VerificationException e) { - assertEquals("Invalid expression 'embed emb1': When the embedding target field is a 3d tensor the name of the tensor dimension that corresponds to the input array elements must be given as a second argument to embed, e.g: ... | embed colbert paragraph | ...", + assertEquals("When the embedding target field is a 3d tensor the name of the tensor dimension that corresponds to the input array elements must be given as a second argument to embed, e.g: ... | embed colbert paragraph | ...", e.getMessage()); } } @@ -268,7 +268,7 @@ public void testArrayEmbedTo3dMixedTensor_wrongDimensionArgument() { fail("Expected exception"); } catch (VerificationException e) { - assertEquals("Invalid expression 'embed emb1 d': The dimension 'd' given to embed is not a sparse dimension of the target type tensor(d[3],passage{},token{})", + assertEquals("The dimension 'd' given to embed is not a sparse dimension of the target type tensor(d[3],passage{},token{})", e.getMessage()); } } @@ -323,7 +323,7 @@ public void testArrayEmbedTo2dMappedTensor_wrongDimensionArgument() { fail("Expected exception"); } catch (VerificationException e) { - assertEquals("Invalid expression 'embed emb1 doh': The dimension 'doh' given to embed is not a sparse dimension of the target type tensor(passage{},token{})", + assertEquals("The dimension 'doh' given to embed is not a sparse dimension of the target type tensor(passage{},token{})", e.getMessage()); } } 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 158c71b5120e..2a145ae79e3f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -9,7 +9,6 @@ import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.BoolFieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; -import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.vespa.indexinglanguage.expressions.*; import com.yahoo.vespa.indexinglanguage.parser.ParseException; @@ -61,7 +60,7 @@ public void requireThatEachStatementHasEmptyInput() { fail(); } 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("Expected any input, but no input is specified", e.getMessage()); } } @@ -166,32 +165,4 @@ public void testLongHash() throws ParseException { assertEquals(7678158186624760752L, adapter.values.get("myLong").getWrappedValue()); } - @SuppressWarnings("unchecked") - @Test - public void testZCurveArray() throws ParseException { - var expression = Expression.fromString("input location_str | for_each { to_pos } | for_each { zcurve } | attribute location_zcurve"); - - SimpleTestAdapter adapter = new SimpleTestAdapter(); - adapter.createField(new Field("location_str", DataType.getArray(DataType.STRING))); - var zcurveField = new Field("location_zcurve", DataType.getArray(DataType.LONG)); - adapter.createField(zcurveField); - var array = new Array(new ArrayDataType(DataType.STRING)); - array.add(new StringFieldValue("30;40")); - array.add(new StringFieldValue("50;60")); - adapter.setValue("location_str", array); - expression.setStatementOutput(new DocumentType("myDocument"), zcurveField); - - // Necessary to resolve output type - VerificationContext verificationContext = new VerificationContext(adapter); - assertEquals(DataType.getArray(DataType.LONG), expression.verify(verificationContext)); - - ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(array); - expression.execute(context); - assertTrue(adapter.values.containsKey("location_zcurve")); - var longArray = (Array)adapter.values.get("location_zcurve"); - assertEquals( 2516, longArray.get(0).getLong()); - assertEquals(4004, longArray.get(1).getLong()); - } - } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleDocumentAdapterTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleDocumentAdapterTestCase.java index 158b5721fe7c..8fe1fd59d093 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleDocumentAdapterTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleDocumentAdapterTestCase.java @@ -48,7 +48,7 @@ public void requireThatUnknownFieldsReturnNull() { adapter.getInputType(null, "foo"); fail(); } catch (VerificationException e) { - assertEquals("Invalid expression 'null': Input field 'foo' not found", e.getMessage()); + assertEquals("Input field 'foo' not found", e.getMessage()); } assertNull(adapter.getInputValue("foo")); } 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..bee0add22c07 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 @@ -11,7 +11,6 @@ import static com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression.Operator; import static org.junit.Assert.*; -import static org.mockito.Mockito.verify; /** * @author Simon Thoresen Hult @@ -65,19 +64,19 @@ public void requireThatVerifyCallsAreForwarded() { SimpleExpression.newOutput(DataType.INT), null); assertVerifyThrows(SimpleExpression.newOutput(null), Operator.ADD, SimpleExpression.newOutput(DataType.INT), null, - "Expected any output, but no output is specified"); + "Attempting to perform arithmetic on a null value"); assertVerifyThrows(SimpleExpression.newOutput(DataType.INT), Operator.ADD, SimpleExpression.newOutput(null), null, - "Expected any output, but no output is specified"); + "Attempting to perform arithmetic on a null value"); assertVerifyThrows(SimpleExpression.newOutput(null), Operator.ADD, SimpleExpression.newOutput(null), null, - "Expected any output, but no output is specified"); + "Attempting to perform arithmetic on a null value"); assertVerifyThrows(SimpleExpression.newOutput(DataType.INT), Operator.ADD, SimpleExpression.newOutput(DataType.STRING), null, - "The second argument must be a number, but has type string"); + "Attempting to perform unsupported arithmetic: [int] + [string]"); assertVerifyThrows(SimpleExpression.newOutput(DataType.STRING), Operator.ADD, SimpleExpression.newOutput(DataType.STRING), null, - "The first argument must be a number, but has type string"); + "Attempting to perform unsupported arithmetic: [string] + [string]"); } @Test @@ -102,13 +101,13 @@ public void requireThatOperandsAreInputCompatible() { @Test public void requireThatResultIsCalculated() { for (int i = 0; i < 50; ++i) { - LongFieldValue left = new LongFieldValue(i); - LongFieldValue right = new LongFieldValue(100 - i); - assertResult(left, Operator.ADD, right, new LongFieldValue(left.getLong() + right.getLong())); - assertResult(left, Operator.SUB, right, new LongFieldValue(left.getLong() - right.getLong())); - assertResult(left, Operator.DIV, right, new LongFieldValue(left.getLong() / right.getLong())); - assertResult(left, Operator.MOD, right, new LongFieldValue(left.getLong() % right.getLong())); - assertResult(left, Operator.MUL, right, new LongFieldValue(left.getLong() * right.getLong())); + LongFieldValue lhs = new LongFieldValue(i); + LongFieldValue rhs = new LongFieldValue(100 - i); + assertResult(lhs, Operator.ADD, rhs, new LongFieldValue(lhs.getLong() + rhs.getLong())); + assertResult(lhs, Operator.SUB, rhs, new LongFieldValue(lhs.getLong() - rhs.getLong())); + assertResult(lhs, Operator.DIV, rhs, new LongFieldValue(lhs.getLong() / rhs.getLong())); + assertResult(lhs, Operator.MOD, rhs, new LongFieldValue(lhs.getLong() % rhs.getLong())); + assertResult(lhs, Operator.MUL, rhs, new LongFieldValue(lhs.getLong() * rhs.getLong())); } } @@ -196,15 +195,11 @@ private static void assertVerify(Expression lhs, Operator op, Expression rhs, Da private static void assertVerifyThrows(Expression lhs, Operator op, Expression rhs, DataType val, String expectedException) { - ArithmeticExpression expression = null; try { - expression = new ArithmeticExpression(lhs, op, rhs); - expression.verify(val); - fail("Expected exception"); + new ArithmeticExpression(lhs, op, rhs).verify(val); + fail(); } catch (VerificationException e) { - String expressionString = expression == null ? "of type '" + ArithmeticExpression.class.getSimpleName() + "'" - : "'" + expression + "'"; - assertEquals("Invalid expression " + expressionString + ": " + expectedException, e.getMessage()); + assertEquals(expectedException, e.getMessage()); } } } 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..680c27181c1b 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 @@ -38,5 +38,4 @@ public void requireThatExpressionCanBeVerified() { 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 01eed5fdc8bf..2d4f7afc6dc2 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 string input, got long", DataType.LONG, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.LONG, exp, "Expected string input, got long"); } } 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..2f73c07d3c8e 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 long input, got string", DataType.STRING, exp); + assertVerifyThrows(null, exp, "Expected long input, but no input is specified"); + assertVerifyThrows(DataType.STRING, exp, "Expected long input, got string"); } } 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..5a9634e4c3b3 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 @@ -51,16 +51,16 @@ public void requireThatExpressionCanBeVerified() { 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"); + "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"); + "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"); + "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"); + "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..9bce89b62330 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(null, exp, "Expected any input, but no input is specified"); } } 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..bff8b81d4fd1 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,8 +84,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } private static void assertAnnotation(int expectedFrom, int expectedLen, StringFieldValue expectedVal, 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..755e47d64086 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 @@ -13,41 +13,44 @@ */ class ExpressionAssert { - public static void assertVerifyCtx(Expression expression, DataType expectedValueAfter, VerificationContext context) { - assertEquals(expectedValueAfter, expression.verify(context)); + public static void assertVerifyCtx(VerificationContext ctx, Expression exp, DataType expectedValueAfter) { + assertEquals(expectedValueAfter, exp.verify(ctx)); } - public static void assertVerify(DataType valueBefore, Expression expression, DataType expectedValueAfter) { - assertVerifyCtx(expression, expectedValueAfter, new VerificationContext().setCurrentType(valueBefore)); + public static void assertVerify(DataType valueBefore, Expression exp, DataType expectedValueAfter) { + assertVerifyCtx(new VerificationContext().setCurrentType(valueBefore), exp, expectedValueAfter); } - public static void assertVerifyThrows(String expectedMessage, DataType valueBefore, Expression expression) { - assertVerifyThrows(expectedMessage, expression, new VerificationContext().setCurrentType(valueBefore)); + public static void assertVerifyThrows(DataType valueBefore, Expression exp, String expectedException) { + assertVerifyCtxThrows(new VerificationContext().setCurrentType(valueBefore), exp, expectedException); } interface CreateExpression { Expression create(); } - public static void assertVerifyThrows(String expectedMessage, DataType valueBefore, CreateExpression createExpression) { - assertVerifyThrows(expectedMessage, createExpression, new VerificationContext().setCurrentType(valueBefore)); + public static void assertVerifyThrows(DataType valueBefore, CreateExpression createExp, String expectedException) { + assertVerifyCtxThrows(new VerificationContext().setCurrentType(valueBefore), createExp, expectedException); } - public static void assertVerifyThrows(String expectedMessage, CreateExpression createExp, VerificationContext context) { + public static void assertVerifyCtxThrows(VerificationContext ctx, CreateExpression createExp, String expectedException) { try { Expression exp = createExp.create(); - exp.verify(context); - fail("Expected exception"); + exp.verify(ctx); + fail(); } catch (VerificationException e) { - assertEquals(expectedMessage, e.getMessage()); + if (!Pattern.matches(expectedException, e.getMessage())) { + assertEquals(expectedException, e.getMessage()); + } } } - public static void assertVerifyThrows(String expectedMessage, Expression expression, VerificationContext context) { + public static void assertVerifyCtxThrows(VerificationContext ctx, Expression exp, String expectedException) { try { - expression.verify(context); - fail("Expected exception"); + exp.verify(ctx); + fail(); } catch (VerificationException e) { - assertEquals(expectedMessage, e.getMessage()); + if (!Pattern.matches(expectedException, e.getMessage())) { + assertEquals(expectedException, e.getMessage()); + } } } - } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssertTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssertTestCase.java index 28de6e6a1b98..4cfda8cefe7c 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssertTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionAssertTestCase.java @@ -25,8 +25,8 @@ public void requireThatAssertVerifyMethodThrowsWhenAppropriate() { thrown = null; try { - assertVerifyThrows("unchecked expected exception message", DataType.INT, new SimpleExpression() - ); + assertVerifyThrows(DataType.INT, new SimpleExpression(), + "unchecked expected exception message"); } catch (Throwable t) { thrown = t; } @@ -34,8 +34,8 @@ public void requireThatAssertVerifyMethodThrowsWhenAppropriate() { thrown = null; try { - assertVerifyThrows("wrong expected exception message", DataType.INT, SimpleExpression.newRequired(DataType.STRING) - ); + assertVerifyThrows(DataType.INT, SimpleExpression.newRequired(DataType.STRING), + "wrong expected exception message"); } catch (Throwable t) { thrown = t; } 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..92f8fbbfd80d 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,22 +34,22 @@ 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"); + "Expected int input, but no input is specified"); assertVerifyThrows(newRequiredInput(DataType.INT), UnresolvedDataType.INSTANCE, - "Invalid expression 'SimpleExpression': Failed to resolve input type"); + "Failed to resolve input type"); assertVerifyThrows(newRequiredInput(DataType.INT), DataType.STRING, - "Invalid expression 'SimpleExpression': Expected int input, got string"); + "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"); + "Expected int output, but no output is specified"); assertVerifyThrows(newCreatedOutput(DataType.INT, UnresolvedDataType.INSTANCE), null, - "Invalid expression 'SimpleExpression': Failed to resolve output type"); + "Failed to resolve output type"); assertVerifyThrows(newCreatedOutput(DataType.INT, DataType.STRING), null, - "Invalid expression 'SimpleExpression': Expected int output, got string"); + "Expected int output, got string"); } @Test 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..4295917fcccf 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } } 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..0ab1c90b7c55 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,9 +53,9 @@ 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 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); + assertVerifyThrows(null, exp, "Expected any input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected Array, Struct, WeightedSet or Map input, got int"); + assertVerifyThrows(DataType.getArray(DataType.STRING), exp, "Expected int input, got string"); } @Test @@ -63,8 +63,10 @@ public void requireThatStructFieldCompatibilityIsVerified() { StructDataType type = new StructDataType("my_struct"); 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(type, new ForEachExpression(SimpleExpression.newConversion(DataType.STRING, DataType.INT)), + "Expected string input, got int"); + assertVerifyThrows(type, new ForEachExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)), + "Expected int output, got string"); } @Test @@ -213,7 +215,7 @@ public void requireThatIncompatibleStructFieldsFailToValidate() { new ForEachExpression(new ToArrayExpression()).verify(ctx); fail(); } catch (VerificationException e) { - assertEquals("Invalid expression 'for_each { to_array }': Expected int output, got Array", e.getMessage()); + assertEquals("Expected int output, got Array", e.getMessage()); } } 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..b3530cca1fe4 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,9 +38,9 @@ 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 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")); + assertVerifyThrows(null, exp, "Expected any input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected a struct or map, bit got an int"); + assertVerifyThrows(type, new GetFieldExpression("bar"), "Field 'bar' not found in struct type 'my_struct'"); } @Test 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..20fdf562ff1c 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 @@ -41,7 +41,7 @@ public void requireThatExpressionCanBeVerified() { new GetVarExpression("bar").verify(ctx); fail(); } catch (VerificationException e) { - assertEquals("Invalid expression 'get_var bar': Variable 'bar' not found", e.getMessage()); + assertEquals("Variable 'bar' not found", e.getMessage()); } } 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..b8f73c14156c 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,8 +46,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 int input, but no input is specified", null, exp); - assertVerifyThrows("Invalid expression 'guard { SimpleExpression; }': Expected int input, got string", DataType.STRING, exp); + assertVerifyThrows(null, exp, "Expected int input, but no input is specified"); + assertVerifyThrows(DataType.STRING, exp, "Expected int input, got string"); } @Test 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..9cb8977afd7b 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,8 +29,8 @@ 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 string input, got long", DataType.LONG, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.LONG, exp, "Expected string input, got long"); } @Test 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..670172319101 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,8 +29,8 @@ 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 long input, got string", DataType.STRING, exp); + assertVerifyThrows(null, exp, "Expected long input, but no input is specified"); + assertVerifyThrows(DataType.STRING, exp, "Expected long input, got string"); } @Test 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..932652e65717 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 @@ -41,30 +41,29 @@ 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 string 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) - ); - 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) - ); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); + assertVerifyThrows(null, () -> newRequiredInput(DataType.INT, Comparator.EQ, DataType.STRING, + DataType.STRING, DataType.STRING), + "Operands require conflicting input types, int vs string"); + assertVerifyThrows(null, () -> newRequiredInput(DataType.STRING, Comparator.EQ, DataType.INT, + DataType.STRING, DataType.STRING), + "Operands require conflicting input types, string vs int"); + assertVerifyThrows(null, () -> newRequiredInput(DataType.STRING, Comparator.EQ, DataType.STRING, + DataType.INT, DataType.STRING), + "Operands require conflicting input types, string vs int"); + assertVerifyThrows(null, () -> newRequiredInput(DataType.STRING, Comparator.EQ, DataType.STRING, + DataType.STRING, DataType.INT), + "Operands require conflicting input types, string vs int"); } @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 string input, got int", DataType.INT, new FlattenExpression() - ); + assertVerifyThrows(null, new FlattenExpression(), + "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, new FlattenExpression(), + "Expected string input, got int"); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/InputTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/InputTestCase.java index 6f013fdccd92..28f8941064db 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/InputTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/InputTestCase.java @@ -40,7 +40,7 @@ public void requireThatExpressionCanBeVerified() { new InputExpression("bar").verify(adapter); fail(); } catch (VerificationException e) { - assertEquals("Invalid expression 'input bar': Input field 'bar' not found.", e.getMessage()); + assertEquals("Input field 'bar' not found.", e.getMessage()); } } 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..7c997ecebf26 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,8 +36,8 @@ 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 Array input, got type int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected any input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected Array input, got int"); } @Test 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..49085ec7da18 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,8 +28,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test 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..a3ce6a204b24 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,8 +46,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test 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..2c8e2c029e2a 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,8 +43,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test 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..750e3114b624 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 @@ -11,7 +11,7 @@ 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.assertVerifyCtxThrows; import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows; import static org.junit.Assert.*; @@ -76,24 +76,22 @@ public void requireThatHashCodeAndEqualsAreImplemented() { @Test 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 predicate input, got int", DataType.INT, exp); - assertVerifyThrows(prefix + "Variable 'arity' must be set", DataType.PREDICATE, exp); + assertVerifyThrows(null, exp, "Expected predicate input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected predicate input, got int"); + assertVerifyThrows(DataType.PREDICATE, exp, "Variable 'arity' must be set"); VerificationContext context = new VerificationContext().setCurrentType(DataType.PREDICATE); context.setVariable("arity", DataType.STRING); - ExpressionAssert.assertVerifyThrows(prefix + "Variable 'arity' must have type int", exp, context); + assertVerifyCtxThrows(context, exp, "Variable 'arity' must have type int"); context.setVariable("arity", DataType.INT); - assertVerifyCtx(exp, DataType.PREDICATE, context); + assertVerifyCtx(context, exp, DataType.PREDICATE); context.setVariable("lower_bound", DataType.INT); - ExpressionAssert.assertVerifyThrows(prefix + "Variable 'lower_bound' must have type long", exp, context); + assertVerifyCtxThrows(context, exp, "Variable 'lower_bound' must have type long"); context.setVariable("lower_bound", DataType.LONG); - assertVerifyCtx(exp, DataType.PREDICATE, context); + assertVerifyCtx(context, exp, DataType.PREDICATE); context.setVariable("upper_bound", DataType.INT); - ExpressionAssert.assertVerifyThrows(prefix + "Variable 'upper_bound' must have type long", exp, context); + assertVerifyCtxThrows(context, exp, "Variable 'upper_bound' must have type long"); context.setVariable("upper_bound", DataType.LONG); - assertVerifyCtx(exp, DataType.PREDICATE, context); + assertVerifyCtx(context, exp, DataType.PREDICATE); } - } 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..23cbc0ab9760 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 @@ -27,8 +27,8 @@ 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(new VerificationException((Expression) null, "foo")), DataType.INT, exp, "Invalid expression 'null': foo"); + assertVerifyThrows(new MyAdapter(null), null, exp, "Expected any input, but no input is specified"); + assertVerifyThrows(new MyAdapter(new VerificationException((Expression) null, "foo")), DataType.INT, exp, "foo"); } public static void assertVerify(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 6c997356bbfd..54aaba282742 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,8 +37,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 int input, but no input is specified", null, exp); - assertVerifyThrows("Invalid expression '(SimpleExpression)': Expected int input, got string", DataType.STRING, exp); + assertVerifyThrows(null, exp, "Expected int input, but no input is specified"); + assertVerifyThrows(DataType.STRING, exp, "Expected int input, got string"); } @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 14435b14c331..8491736c763f 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 @@ -6,6 +6,7 @@ import com.yahoo.document.Field; import com.yahoo.document.StructDataType; 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.Struct; @@ -61,12 +62,12 @@ 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 int input, got string", DataType.STRING, exp); + assertVerifyThrows(null, exp, "Expected int input, but no input is specified"); + assertVerifyThrows(DataType.STRING, exp, "Expected int input, got string"); - 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))) - ); + assertVerifyThrows(null, () -> newScript(newStatement(SimpleExpression.newConversion(DataType.INT, DataType.STRING)), + newStatement(SimpleExpression.newConversion(DataType.STRING, DataType.INT))), + "Statements require conflicting input types, int vs string"); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputTestCase.java index 1820eea893dd..22bb6085c254 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SelectInputTestCase.java @@ -58,9 +58,9 @@ public void requireThatExpressionCanBeVerified() { assertVerify(adapter, DataType.STRING, exp); assertVerifyThrows(adapter, newSelectInput(new AttributeExpression("my_int"), "my_str"), - "Invalid expression 'attribute my_int': Can not assign string to field 'my_int' which is int."); + "Can not assign string to field 'my_int' which is int."); assertVerifyThrows(adapter, newSelectInput(new AttributeExpression("my_int"), "my_unknown"), - "Invalid expression 'select_input { my_unknown: attribute my_int; }': Input field 'my_unknown' not found."); + "Input field 'my_unknown' not found."); } @Test 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..fae3b0c25d4e 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,8 +29,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test 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..4364865ba24e 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,13 +36,13 @@ 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(null, exp, "Expected any input, but no input is specified"); try { new VerificationContext().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()); + assertEquals("Attempting to assign conflicting types to variable 'foo', int vs string", e.getMessage()); } } @@ -69,7 +69,7 @@ public void requireThatVariableTypeCanNotChange() { fail(); } catch (VerificationException e) { assertTrue(e.getExpressionType().equals(SetVarExpression.class)); - assertEquals("Invalid expression 'set_var out': Cannot set variable 'out' to type string: It is already set to type int", e.getMessage()); + assertEquals("Attempting to assign conflicting types to variable 'out', int vs string", e.getMessage()); } } 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..e7df02f9be25 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,8 +37,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test 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 351df9af3fcf..f134191c4a3d 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 @@ -91,9 +91,9 @@ 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); + assertVerifyThrows(null, exp, "Expected int input, got string"); + assertVerifyThrows(DataType.INT, exp, "Expected int input, got string"); + assertVerifyThrows(DataType.STRING, exp, "Expected int input, got string"); exp = newStatement(SimpleExpression.newOutput(DataType.INT), SimpleExpression.newConversion(DataType.INT, DataType.STRING)); 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..f05e3117ba70 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,8 +37,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test 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..dddc8762b553 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,18 +57,18 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test public void requireThatCasesAreVerified() { Map cases = new HashMap<>(); cases.put("foo", SimpleExpression.newRequired(DataType.INT)); - assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.STRING, new SwitchExpression(cases) - ); - assertVerifyThrows("Invalid expression 'SimpleExpression': Expected int input, got string", DataType.STRING, new SwitchExpression(Map.of(), SimpleExpression.newRequired(DataType.INT)) - ); + assertVerifyThrows(DataType.STRING, new SwitchExpression(cases), + "Expected int input, got string"); + assertVerifyThrows(DataType.STRING, new SwitchExpression(Map.of(), SimpleExpression.newRequired(DataType.INT)), + "Expected int input, got string"); } @Test 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..21c399b8c0cf 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(null, exp, "Expected any input, but no input is specified"); } @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..d1ac4152ee36 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(null, exp, "Expected any input, but no input is specified"); } @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..6ac0a27c11be 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(null, exp, "Expected any input, but no input is specified"); } @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..43f53c45e09c 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(null, exp, "Expected any input, but no input is specified"); } @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..60d3f83c77a1 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(null, exp, "Expected any input, but no input is specified"); } @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..0a98ef845996 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 @@ -27,8 +27,8 @@ public void requireThatHashCodeAndEqualsAreImplemented() { 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(DataType.INT, exp, "Expected string input, got int"); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); } @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..32677aea11f5 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(null, exp, "Expected any input, but no input is specified"); } @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..6812848e0100 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(null, exp, "Expected any input, but no input is specified"); } @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..d88d1c6691d7 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(null, exp, "Expected any input, but no input is specified"); } @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..bd7fe2fe78bc 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,8 +31,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @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 ed41629ae9c3..70ef2302e099 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(null, exp, "Expected any input, but no input is specified"); } @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..0c86fc462209 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 @@ -55,23 +55,22 @@ public void requireThatValueIsConverted() { } private static void assertVerify(boolean createIfNonExistent, boolean removeIfZero) { - Expression expression = new ToWsetExpression(createIfNonExistent, removeIfZero); - ExpressionAssert.assertVerify(DataType.INT, expression, + Expression exp = new ToWsetExpression(createIfNonExistent, removeIfZero); + ExpressionAssert.assertVerify(DataType.INT, exp, DataType.getWeightedSet(DataType.INT, createIfNonExistent, removeIfZero)); - ExpressionAssert.assertVerify(DataType.STRING, expression, + ExpressionAssert.assertVerify(DataType.STRING, exp, DataType.getWeightedSet(DataType.STRING, createIfNonExistent, removeIfZero)); - assertVerifyThrows("Invalid expression '" + expression + "': " + - "Expected any input, but no input is specified", null, expression); + assertVerifyThrows(null, exp, "Expected any input, but no input is specified"); } private static void assertConvert(boolean createIfNonExistent, boolean removeIfZero) { - ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); - context.setCurrentValue(new StringFieldValue("69")).execute(new ToWsetExpression(createIfNonExistent, removeIfZero)); + ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); + ctx.setCurrentValue(new StringFieldValue("69")).execute(new ToWsetExpression(createIfNonExistent, removeIfZero)); - FieldValue value = context.getCurrentValue(); - assertEquals(WeightedSet.class, value.getClass()); + FieldValue val = ctx.getCurrentValue(); + assertEquals(WeightedSet.class, val.getClass()); - WeightedSet wset = (WeightedSet)value; + WeightedSet wset = (WeightedSet)val; WeightedSetDataType type = wset.getDataType(); assertEquals(DataType.STRING, type.getNestedType()); assertEquals(createIfNonExistent, type.createIfNonExistent()); @@ -82,9 +81,8 @@ private static void assertConvert(boolean createIfNonExistent, boolean removeIfZ } private static void assertAccessors(boolean createIfNonExistent, boolean removeIfZero) { - ToWsetExpression expression = new ToWsetExpression(createIfNonExistent, removeIfZero); - assertEquals(createIfNonExistent, expression.getCreateIfNonExistent()); - assertEquals(removeIfZero, expression.getRemoveIfZero()); + ToWsetExpression exp = new ToWsetExpression(createIfNonExistent, removeIfZero); + assertEquals(createIfNonExistent, exp.getCreateIfNonExistent()); + assertEquals(removeIfZero, exp.getRemoveIfZero()); } - } 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..9c0b17dd1220 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,8 +48,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test 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..c2f9d4b126f4 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,8 +28,8 @@ 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 string input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected string input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected string input, got int"); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationExceptionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationExceptionTestCase.java index 1a82d9cb9749..ad94c4592900 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationExceptionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationExceptionTestCase.java @@ -15,7 +15,7 @@ public void requireThatAccessorsWork() { Expression exp = new SimpleExpression(); VerificationException e = new VerificationException(exp, "foo"); assertEquals(exp.toString(), e.getExpression()); - assertEquals("Invalid expression 'SimpleExpression': foo", e.getMessage()); + assertEquals("foo", e.getMessage()); assertTrue(e.toString().contains(exp.toString())); assertTrue(e.toString().contains(e.getMessage())); } 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..4babd49dbc29 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,8 +30,8 @@ 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 position input, got int", DataType.INT, exp); + assertVerifyThrows(null, exp, "Expected position input, but no input is specified"); + assertVerifyThrows(DataType.INT, exp, "Expected position input, got int"); } @Test