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 55abf02e39ea..3f336544a99b 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 @@ -76,7 +76,7 @@ protected boolean shouldConvert(Expression exp) { String fieldName = ((OutputExpression)exp).getFieldName(); if (outputs.contains(fieldName) && !prevNames.contains(fieldName)) { throw new VerificationException(exp, "Attempting to assign conflicting values to field '" + - fieldName + "'"); + fieldName + "'."); } outputs.add(fieldName); prevNames.add(fieldName); @@ -111,24 +111,24 @@ public DataType getInputType(Expression exp, String fieldName) { } @Override - public void tryOutputType(Expression expression, String fieldName, DataType valueType) { + public void tryOutputType(Expression exp, String fieldName, DataType valueType) { String fieldDesc; DataType fieldType; - if (expression instanceof AttributeExpression) { + if (exp instanceof AttributeExpression) { Attribute attribute = schema.getAttribute(fieldName); if (attribute == null) { - throw new VerificationException(expression, "Attribute '" + fieldName + "' not found."); + throw new VerificationException(exp, "Attribute '" + fieldName + "' not found."); } fieldDesc = "attribute"; fieldType = attribute.getDataType(); - } else if (expression instanceof IndexExpression) { + } else if (exp instanceof IndexExpression) { SDField field = schema.getConcreteField(fieldName); if (field == null) { - throw new VerificationException(expression, "Index field '" + fieldName + "' not found."); + throw new VerificationException(exp, "Index field '" + fieldName + "' not found."); } fieldDesc = "index field"; fieldType = field.getDataType(); - } else if (expression instanceof SummaryExpression) { + } else if (exp instanceof SummaryExpression) { SummaryField field = schema.getSummaryField(fieldName); if (field == null) { // Use document field if summary field is not found @@ -137,7 +137,7 @@ public void tryOutputType(Expression expression, String fieldName, DataType valu fieldDesc = "document field"; fieldType = sdField.getDataType(); } else { - throw new VerificationException(expression, "Summary field '" + fieldName + "' not found."); + throw new VerificationException(exp, "Summary field '" + fieldName + "' not found."); } } else { fieldDesc = "summary field"; @@ -148,8 +148,8 @@ public void tryOutputType(Expression expression, String fieldName, DataType valu } if ( ! fieldType.isAssignableFrom(valueType) && ! fieldType.isAssignableFrom(createCompatType(valueType))) { - throw new VerificationException(expression, "Can not assign " + valueType.getName() + " to " + fieldDesc + - " '" + fieldName + "' which is " + fieldType.getName() + "."); + throw new VerificationException(exp, "Can not assign " + valueType.getName() + " to " + fieldDesc + + " '" + fieldName + "' which is " + fieldType.getName() + "."); } } 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 ebaa0ef37b0e..d5af996bd59b 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 @@ -57,7 +57,7 @@ void requireThatOutputConflictThrows() throws ParseException { } catch (IllegalArgumentException e) { assertEquals("For schema 'indexing_output_confict', field 'bar': For expression 'index bar': Attempting " + - "to assign conflicting values to field 'bar'", + "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 898f3f5b23d7..4053834784f8 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 @@ -36,7 +36,7 @@ void testAttributeChanged() throws ParseException { } catch (IllegalArgumentException e) { assertEquals("For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " + - "Attempting to assign conflicting values to field 'foo'", + "Attempting to assign conflicting values to field 'foo'.", Exceptions.toMessageString(e)); } } @@ -80,7 +80,7 @@ void testIndexChanged() throws ParseException { } catch (IllegalArgumentException e) { assertEquals("For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " + - "Attempting to assign conflicting values to field 'foo'", + "Attempting to assign conflicting values to field 'foo'.", Exceptions.toMessageString(e)); } } @@ -124,7 +124,7 @@ void testSummaryChanged() throws ParseException { } catch (IllegalArgumentException e) { assertEquals("For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " + - "to assign conflicting values to field 'foo'", + "to assign conflicting values to field 'foo'.", Exceptions.toMessageString(e)); } } @@ -186,7 +186,7 @@ void requireThatMultilineOutputConflictThrows() throws ParseException { } catch (IllegalArgumentException e) { assertEquals("For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " + - "Attempting to assign conflicting values to field '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 ba2313dcf0b1..89c0e4e27196 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -200,7 +200,6 @@ "public int getCode()", "public com.yahoo.document.FieldPath buildFieldPath(java.lang.String)", "public com.yahoo.document.PrimitiveDataType getPrimitiveType()", - "public com.yahoo.document.DataType getNestedType()", "public void visitMembers(com.yahoo.vespa.objects.ObjectVisitor)", "public int compareTo(com.yahoo.document.DataType)", "public boolean isMultivalue()", diff --git a/document/src/main/java/com/yahoo/document/ArrayDataType.java b/document/src/main/java/com/yahoo/document/ArrayDataType.java index 05b578f74457..b14e6cd8a424 100644 --- a/document/src/main/java/com/yahoo/document/ArrayDataType.java +++ b/document/src/main/java/com/yahoo/document/ArrayDataType.java @@ -24,12 +24,10 @@ public ArrayDataType(DataType nestedType, int code) { super("Array<"+nestedType.getName()+">", code, nestedType); } - @Override public ArrayDataType clone() { return (ArrayDataType) super.clone(); } - @Override public Array createFieldValue() { return new Array(this); } diff --git a/document/src/main/java/com/yahoo/document/CollectionDataType.java b/document/src/main/java/com/yahoo/document/CollectionDataType.java index 98be8d4709f5..d580e27d4371 100644 --- a/document/src/main/java/com/yahoo/document/CollectionDataType.java +++ b/document/src/main/java/com/yahoo/document/CollectionDataType.java @@ -33,8 +33,9 @@ public CollectionDataType clone() { return type; } - @Override - public DataType getNestedType() { return nestedType; } + public DataType getNestedType() { + return nestedType; + } @Override protected FieldValue createByReflection(Object arg) { return null; } diff --git a/document/src/main/java/com/yahoo/document/DataType.java b/document/src/main/java/com/yahoo/document/DataType.java index 7a49938334fa..64bd462fb34d 100644 --- a/document/src/main/java/com/yahoo/document/DataType.java +++ b/document/src/main/java/com/yahoo/document/DataType.java @@ -291,10 +291,9 @@ public FieldPath buildFieldPath(String fieldPathString) { * * @return primitive data type, or null */ - public PrimitiveDataType getPrimitiveType() { return null; } - - /** Returns the nested type of this if it is a collection type, null otherwise. */ - public DataType getNestedType() { return null; } + public PrimitiveDataType getPrimitiveType() { + return null; + } @Override public void visitMembers(ObjectVisitor visitor) { 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 deleted file mode 100644 index 3b401ae40851..000000000000 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyDataType.java +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.indexinglanguage.expressions; - -import com.yahoo.document.DataType; -import com.yahoo.document.datatypes.FieldValue; - -/** - * A DataType representing "any". This is (so far) only needed during type resolution of indexing pipelines - * so it is placed here. - * - * @author bratseth - */ -class AnyDataType extends DataType { - - static final AnyDataType instance = new AnyDataType(); - - private AnyDataType() { - super("any", DataType.lastPredefinedDataTypeId() + 1); - } - - @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 1a5bda47b8be..5a12ce76d2b6 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 @@ -10,7 +10,6 @@ import java.math.BigDecimal; import java.math.MathContext; -import java.util.Objects; /** * @author Simon Thoresen Hult @@ -49,45 +48,59 @@ public String toString() { public ArithmeticExpression(Expression left, Operator op, Expression right) { super(requiredInputType(left, right)); - this.left = Objects.requireNonNull(left); - this.op = Objects.requireNonNull(op); - this.right = Objects.requireNonNull(right); + left.getClass(); // throws NullPointerException + op.getClass(); + right.getClass(); + this.left = left; + this.op = op; + this.right = right; } - public Expression getLeftHandSide() { return left; } - - public Operator getOperator() { return op; } - - public Expression getRightHandSide() { return right; } - @Override public ArithmeticExpression convertChildren(ExpressionConverter converter) { // TODO: branch()? return new ArithmeticExpression(converter.convert(left), op, converter.convert(right)); } - @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); - context.setCurrentType(evaluate(context.setCurrentType(input).verify(left).getCurrentType(), - context.setCurrentType(input).verify(right).getCurrentType())); + public Expression getLeftHandSide() { + return left; + } + + public Operator getOperator() { + return op; + } + + public Expression getRightHandSide() { + return right; } @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); - context.setCurrentValue(evaluate(context.setCurrentValue(input).execute(left).getCurrentValue(), - context.setCurrentValue(input).execute(right).getCurrentValue())); + FieldValue input = context.getValue(); + context.setValue(evaluate(context.setValue(input).execute(left).getValue(), + context.setValue(input).execute(right).getValue())); + } + + @Override + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); + context.setValueType(evaluate(context.setValueType(input).execute(left).getValueType(), + context.setValueType(input).execute(right).getValueType())); } 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)) + if (lhsType == null) { + return rhsType; + } + if (rhsType == null) { + return lhsType; + } + if (!lhsType.equals(rhsType)) { throw new VerificationException(ArithmeticExpression.class, "Operands require conflicting input types, " + lhsType.getName() + " vs " + rhsType.getName()); + } return lhsType; } @@ -102,12 +115,20 @@ public String toString() { } @Override - public boolean equals(Object object) { - if (!(object instanceof ArithmeticExpression expression)) return false; - - if (!left.equals(expression.left)) return false; - if (!op.equals(expression.op)) return false; - if (!right.equals(expression.right)) return false; + public boolean equals(Object obj) { + if (!(obj instanceof ArithmeticExpression)) { + return false; + } + ArithmeticExpression exp = (ArithmeticExpression)obj; + if (!left.equals(exp.left)) { + return false; + } + if (!op.equals(exp.op)) { + return false; + } + if (!right.equals(exp.right)) { + return false; + } return true; } @@ -117,28 +138,39 @@ public int hashCode() { } private DataType evaluate(DataType lhs, DataType rhs) { - if (lhs == null || rhs == null) + if (lhs == null || rhs == null) { throw new VerificationException(this, "Attempting to perform arithmetic on a null value"); - if (!(lhs instanceof NumericDataType) || !(rhs instanceof NumericDataType)) + } + 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) + } + 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) + 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)) + if (lhs == null || rhs == null) { + return null; + } + if (!(lhs instanceof NumericFieldValue) || + !(rhs instanceof NumericFieldValue)) + { throw new IllegalArgumentException("Unsupported operation: [" + lhs.getDataType().getName() + "] " + op + " [" + rhs.getDataType().getName() + "]"); - + } BigDecimal lhsVal = asBigDecimal((NumericFieldValue)lhs); BigDecimal rhsVal = asBigDecimal((NumericFieldValue)rhs); return switch (op) { @@ -152,27 +184,31 @@ private FieldValue evaluate(FieldValue lhs, FieldValue rhs) { private FieldValue createFieldValue(FieldValue lhs, FieldValue rhs, BigDecimal val) { if (lhs instanceof FloatFieldValue || lhs instanceof DoubleFieldValue || - rhs instanceof FloatFieldValue || rhs instanceof DoubleFieldValue) { - if (lhs instanceof DoubleFieldValue || rhs instanceof DoubleFieldValue) + rhs instanceof FloatFieldValue || rhs instanceof DoubleFieldValue) + { + if (lhs instanceof DoubleFieldValue || rhs instanceof DoubleFieldValue) { return new DoubleFieldValue(val.doubleValue()); + } return new FloatFieldValue(val.floatValue()); } - if (lhs instanceof LongFieldValue || rhs instanceof LongFieldValue) + if (lhs instanceof LongFieldValue || rhs instanceof LongFieldValue) { return new LongFieldValue(val.longValue()); + } return new IntegerFieldValue(val.intValue()); } public static BigDecimal asBigDecimal(NumericFieldValue value) { - if (value instanceof ByteFieldValue) + if (value instanceof ByteFieldValue) { return BigDecimal.valueOf(((ByteFieldValue)value).getByte()); - else if (value instanceof DoubleFieldValue) + } else if (value instanceof DoubleFieldValue) { return BigDecimal.valueOf(((DoubleFieldValue)value).getDouble()); - else if (value instanceof FloatFieldValue) + } else if (value instanceof FloatFieldValue) { return BigDecimal.valueOf(((FloatFieldValue)value).getFloat()); - else if (value instanceof IntegerFieldValue) + } else if (value instanceof IntegerFieldValue) { return BigDecimal.valueOf(((IntegerFieldValue)value).getInteger()); - else if (value instanceof LongFieldValue) + } else if (value instanceof LongFieldValue) { return BigDecimal.valueOf(((LongFieldValue)value).getLong()); + } throw new IllegalArgumentException("Unsupported numeric field value type '" + value.getClass().getName() + "'"); } @@ -182,5 +218,4 @@ public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) left.select(predicate, operation); right.select(predicate, operation); } - } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpression.java index 64544a4dafb6..fee96513786c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AttributeExpression.java @@ -14,5 +14,4 @@ public AttributeExpression(String fieldName) { public boolean equals(Object obj) { return super.equals(obj) && obj instanceof AttributeExpression; } - } 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 2ad8a2bac573..ea9e778ddfbe 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/Base64DecodeExpression.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; -import com.yahoo.document.TensorDataType; import com.yahoo.document.datatypes.LongFieldValue; import java.util.Base64; @@ -16,28 +15,11 @@ public Base64DecodeExpression() { 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(outputType, DataType.LONG, context); - return DataType.STRING; - } - - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); - } - @Override protected void doExecute(ExecutionContext context) { - String input = String.valueOf(context.getCurrentValue()); - if (input.isEmpty()) { // TODO: Or if context.getCurrentValue() is null or if context.getCurrentValue().getDataType() != DataType.STRING - context.setCurrentValue(new LongFieldValue(Long.MIN_VALUE)); + String input = String.valueOf(context.getValue()); + if (input.isEmpty()) { + context.setValue(new LongFieldValue(Long.MIN_VALUE)); return; } if (input.length() > 12) { @@ -51,14 +33,23 @@ protected void doExecute(ExecutionContext context) { for (int i = decoded.length; --i >= 0;) { output = (output << 8) + (((int)decoded[i]) & 0xff); } - context.setCurrentValue(new LongFieldValue(output)); + context.setValue(new LongFieldValue(output)); + } + + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.LONG; } + public DataType createdOutputType() { + return DataType.LONG; + } @Override - public String toString() { return "base64decode"; } + public String toString() { + return "base64decode"; + } @Override public boolean equals(Object obj) { @@ -66,6 +57,7 @@ public boolean equals(Object obj) { } @Override - public int hashCode() { return getClass().hashCode(); } - + public int hashCode() { + return getClass().hashCode(); + } } 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 e430d5ce8fb5..5cdaf0ab5db1 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 @@ -15,45 +15,38 @@ public final class Base64EncodeExpression extends Expression { public Base64EncodeExpression() { super(DataType.LONG); } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, DataType.LONG, context); - return DataType.STRING; - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, DataType.STRING, context); - return DataType.LONG; - } - - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); - } - @Override protected void doExecute(ExecutionContext context) { - long input = ((LongFieldValue) context.getCurrentValue()).getLong(); + long input = ((LongFieldValue) context.getValue()).getLong(); byte[] output = new byte[8]; for (int i = 0; i < output.length; ++i) { output[i] = (byte)(input & 0xffL); input >>>= 8; } String encoded = Base64.getEncoder().encodeToString(output); - context.setCurrentValue(new StringFieldValue(encoded)); + context.setValue(new StringFieldValue(encoded)); + } + + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.STRING; } + public DataType createdOutputType() { + return DataType.STRING; + } @Override - public String toString() { return "base64encode"; } + public String toString() { + return "base64encode"; + } @Override public boolean equals(Object obj) { - if (!(obj instanceof Base64EncodeExpression)) return false; + if (!(obj instanceof Base64EncodeExpression)) { + return false; + } return true; } @@ -61,5 +54,4 @@ public boolean equals(Object obj) { public int hashCode() { return getClass().hashCode(); } - } 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 8c28f53be8ed..491860cd788e 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 @@ -32,29 +32,19 @@ public BinarizeExpression(double threshold) { } @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - return super.setInputType(inputType, TensorDataType.any(), context); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - return super.setOutputType(outputType, TensorDataType.any(), context); + protected void doExecute(ExecutionContext context) { + Optional tensor = ((TensorFieldValue)context.getValue()).getTensor(); + if (tensor.isEmpty()) return; + context.setValue(new TensorFieldValue(tensor.get().map(v -> v > threshold ? 1 : 0))); } @Override protected void doVerify(VerificationContext context) { - type = context.getCurrentType(); + type = context.getValueType(); if (! (type instanceof TensorDataType)) throw new IllegalArgumentException("The 'binarize' function requires a tensor, but got " + type); } - @Override - protected void doExecute(ExecutionContext context) { - Optional tensor = ((TensorFieldValue)context.getCurrentValue()).getTensor(); - if (tensor.isEmpty()) return; - context.setCurrentValue(new TensorFieldValue(tensor.get().map(v -> v > threshold ? 1 : 0))); - } - @Override public DataType createdOutputType() { return type; } @@ -67,9 +57,6 @@ public String toString() { public int hashCode() { return Objects.hash(threshold, toString().hashCode()); } @Override - public boolean equals(Object o) { - if ( ! (o instanceof BinarizeExpression other)) return false; - return this.threshold == other.threshold; - } + public boolean equals(Object o) { return o instanceof BinarizeExpression; } } 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 61fa94402032..8ae77aad1b1e 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 @@ -6,19 +6,22 @@ /** * Utility expression that will busy-wait the amount of time given in the numeric field. - * Non-numeric fields will be ignored. - * + * Non-numeric fields will be ignored * @author baldersheim */ public final class BusyWaitExpression extends Expression { - public BusyWaitExpression() { super(UnresolvedDataType.INSTANCE); } + private static double nihlakanta(int i) { + long a = 2 + i * 4L; + return (24 * (a+2))/(double)(a*(a+1)*(a+2)*(a+3)); + } + @Override protected void doExecute(ExecutionContext context) { - FieldValue value = context.getCurrentValue(); + FieldValue value = context.getValue(); if (value instanceof NumericFieldValue num) { double napSecs = num.getNumber().doubleValue(); long doom = System.nanoTime() + (long)(1_000_000_000.0 * napSecs); @@ -32,11 +35,7 @@ protected void doExecute(ExecutionContext context) { } } - private static double nihlakanta(int i) { - long a = 2 + i * 4L; - return (24 * (a+2))/(double)(a*(a+1)*(a+2)*(a+3)); - } - + @Override protected void doVerify(VerificationContext context) { } @Override public DataType createdOutputType() { return null; } @Override public String toString() { return "busy_wait"; } @Override public boolean equals(Object obj) { return obj instanceof BusyWaitExpression; } 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 be6d0f7c473c..c12239a99c3d 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 @@ -18,12 +18,12 @@ */ public final class CatExpression extends ExpressionList { - public CatExpression(Expression... expressions) { - this(List.of(expressions)); + public CatExpression(Expression... lst) { + this(List.of(lst)); } - public CatExpression(Collection expressions) { - super(expressions, resolveInputType(expressions)); + public CatExpression(Collection lst) { + super(lst, resolveInputType(lst)); } @Override @@ -31,42 +31,42 @@ public CatExpression convertChildren(ExpressionConverter converter) { return new CatExpression(convertChildList(converter)); } - @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); - List types = new LinkedList<>(); - for (Expression exp : this) { - DataType val = context.setCurrentType(input).verify(exp).getCurrentType(); - types.add(val); - if (val == null) { - throw new VerificationException(this, "Attempting to concatenate a null value (" + exp + ")"); - } - } - context.setCurrentType(resolveOutputType(types)); - } - @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); + FieldValue input = context.getValue(); DataType inputType = input != null ? input.getDataType() : null; - VerificationContext verificationContext = new VerificationContext(context.getFieldValue()); - context.fillVariableTypes(verificationContext); + VerificationContext ver = new VerificationContext(context); + context.fillVariableTypes(ver); List values = new LinkedList<>(); List types = new LinkedList<>(); for (Expression exp : this) { - FieldValue val = context.setCurrentValue(input).execute(exp).getCurrentValue(); + FieldValue val = context.setValue(input).execute(exp).getValue(); values.add(val); DataType type; if (val != null) { type = val.getDataType(); } else { - type = verificationContext.setCurrentType(inputType).verify(this).getCurrentType(); + type = ver.setValueType(inputType).execute(this).getValueType(); } types.add(type); } DataType type = resolveOutputType(types); - context.setCurrentValue(type == DataType.STRING ? asString(values) : asCollection(type, values)); + context.setValue(type == DataType.STRING ? asString(values) : asCollection(type, values)); + } + + @Override + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); + List types = new LinkedList<>(); + for (Expression exp : this) { + DataType val = context.setValueType(input).execute(exp).getValueType(); + types.add(val); + if (val == null) { + throw new VerificationException(this, "Attempting to concatenate a null value (" + exp + ")"); + } + } + context.setValueType(resolveOutputType(types)); } private static DataType resolveInputType(Collection list) { 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 02443ced8112..7a556bd90d05 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 @@ -36,24 +36,24 @@ public ChoiceExpression convertChildren(ExpressionConverter converter) { return new ChoiceExpression(asList().stream().map(choice -> converter.branch().convert(choice)).toList()); } - @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); - context.setCurrentType(input); - for (Expression exp : this) - context.setCurrentType(input).verify(exp); - } - @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); + FieldValue input = context.getValue(); for (Expression expression : this) { - context.setCurrentValue(input).execute(expression); - if (context.getCurrentValue() != null) + context.setValue(input).execute(expression); + if (context.getValue() != null) break; // value found } } + @Override + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); + context.setValueType(input); + for (Expression exp : this) + context.setValueType(input).execute(exp); + } + private static DataType resolveInputType(Collection list) { DataType previousInput = null; DataType previousOutput = null; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java index 48b69525df52..d7823b8d6a5e 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateExpression.java @@ -13,20 +13,24 @@ public ClearStateExpression() { } @Override - protected void doVerify(VerificationContext context) { + protected void doExecute(ExecutionContext context) { context.clear(); } @Override - protected void doExecute(ExecutionContext context) { + protected void doVerify(VerificationContext context) { context.clear(); } @Override - public DataType createdOutputType() { return null; } + public DataType createdOutputType() { + return null; + } @Override - public String toString() { return "clear_state"; } + public String toString() { + return "clear_state"; + } @Override public boolean equals(Object obj) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java index df1ec9e39b44..fbc47e59ffae 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/CompositeExpression.java @@ -17,10 +17,12 @@ protected CompositeExpression(DataType inputType) { } protected static String toScriptBlock(Expression exp) { - if (exp instanceof ScriptExpression) + if (exp instanceof ScriptExpression) { return exp.toString(); - if (exp instanceof StatementExpression) + } + if (exp instanceof StatementExpression) { return new ScriptExpression((StatementExpression)exp).toString(); + } return new ScriptExpression(new StatementExpression(exp)).toString(); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java index 986556a343f4..76ff93295983 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ConstantExpression.java @@ -21,31 +21,18 @@ public ConstantExpression(FieldValue value) { this.value = Objects.requireNonNull(value); } - public FieldValue getValue() { return value; } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return value.getDataType(); + public FieldValue getValue() { + return value; } @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - // TODO: - //if (outputType != value.getDataType()) - // throw new IllegalArgumentException(this + " produces a " + value.getDataType() + ", but a " + - // outputType + " is required"); - return super.setOutputType(outputType, context); + protected void doExecute(ExecutionContext context) { + context.setValue(value); } @Override protected void doVerify(VerificationContext context) { - context.setCurrentType(value.getDataType()); - } - - @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(value); + context.setValueType(value.getDataType()); } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java index 173f086d9231..4001e2a6fd04 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EchoExpression.java @@ -21,22 +21,34 @@ public EchoExpression(PrintStream out) { this.out = out; } - public PrintStream getOutputStream() { return out; } + public PrintStream getOutputStream() { + return out; + } @Override protected void doExecute(ExecutionContext context) { - out.println(context.getCurrentValue()); + out.println(context.getValue()); + } + + @Override + protected void doVerify(VerificationContext context) { + // empty } @Override - public DataType createdOutputType() { return null; } + public DataType createdOutputType() { + return null; + } @Override - public String toString() { return "echo"; } + public String toString() { + return "echo"; + } @Override public boolean equals(Object obj) { if (!(obj instanceof EchoExpression rhs)) return false; + return out == rhs.out; } @@ -44,5 +56,4 @@ public boolean equals(Object obj) { public int hashCode() { return getClass().hashCode() + out.hashCode(); } - } 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 1fbad0298827..8a51ce2c5b41 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java @@ -64,82 +64,38 @@ else if ( ! embedders.containsKey(embedderId)) { } } - @Override - public DataType setInputType(DataType type, VerificationContext context) { - super.setInputType(type, context); - if ( ! (type == DataType.STRING) - && ! (type instanceof ArrayDataType array && array.getNestedType() == DataType.STRING)) - 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(type, TensorDataType.any(), context); - return getInputType(context); // the input (string vs. array of string) cannot be determined from the output - } - @Override public void setStatementOutput(DocumentType documentType, Field field) { targetType = toTargetTensor(field.getDataType()); destination = documentType.getName() + "." + field.getName(); } - @Override - protected void doVerify(VerificationContext context) { - targetType = toTargetTensor(getOutputType(context)); - if ( ! validTarget(targetType)) - throw new VerificationException(this, "The embedding target field must either be a dense 1d tensor, a mapped 1d tensor, a mapped 2d tensor, " + - "an array of dense 1d tensors, or a mixed 2d or 3d tensor"); - if (targetType.rank() == 2 && targetType.mappedSubtype().rank() == 2) { - if (embedderArguments.size() != 1) - throw new VerificationException(this, "When the embedding target field is a 2d mapped 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 splade paragraph | ..."); - if ( ! targetType.mappedSubtype().dimensionNames().contains(embedderArguments.get(0))) { - throw new VerificationException(this, "The dimension '" + embedderArguments.get(0) + "' given to embed " + - "is not a sparse dimension of the target type " + targetType); - - } - } - if (targetType.rank() == 3) { - if (embedderArguments.size() != 1) - throw new VerificationException(this, "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 | ..."); - if ( ! targetType.mappedSubtype().dimensionNames().contains(embedderArguments.get(0))) - throw new VerificationException(this, "The dimension '" + embedderArguments.get(0) + "' given to embed " + - "is not a sparse dimension of the target type " + targetType); - } - context.setCurrentType(createdOutputType()); - } - @Override protected void doExecute(ExecutionContext context) { - if (context.getCurrentValue() == null) return; + if (context.getValue() == null) return; Tensor output; - if (context.getCurrentValue().getDataType() == DataType.STRING) { + if (context.getValue().getDataType() == DataType.STRING) { output = embedSingleValue(context); } - else if (context.getCurrentValue().getDataType() instanceof ArrayDataType arrayType - && arrayType.getNestedType() == DataType.STRING) { + else if (context.getValue().getDataType() instanceof ArrayDataType && + ((ArrayDataType)context.getValue().getDataType()).getNestedType() == DataType.STRING) { output = embedArrayValue(context); } else { throw new IllegalArgumentException("Embedding can only be done on string or string array fields, not " + - context.getCurrentValue().getDataType()); + context.getValue().getDataType()); } - context.setCurrentValue(new TensorFieldValue(output)); + context.setValue(new TensorFieldValue(output)); } private Tensor embedSingleValue(ExecutionContext context) { - StringFieldValue input = (StringFieldValue)context.getCurrentValue(); + StringFieldValue input = (StringFieldValue)context.getValue(); return embed(input.getString(), targetType, context); } @SuppressWarnings("unchecked") private Tensor embedArrayValue(ExecutionContext context) { - var input = (Array)context.getCurrentValue(); + var input = (Array)context.getValue(); var builder = Tensor.Builder.of(targetType); if (targetType.rank() == 2) if (targetType.indexedSubtype().rank() == 1) @@ -221,13 +177,47 @@ private Tensor embed(String input, TensorType targetType, ExecutionContext conte targetType); } + @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 tensor type to embed into"); + targetType = toTargetTensor(context.getInputType(this, outputField)); + if ( ! validTarget(targetType)) + throw new VerificationException(this, "The embedding target field must either be a dense 1d tensor, a mapped 1d tensor, a mapped 2d tensor, " + + "an array of dense 1d tensors, or a mixed 2d or 3d tensor"); + if (targetType.rank() == 2 && targetType.mappedSubtype().rank() == 2) { + if (embedderArguments.size() != 1) + throw new VerificationException(this, "When the embedding target field is a 2d mapped 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 splade paragraph | ..."); + if ( ! targetType.mappedSubtype().dimensionNames().contains(embedderArguments.get(0))) { + throw new VerificationException(this, "The dimension '" + embedderArguments.get(0) + "' given to embed " + + "is not a sparse dimension of the target type " + targetType); + + } + } + if (targetType.rank() == 3) { + if (embedderArguments.size() != 1) + throw new VerificationException(this, "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 | ..."); + if ( ! targetType.mappedSubtype().dimensionNames().contains(embedderArguments.get(0))) + throw new VerificationException(this, "The dimension '" + embedderArguments.get(0) + "' given to embed " + + "is not a sparse dimension of the target type " + targetType); + } + + context.setValueType(createdOutputType()); + } + @Override public DataType createdOutputType() { return new TensorDataType(targetType); } private static TensorType toTargetTensor(DataType dataType) { - if (dataType instanceof ArrayDataType) return toTargetTensor(dataType.getNestedType()); + if (dataType instanceof ArrayDataType) return toTargetTensor(((ArrayDataType) dataType).getNestedType()); if ( ! ( dataType instanceof TensorDataType)) throw new IllegalArgumentException("Expected a tensor data type but got " + dataType); return ((TensorDataType)dataType).getTensorType(); 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 259a89e98032..7481363b7372 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 @@ -23,7 +23,7 @@ */ public final class ExactExpression extends Expression { - private final int maxTokenLength; + private int maxTokenLength; private ExactExpression(OptionalInt maxTokenLength) { super(DataType.STRING); @@ -40,11 +40,11 @@ public ExactExpression(int maxTokenLength) { @Override protected void doExecute(ExecutionContext context) { - StringFieldValue input = (StringFieldValue) context.getCurrentValue(); + StringFieldValue input = (StringFieldValue) context.getValue(); if (input.getString().isEmpty()) return; StringFieldValue output = input.clone(); - context.setCurrentValue(output); + context.setValue(output); String prev = output.getString(); String next = toLowerCase(prev); @@ -74,16 +74,24 @@ protected void doExecute(ExecutionContext context) { } @Override - public DataType createdOutputType() { return null; } + protected void doVerify(VerificationContext context) { + // empty + } + + @Override + public DataType createdOutputType() { + return null; + } @Override - public String toString() { - StringBuilder s = new StringBuilder(); - s.append("exact"); + public String toString() + { + StringBuilder ret = new StringBuilder(); + ret.append("exact"); if (maxTokenLength != AnnotatorConfig.getDefaultMaxTokenLength()) { - s.append(" max-token-length:").append(maxTokenLength); + ret.append(" max-token-length:" + maxTokenLength); } - return s.toString(); + return ret.toString(); } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContext.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContext.java index ea659eb622ea..dc7c11394f90 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContext.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContext.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.collections.LazyMap; +import com.yahoo.document.DataType; import com.yahoo.document.FieldPath; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.language.Language; @@ -15,11 +16,11 @@ /** * @author Simon Thoresen Hult */ -public class ExecutionContext { +public class ExecutionContext implements FieldTypeAdapter, FieldValueAdapter { private final Map variables = new HashMap<>(); - private final FieldValueAdapter fieldValue; - private FieldValue currentValue; + private final FieldValueAdapter adapter; + private FieldValue value; private Language language; private final Map cache = LazyMap.newHashMap(); @@ -27,8 +28,8 @@ public ExecutionContext() { this(null); } - public ExecutionContext(FieldValueAdapter fieldValue) { - this.fieldValue = fieldValue; + public ExecutionContext(FieldValueAdapter adapter) { + this.adapter = adapter; this.language = Language.UNKNOWN; } @@ -43,58 +44,54 @@ public ExecutionContext execute(Expression expression) { * or a partial execution of only the statements accessing the available data. */ public boolean isComplete() { - return fieldValue != null && fieldValue.isComplete(); + return adapter != null && adapter.isComplete(); } - public FieldValue getFieldValue(String fieldName) { - return fieldValue.getInputValue(fieldName); + @Override + public DataType getInputType(Expression exp, String fieldName) { + return adapter.getInputType(exp, fieldName); } - public FieldValue getFieldValue(FieldPath fieldPath) { - return fieldValue.getInputValue(fieldPath); - } - - public ExecutionContext setFieldValue(String fieldName, FieldValue fieldValue, Expression expression) { - this.fieldValue.setOutputValue(expression, fieldName, fieldValue); - return this; + @Override + public FieldValue getInputValue(String fieldName) { + if (adapter == null) { + throw new IllegalStateException("Can not get field '" + fieldName + "' because adapter is null"); + } + return adapter.getInputValue(fieldName); } - public FieldValueAdapter getFieldValue() { return fieldValue; } - - public FieldValue getVariable(String name) { - return variables.get(name); + @Override + public FieldValue getInputValue(FieldPath fieldPath) { + if (adapter == null) { + throw new IllegalStateException("Can not get field '" + fieldPath + "' because adapter is null"); + } + return adapter.getInputValue(fieldPath); } - public ExecutionContext setVariable(String name, FieldValue value) { - variables.put(name, value); - return this; + @Override + public void tryOutputType(Expression exp, String fieldName, DataType valueType) { + adapter.tryOutputType(exp, fieldName, valueType); } - public FieldValue getCurrentValue() { return currentValue; } - - public ExecutionContext setCurrentValue(FieldValue value) { - this.currentValue = value; + @Override + public ExecutionContext setOutputValue(Expression exp, String fieldName, FieldValue fieldValue) { + if (adapter == null) + throw new IllegalStateException("Can not set field '" + fieldName + "' because adapter is null"); + adapter.setOutputValue(exp, fieldName, fieldValue); return this; } - /** Returns a cached value, or null if not present. */ - public Object getCachedValue(Object key) { - return cache.get(key); - } - - public void putCachedValue(String key, Object value) { - cache.put(key, value); + public FieldValueAdapter getAdapter() { + return adapter; } - /** Returns a mutable reference to the cache of this. */ - public Map getCache() { - return cache; + public FieldValue getVariable(String name) { + return variables.get(name); } - void fillVariableTypes(VerificationContext vctx) { - for (var entry : variables.entrySet()) { - vctx.setVariable(entry.getKey(), entry.getValue().getDataType()); - } + public ExecutionContext setVariable(String name, FieldValue value) { + variables.put(name, value); + return this; } public Language getLanguage() { return language; } @@ -108,7 +105,7 @@ public Language resolveLanguage(Linguistics linguistics) { if (language != Language.UNKNOWN) return language; if (linguistics == null) return Language.ENGLISH; - Detection detection = linguistics.getDetector().detect(String.valueOf(currentValue), null); + Detection detection = linguistics.getDetector().detect(String.valueOf(value), null); if (detection == null) return Language.ENGLISH; Language detected = detection.getLanguage(); @@ -116,11 +113,38 @@ public Language resolveLanguage(Linguistics linguistics) { return detected; } + public FieldValue getValue() { return value; } + + public ExecutionContext setValue(FieldValue value) { + this.value = value; + return this; + } + + public void putCachedValue(String key, Object value) { + cache.put(key, value); + } + + /** Returns a cached value, or null if not present. */ + public Object getCachedValue(Object key) { + return cache.get(key); + } + + /** Returns a mutable reference to the cache of this. */ + public Map getCache() { + return cache; + } + /** Clears all state in this except the cache. */ public ExecutionContext clear() { variables.clear(); - currentValue = null; + value = null; return this; } + void fillVariableTypes(VerificationContext vctx) { + for (var entry : variables.entrySet()) { + vctx.setVariable(entry.getKey(), entry.getValue().getDataType()); + } + } + } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java index 363f08ddb07e..118ab14ad7bb 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionValueExpression.java @@ -30,10 +30,17 @@ protected void doExecute(ExecutionContext context) { } @Override - public DataType createdOutputType() { return UnresolvedDataType.INSTANCE; } + protected void doVerify(VerificationContext context) {} @Override - public String toString() { return "_"; } + public DataType createdOutputType() { + return UnresolvedDataType.INSTANCE; + } + + @Override + public String toString() { + return "_"; + } @Override public boolean equals(Object obj) { 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 49808d93d489..06d13557316b 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,7 +6,6 @@ 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; @@ -23,21 +22,17 @@ */ public abstract class Expression extends Selectable { - private final DataType requiredInputType; - - // Input and output types resolved during verification - private DataType inputType; - private DataType outputType; + private final DataType inputType; /** * Creates an expression * - * @param requiredInputType the type of the input this expression can work with. - * UnresolvedDataType.INSTANCE if it works with any type, - * and null if it does not consume any input. + * @param inputType the type of the input this expression can work with. + * UnresolvedDataType.INSTANCE if it works with any type, + * and null if it does not consume any input. */ - protected Expression(DataType requiredInputType) { - this.requiredInputType = requiredInputType; + protected Expression(DataType inputType) { + this.inputType = inputType; } /** @@ -49,85 +44,78 @@ protected Expression(DataType requiredInputType) { /** Sets the document type and field the statement this expression is part of will write to */ public void setStatementOutput(DocumentType documentType, Field field) {} - public final DataType requiredInputType() { return requiredInputType; } - - public DataType getInputType(VerificationContext context) { return inputType; } + public final FieldValue execute(FieldValue val) { + return execute(new ExecutionContext().setValue(val)); + } - /** - * Sets the input type of this and returns the resulting output type, or null if it cannot be - * uniquely determined. - * This default implementation returns the same type, which is appropriate for all statements - * that do not change the type. - * - * @param inputType the type to set as the input type of this, or null if it cannot be determined - * @param requiredType the type the input type must be assignable to - * @param context the context of this - * @throws IllegalArgumentException if inputType isn't assignable to requiredType - */ - protected final DataType setInputType(DataType inputType, DataType requiredType, VerificationContext context) { - // TODO: Activate type chedcking - // if ( ! (inputType instanceof TensorDataType)) - // throw new IllegalArgumentException(this + " requires a " + requiredType + ", but gets " + inputType); - this.inputType = inputType; - return inputType; + public final Document execute(AdapterFactory factory, Document doc) { + return execute(factory.newDocumentAdapter(doc)); } - /** - * Sets the input type of this and returns the resulting output type, or null if it cannot be - * uniquely determined. - * Subtypes may implement this by calling setInputType(inputType, requiredType, VerificationContext context). - */ - public DataType setInputType(DataType inputType, VerificationContext context) { - this.inputType = inputType; - return inputType; + public final Document execute(DocumentAdapter adapter) { + execute((FieldValueAdapter)adapter); + return adapter.getFullOutput(); } - /** - * Returns the output type this is must produce (since it is part of a statement expression), - * or null if this is not set or there is no output produced at the end of the statement. - */ - public DataType getOutputType(VerificationContext context) { return outputType; } + public static DocumentUpdate execute(Expression expression, AdapterFactory factory, DocumentUpdate update) { + DocumentUpdate result = null; + for (UpdateAdapter adapter : factory.newUpdateAdapterList(update)) { + DocumentUpdate output = adapter.getExpression(expression).execute(adapter); + if (output == null) { + // ignore + } else if (result != null) { + result.addAll(output); + } else { + result = output; + } + } + if (result != null) { + result.setCreateIfNonExistent(update.getCreateIfNonExistent()); + } + return result; + } - /** - * Sets the output type of this and returns the resulting input type, or null if it cannot be - * uniquely determined. - * This implementation returns the same type, which is appropriate for all statements - * that do not change the type. - * - * @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 - * @throws IllegalArgumentException if outputType isn't assignable to requiredType - */ - protected final DataType setOutputType(DataType outputType, DataType requiredType, VerificationContext context) { - // TODO: Activate type checking - // if (outputType != null && ! requiredType.isAssignableFrom(outputType)) - // throw new IllegalArgumentException(this + " produces a " + outputType + " but " + requiredType + " is required"); - this.outputType = outputType; - return outputType; + public final DocumentUpdate execute(UpdateAdapter adapter) { + execute((FieldValueAdapter)adapter); + return adapter.getOutput(); } - /** - * Sets the output type of this and returns the resulting input type, or null if it cannot be - * uniquely determined. - * Subtypes implement this by calling setOutputType(outputType, requiredType, VerificationContext context). - */ - public DataType setOutputType(DataType outputType, VerificationContext context) { - this.outputType = outputType; - return outputType; + public final FieldValue execute(FieldValueAdapter adapter) { + return execute(new ExecutionContext(adapter)); } - public abstract DataType createdOutputType(); + public final FieldValue execute(ExecutionContext context) { + DataType inputType = requiredInputType(); + if (inputType != null) { + FieldValue input = context.getValue(); + if (input == null) { + return null; + } + if (!inputType.isValueCompatible(input)) { + throw new IllegalArgumentException("Expression '" + this + "' expected " + inputType.getName() + + " input, got " + input.getDataType().getName()); + } + } + doExecute(context); + DataType outputType = createdOutputType(); + if (outputType != null) { + FieldValue output = context.getValue(); + if (output != null && !outputType.isValueCompatible(output)) { + throw new IllegalStateException("Expression '" + this + "' expected " + outputType.getName() + + " output, got " + output.getDataType().getName()); + } + } + return context.getValue(); + } - /** Implementations that don't change the type should implement this to do verification. */ - protected void doVerify(VerificationContext context) {} + protected abstract void doExecute(ExecutionContext context); public final DataType verify() { return verify(new VerificationContext()); } public final DataType verify(DataType val) { - return verify(new VerificationContext().setCurrentType(val)); + return verify(new VerificationContext().setValueType(val)); } public final Document verify(Document doc) { @@ -172,23 +160,23 @@ public final DataType verify(FieldTypeAdapter adapter) { } public final DataType verify(VerificationContext context) { - if (requiredInputType != null) { - DataType input = context.getCurrentType(); + if (inputType != null) { + DataType input = context.getValueType(); if (input == null) { - throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, but no input is specified"); + throw new VerificationException(this, "Expected " + inputType.getName() + " input, but no input is specified"); } if (input.getPrimitiveType() == UnresolvedDataType.INSTANCE) { throw new VerificationException(this, "Failed to resolve input type"); } - if (!requiredInputType.isAssignableFrom(input)) { - throw new VerificationException(this, "Expected " + requiredInputType.getName() + " input, got " + + if (!inputType.isAssignableFrom(input)) { + throw new VerificationException(this, "Expected " + inputType.getName() + " input, got " + input.getName()); } } doVerify(context); DataType outputType = createdOutputType(); if (outputType != null) { - DataType output = context.getCurrentType(); + DataType output = context.getValueType(); if (output == null) { throw new VerificationException(this, "Expected " + outputType.getName() + " output, but no output is specified"); } @@ -199,73 +187,14 @@ public final DataType verify(VerificationContext context) { throw new VerificationException(this, "Expected " + outputType.getName() + " output, got " + output.getName()); } } - return context.getCurrentType(); - } - - public final FieldValue execute(FieldValue val) { - return execute(new ExecutionContext().setCurrentValue(val)); + return context.getValueType(); } - public final Document execute(AdapterFactory factory, Document doc) { - return execute(factory.newDocumentAdapter(doc)); - } + protected abstract void doVerify(VerificationContext context); - public final Document execute(DocumentAdapter adapter) { - execute((FieldValueAdapter)adapter); - return adapter.getFullOutput(); - } + public final DataType requiredInputType() { return inputType; } - public static DocumentUpdate execute(Expression expression, AdapterFactory factory, DocumentUpdate update) { - DocumentUpdate result = null; - for (UpdateAdapter adapter : factory.newUpdateAdapterList(update)) { - DocumentUpdate output = adapter.getExpression(expression).execute(adapter); - if (output == null) { - // ignore - } else if (result != null) { - result.addAll(output); - } else { - result = output; - } - } - if (result != null) { - result.setCreateIfNonExistent(update.getCreateIfNonExistent()); - } - return result; - } - - public final DocumentUpdate execute(UpdateAdapter adapter) { - execute((FieldValueAdapter)adapter); - return adapter.getOutput(); - } - - public final FieldValue execute(FieldValueAdapter adapter) { - return execute(new ExecutionContext(adapter)); - } - - public final FieldValue execute(ExecutionContext context) { - DataType inputType = requiredInputType(); - if (inputType != null) { - FieldValue input = context.getCurrentValue(); - if (input == null) return null; - - if (!inputType.isValueCompatible(input)) { - throw new IllegalArgumentException("Expression '" + this + "' expected " + inputType.getName() + - " input, got " + input.getDataType().getName()); - } - } - doExecute(context); - DataType outputType = createdOutputType(); - if (outputType != null) { - FieldValue output = context.getCurrentValue(); - if (output != null && !outputType.isValueCompatible(output)) { - throw new IllegalStateException("Expression '" + this + "' expected " + outputType.getName() + - " output, got " + output.getDataType().getName()); - } - } - return context.getCurrentValue(); - } - - protected abstract void doExecute(ExecutionContext context); + public abstract DataType createdOutputType(); /** Creates an expression with simple lingustics for testing */ public static Expression fromString(String expression) throws ParseException { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java index a31e09e59e1e..ef9e6f41a6db 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ExpressionList.java @@ -8,9 +8,9 @@ import com.yahoo.vespa.objects.ObjectOperation; import com.yahoo.vespa.objects.ObjectPredicate; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -19,7 +19,7 @@ */ public abstract class ExpressionList extends CompositeExpression implements Iterable { - private final List expressions = new ArrayList(); + private final List expressions = new LinkedList(); protected ExpressionList(Iterable expressions, DataType inputType) { super(inputType); @@ -28,8 +28,6 @@ protected ExpressionList(Iterable expressions, DataType inputType) } } - public List expressions() { return expressions; } - protected List convertChildList(ExpressionConverter converter) { return asList().stream().map(converter::convert).filter(Objects::nonNull).toList(); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldTypeAdapter.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldTypeAdapter.java index 6d1a72b33cce..9633c8dcfb93 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldTypeAdapter.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldTypeAdapter.java @@ -8,8 +8,8 @@ */ public interface FieldTypeAdapter { - DataType getInputType(Expression expression, String fieldName); + DataType getInputType(Expression exp, String fieldName); - void tryOutputType(Expression expression, String fieldName, DataType valueType); + void tryOutputType(Expression exp, String fieldName, DataType valueType); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldValueAdapter.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldValueAdapter.java index 685d7b12c823..91622c4b85a4 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldValueAdapter.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/FieldValueAdapter.java @@ -12,7 +12,7 @@ public interface FieldValueAdapter extends FieldTypeAdapter { FieldValue getInputValue(String fieldName); FieldValue getInputValue(FieldPath fieldPath); - FieldValueAdapter setOutputValue(Expression expression, String fieldName, FieldValue fieldValue); + FieldValueAdapter setOutputValue(Expression exp, String fieldName, FieldValue fieldValue); /** Returns true if this has values for all possibly existing inputs, or represents a partial set of values. */ boolean isComplete(); 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 6b44e4ef3cc3..557c91d4e533 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 @@ -17,42 +17,37 @@ import java.util.Map; /** - * Deprecated. - * * @author Simon Thoresen Hult */ -// TODO: Remove on Vespa 9 public final class FlattenExpression extends Expression { public FlattenExpression() { super(DataType.STRING); } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); - } - @Override protected void doExecute(ExecutionContext context) { - StringFieldValue input = (StringFieldValue) context.getCurrentValue(); + StringFieldValue input = (StringFieldValue) context.getValue(); SpanTree tree = input.getSpanTree(SpanTrees.LINGUISTICS); Map> map = new HashMap<>(); for (Annotation anno : tree) { SpanNode span = anno.getSpanNode(); - if (span == null) continue; - if (anno.getType() != AnnotationTypes.TERM) continue; - + if (span == null) { + continue; + } + if (anno.getType() != AnnotationTypes.TERM) { + continue; + } FieldValue val = anno.getFieldValue(); - String s; + String str; if (val instanceof StringFieldValue) { - s = ((StringFieldValue)val).getString(); + str = ((StringFieldValue)val).getString(); } else { - s = input.getString().substring(span.getFrom(), span.getTo()); + str = input.getString().substring(span.getFrom(), span.getTo()); } Integer pos = span.getTo(); List entry = map.computeIfAbsent(pos, k -> new LinkedList<>()); - entry.add(s); + entry.add(str); } String inputVal = String.valueOf(input); StringBuilder output = new StringBuilder(); @@ -66,14 +61,23 @@ protected void doExecute(ExecutionContext context) { output.append(inputVal.charAt(i)); } } - context.setCurrentValue(new StringFieldValue(output.toString())); + context.setValue(new StringFieldValue(output.toString())); } @Override - public DataType createdOutputType() { return DataType.STRING; } + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); + } + + @Override + public DataType createdOutputType() { + return DataType.STRING; + } @Override - public String toString() { return "flatten"; } + public String toString() { + return "flatten"; + } @Override public boolean equals(Object obj) { 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 32b8c3314ef9..256ae68ba656 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 @@ -18,69 +18,75 @@ */ public final class ForEachExpression extends CompositeExpression { - private final Expression expression; + private final Expression exp; - public ForEachExpression(Expression expression) { + public ForEachExpression(Expression exp) { super(UnresolvedDataType.INSTANCE); - this.expression = Objects.requireNonNull(expression); + this.exp = Objects.requireNonNull(exp); } - public Expression getInnerExpression() { return expression; } + public Expression getInnerExpression() { + return exp; + } @Override public ForEachExpression convertChildren(ExpressionConverter converter) { - Expression converted = converter.convert(expression); + Expression converted = converter.convert(exp); return converted != null ? new ForEachExpression(converted) : null; } @Override public void setStatementOutput(DocumentType documentType, Field field) { - expression.setStatementOutput(documentType, field); - } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - 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); + exp.setStatementOutput(documentType, field); } @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - 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); + protected void doExecute(final ExecutionContext context) { + FieldValue input = context.getValue(); + if (input instanceof Array || input instanceof WeightedSet) { + FieldValue next = new MyConverter(context, exp).convert(input); + if (next == null) { + VerificationContext vctx = new VerificationContext(context); + context.fillVariableTypes(vctx); + vctx.setValueType(input.getDataType()).execute(this); + next = vctx.getValueType().createFieldValue(); + } + context.setValue(next); + } else if (input instanceof Struct) { + context.setValue(new MyConverter(context, exp).convert(input)); + } else { + throw new IllegalArgumentException("Expected Array, Struct or WeightedSet input, got " + + input.getDataType().getName()); + } } @Override protected void doVerify(VerificationContext context) { - DataType valueType = context.getCurrentType(); + DataType valueType = context.getValueType(); if (valueType instanceof ArrayDataType || valueType instanceof WeightedSetDataType) { // Set type for block evaluation - context.setCurrentType(((CollectionDataType)valueType).getNestedType()); + context.setValueType(((CollectionDataType)valueType).getNestedType()); - // Evaluate block, which sets valueType to the output of the block - context.verify(expression); + // Evaluate block, which sets value>Type to the output of the block + context.execute(exp); // Value type outside block becomes the collection type having the block output type as argument if (valueType instanceof ArrayDataType) { - context.setCurrentType(DataType.getArray(context.getCurrentType())); + context.setValueType(DataType.getArray(context.getValueType())); } else { WeightedSetDataType wset = (WeightedSetDataType)valueType; - context.setCurrentType(DataType.getWeightedSet(context.getCurrentType(), wset.createIfNonExistent(), wset.removeIfZero())); + context.setValueType(DataType.getWeightedSet(context.getValueType(), wset.createIfNonExistent(), wset.removeIfZero())); } } else if (valueType instanceof StructDataType) { for (Field field : ((StructDataType)valueType).getFields()) { DataType fieldType = field.getDataType(); - DataType structValueType = context.setCurrentType(fieldType).verify(expression).getCurrentType(); + DataType structValueType = context.setValueType(fieldType).execute(exp).getValueType(); if (!fieldType.isAssignableFrom(structValueType)) throw new VerificationException(this, "Expected " + fieldType.getName() + " output, got " + structValueType.getName()); } - context.setCurrentType(valueType); + context.setValueType(valueType); } else { throw new VerificationException(this, "Expected Array, Struct or WeightedSet input, got " + @@ -88,29 +94,9 @@ else if (valueType instanceof StructDataType) { } } - @Override - protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); - if (input instanceof Array || input instanceof WeightedSet) { - FieldValue next = new MyConverter(context, expression).convert(input); - if (next == null) { - VerificationContext verificationContext = new VerificationContext(context.getFieldValue()); - context.fillVariableTypes(verificationContext); - verificationContext.setCurrentType(input.getDataType()).verify(this); - next = verificationContext.getCurrentType().createFieldValue(); - } - context.setCurrentValue(next); - } else if (input instanceof Struct) { - context.setCurrentValue(new MyConverter(context, expression).convert(input)); - } else { - throw new IllegalArgumentException("Expected Array, Struct or WeightedSet input, got " + - input.getDataType().getName()); - } - } - @Override public DataType createdOutputType() { - if (expression.createdOutputType() == null) { + if (exp.createdOutputType() == null) { return null; } return UnresolvedDataType.INSTANCE; @@ -118,19 +104,19 @@ public DataType createdOutputType() { @Override public String toString() { - return "for_each { " + expression + " }"; + return "for_each { " + exp + " }"; } @Override public boolean equals(Object obj) { if (!(obj instanceof ForEachExpression rhs)) return false; - if (!expression.equals(rhs.expression)) return false; + if (!exp.equals(rhs.exp)) return false; return true; } @Override public int hashCode() { - return getClass().hashCode() + expression.hashCode(); + return getClass().hashCode() + exp.hashCode(); } private static final class MyConverter extends FieldValueConverter { @@ -151,14 +137,14 @@ protected boolean shouldConvert(FieldValue value) { @Override protected FieldValue doConvert(FieldValue value) { - context.setCurrentValue(value).execute(expression); - return context.getCurrentValue(); + context.setValue(value).execute(expression); + return context.getValue(); } } @Override public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) { - select(expression, predicate, operation); + select(exp, predicate, operation); } } 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 4ebbc8bdad25..bb9a1a034960 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 @@ -19,23 +19,27 @@ public GetFieldExpression(String fieldName) { this.fieldName = fieldName; } - public String getFieldName() { return fieldName; } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return context.getFieldType(fieldName, this); + public String getFieldName() { + return fieldName; } @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(context.getFieldType(fieldName, this), outputType, context); - return AnyDataType.instance; + protected void doExecute(ExecutionContext context) { + FieldValue input = context.getValue(); + if (!(input instanceof StructuredFieldValue struct)) { + throw new IllegalArgumentException("Expected structured input, got " + input.getDataType().getName()); + } + Field field = struct.getField(fieldName); + if (field == null) { + throw new IllegalArgumentException("Field '" + fieldName + "' not found in struct type '" + + struct.getDataType().getName() + "'"); + } + context.setValue(struct.getFieldValue(field)); } @Override protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); + DataType input = context.getValueType(); if (!(input instanceof StructuredDataType)) { throw new VerificationException(this, "Expected structured input, got " + input.getName()); } @@ -44,20 +48,7 @@ protected void doVerify(VerificationContext context) { throw new VerificationException(this, "Field '" + fieldName + "' not found in struct type '" + input.getName() + "'"); } - context.setCurrentType(field.getDataType()); - } - - @Override - protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); - if (!(input instanceof StructuredFieldValue struct)) - throw new IllegalArgumentException("Expected structured input, got " + input.getDataType().getName()); - - Field field = struct.getField(fieldName); - if (field == null) - throw new IllegalArgumentException("Field '" + fieldName + "' not found in struct type '" + - struct.getDataType().getName() + "'"); - context.setCurrentValue(struct.getFieldValue(field)); + context.setValueType(field.getDataType()); } @Override 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 1f5e1c4f5b9d..8b2604bfec5c 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 @@ -8,39 +8,29 @@ */ public final class GetVarExpression extends Expression { - private final String variableName; + private final String varName; - public GetVarExpression(String variableName) { + public GetVarExpression(String varName) { super(null); - this.variableName = variableName; + this.varName = varName; } - public String getVariableName() { return variableName; } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return context.getVariable(variableName); + public String getVariableName() { + return varName; } @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(context.getVariable(variableName), outputType, context); - return AnyDataType.instance; + protected void doExecute(ExecutionContext context) { + context.setValue(context.getVariable(varName)); } @Override protected void doVerify(VerificationContext context) { - DataType input = context.getVariable(variableName); + DataType input = context.getVariable(varName); if (input == null) { - throw new VerificationException(this, "Variable '" + variableName + "' not found"); + throw new VerificationException(this, "Variable '" + varName + "' not found"); } - context.setCurrentType(input); - } - - @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(context.getVariable(variableName)); + context.setValueType(input); } @Override @@ -50,19 +40,19 @@ public DataType createdOutputType() { @Override public String toString() { - return "get_var " + variableName; + return "get_var " + varName; } @Override public boolean equals(Object obj) { if (!(obj instanceof GetVarExpression rhs)) return false; - if (!variableName.equals(rhs.variableName)) return false; + if (!varName.equals(rhs.varName)) return false; return true; } @Override public int hashCode() { - return getClass().hashCode() + variableName.hashCode(); + return getClass().hashCode() + varName.hashCode(); } } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java index 58037e3927d5..92fc852a61fe 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/GuardExpression.java @@ -15,78 +15,68 @@ */ public final class GuardExpression extends CompositeExpression { - private final Expression expression; + private final Expression exp; private final boolean shouldExecute; - public GuardExpression(Expression expression) { - super(expression.requiredInputType()); - this.expression = expression; - shouldExecute = shouldExecute(expression); + public GuardExpression(Expression exp) { + super(exp.requiredInputType()); + this.exp = exp; + shouldExecute = shouldExecute(exp); } - public Expression getInnerExpression() { return expression; } - - @Override - public GuardExpression convertChildren(ExpressionConverter converter) { - return new GuardExpression(converter.convert(expression)); - } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - return expression.setInputType(inputType, context); + public Expression getInnerExpression() { + return exp; } @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - return expression.setOutputType(outputType, context); + public GuardExpression convertChildren(ExpressionConverter converter) { + return new GuardExpression(converter.convert(exp)); } @Override - protected void doVerify(VerificationContext context) { - expression.verify(context); + public void setStatementOutput(DocumentType documentType, Field field) { + exp.setStatementOutput(documentType, field); } @Override protected void doExecute(ExecutionContext context) { - if (!shouldExecute && context.getFieldValue() instanceof UpdateAdapter) { - context.setCurrentValue(null); + if (!shouldExecute && context.getAdapter() instanceof UpdateAdapter) { + context.setValue(null); } else { - expression.execute(context); + exp.execute(context); } } @Override - public void setStatementOutput(DocumentType documentType, Field field) { - expression.setStatementOutput(documentType, field); + protected void doVerify(VerificationContext context) { + exp.verify(context); } @Override public DataType createdOutputType() { - return expression.createdOutputType(); + return exp.createdOutputType(); } @Override public String toString() { - return "guard " + toScriptBlock(expression); + return "guard " + toScriptBlock(exp); } @Override public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) { - select(expression, predicate, operation); + select(exp, predicate, operation); } @Override public boolean equals(Object obj) { if (!(obj instanceof GuardExpression rhs)) return false; - if (!expression.equals(rhs.expression)) return false; + if (!exp.equals(rhs.exp)) return false; return true; } @Override public int hashCode() { - return getClass().hashCode() + expression.hashCode(); + return getClass().hashCode() + exp.hashCode(); } private static boolean shouldExecute(Expression exp) { 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 bdfcd6155803..eb3e316ba816 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 @@ -39,27 +39,13 @@ public void setStatementOutput(DocumentType documentType, Field field) { 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(); + StringFieldValue input = (StringFieldValue) context.getValue(); if (targetType.equals(DataType.INT)) - context.setCurrentValue(new IntegerFieldValue(hashToInt(input.getString()))); + context.setValue(new IntegerFieldValue(hashToInt(input.getString()))); else if (targetType.equals(DataType.LONG)) - context.setCurrentValue(new LongFieldValue(hashToLong(input.getString()))); + context.setValue(new LongFieldValue(hashToLong(input.getString()))); else throw new IllegalStateException(); // won't happen } @@ -72,6 +58,20 @@ private long hashToLong(String value) { return hasher.hashString(value, StandardCharsets.UTF_8).asLong(); } + @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.getInputType(this, outputField); + 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.setValueType(createdOutputType()); + } + private boolean canStoreHash(DataType type) { if (type.equals(DataType.INT)) return true; if (type.equals(DataType.LONG)) return true; 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 a7d314ff45a4..a344a1d867ed 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,16 +17,11 @@ public HexDecodeExpression() { super(DataType.STRING); } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); - } - @Override protected void doExecute(ExecutionContext context) { - String input = String.valueOf(context.getCurrentValue()); + String input = String.valueOf(context.getValue()); if (input.isEmpty()) { - context.setCurrentValue(new LongFieldValue(Long.MIN_VALUE)); + context.setValue(new LongFieldValue(Long.MIN_VALUE)); return; } BigInteger output; @@ -41,14 +36,23 @@ protected void doExecute(ExecutionContext context) { if (output.compareTo(BigInteger.ZERO) > 0 && output.bitLength() == 64) { output = output.subtract(ULONG_MAX); // flip to negative } - context.setCurrentValue(new LongFieldValue(output.longValue())); + context.setValue(new LongFieldValue(output.longValue())); + } + + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.LONG; } + public DataType createdOutputType() { + return DataType.LONG; + } @Override - public String toString() { return "hexdecode"; } + public String toString() { + return "hexdecode"; + } @Override public boolean equals(Object obj) { 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 c32b08e12484..249ddf03fc22 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 @@ -15,25 +15,31 @@ public HexEncodeExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + long input = ((LongFieldValue) context.getValue()).getLong(); + context.setValue(new StringFieldValue(Long.toHexString(input))); } @Override - protected void doExecute(ExecutionContext context) { - long input = ((LongFieldValue) context.getCurrentValue()).getLong(); - context.setCurrentValue(new StringFieldValue(Long.toHexString(input))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.STRING; } + public DataType createdOutputType() { + return DataType.STRING; + } @Override - public String toString() { return "hexencode"; } + public String toString() { + return "hexencode"; + } @Override public boolean equals(Object obj) { - if (!(obj instanceof HexEncodeExpression)) return false; + if (!(obj instanceof HexEncodeExpression)) { + return false; + } return true; } 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 550355c9d242..17c4e7a49846 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 @@ -15,20 +15,24 @@ public HostNameExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new StringFieldValue(normalizeHostName(getDefaults().vespaHostname()))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new StringFieldValue(normalizeHostName(getDefaults().vespaHostname()))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.STRING; } + public DataType createdOutputType() { + return DataType.STRING; + } @Override - public String toString() { return "hostname"; } + public String toString() { + return "hostname"; + } @Override public boolean equals(Object obj) { 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 eeaee3ff1355..7362cbcbdf72 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 @@ -84,32 +84,20 @@ public void setStatementOutput(DocumentType documentType, Field field) { public Expression getIfFalseExpression() { return ifFalse; } - @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); - context.setCurrentType(input).verify(left); - context.setCurrentType(input).verify(right); - var trueValue = context.setCurrentType(input).verify(ifTrue); - var falseValue = context.setCurrentType(input).verify(ifFalse); - var valueType = trueValue.getCurrentType().isAssignableFrom(falseValue.getCurrentType()) ? - trueValue.getCurrentType() : falseValue.getCurrentType(); - context.setCurrentType(valueType); - } - @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); - FieldValue leftValue = context.setCurrentValue(input).execute(left).getCurrentValue(); + FieldValue input = context.getValue(); + FieldValue leftValue = context.setValue(input).execute(left).getValue(); if (leftValue == null) { - context.setCurrentValue(null); + context.setValue(null); return; } - FieldValue rightValue = context.setCurrentValue(input).execute(right).getCurrentValue(); + FieldValue rightValue = context.setValue(input).execute(right).getValue(); if (rightValue == null) { - context.setCurrentValue(null); + context.setValue(null); return; } - context.setCurrentValue(input); + context.setValue(input); if (isTrue(leftValue, comparator, rightValue)) { ifTrue.execute(context); } else if (ifFalse != null) { @@ -117,6 +105,18 @@ protected void doExecute(ExecutionContext context) { } } + @Override + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); + context.setValueType(input).execute(left); + context.setValueType(input).execute(right); + var trueValue = context.setValueType(input).execute(ifTrue); + var falseValue = context.setValueType(input).execute(ifFalse); + var valueType = trueValue.getValueType().isAssignableFrom(falseValue.getValueType()) ? + trueValue.getValueType() : falseValue.getValueType(); + context.setValueType(valueType); + } + @Override public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) { select(left, predicate, operation); 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 48cf6ac237c3..d49ca4ae6798 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 @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * @author Simon Thoresen Hult @@ -25,30 +26,29 @@ public InputExpression(String fieldName) { this.fieldName = fieldName; } - public String getFieldName() { return fieldName; } - - @Override - protected void doVerify(VerificationContext context) { - DataType val = context.getFieldType(fieldName, this); - if (val == null) - throw new VerificationException(this, "Field '" + fieldName + "' not found"); - context.setCurrentType(val); + public String getFieldName() { + return fieldName; } @Override protected void doExecute(ExecutionContext context) { if (fieldPath != null) - context.setCurrentValue(context.getFieldValue(fieldPath)); + context.setValue(context.getInputValue(fieldPath)); else - context.setCurrentValue(context.getFieldValue(fieldName)); + context.setValue(context.getInputValue(fieldName)); } @Override - public DataType createdOutputType() { return UnresolvedDataType.INSTANCE; } + protected void doVerify(VerificationContext context) { + DataType val = context.getInputType(this, fieldName); + if (val == null) + throw new VerificationException(this, "Field '" + fieldName + "' not found"); + context.setValueType(val); + } @Override - public DataType getOutputType(VerificationContext context) { - return context.getFieldType(fieldName, this); + public DataType createdOutputType() { + return UnresolvedDataType.INSTANCE; } @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 d4640086a311..07c8dbeaa6b6 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 @@ -22,23 +22,17 @@ public JoinExpression(String delimiter) { this.delimiter = delimiter; } - public String getDelimiter() { return delimiter; } - - @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); - if (!(input instanceof ArrayDataType)) { - throw new VerificationException(this, "Expected Array input, got " + input.getName()); - } - context.setCurrentType(createdOutputType()); + public String getDelimiter() { + return delimiter; } @SuppressWarnings({ "unchecked" }) @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); - if (!(input instanceof Array)) + FieldValue input = context.getValue(); + if (!(input instanceof Array)) { throw new IllegalArgumentException("Expected Array input, got " + input.getDataType().getName()); + } StringBuilder output = new StringBuilder(); for (Iterator it = ((Array)input).fieldValueIterator(); it.hasNext(); ) { output.append(it.next()); @@ -46,11 +40,22 @@ protected void doExecute(ExecutionContext context) { output.append(delimiter); } } - context.setCurrentValue(new StringFieldValue(output.toString())); + context.setValue(new StringFieldValue(output.toString())); } @Override - public DataType createdOutputType() { return DataType.STRING; } + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); + if (!(input instanceof ArrayDataType)) { + throw new VerificationException(this, "Expected Array input, got " + input.getName()); + } + context.setValueType(createdOutputType()); + } + + @Override + public DataType createdOutputType() { + return DataType.STRING; + } @Override public String toString() { 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 12fa802d59b1..f4288e035f14 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpression.java @@ -19,17 +19,19 @@ public LiteralBoolExpression(boolean value) { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new BoolFieldValue(value)); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new BoolFieldValue(value)); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.BOOL; } + public DataType createdOutputType() { + return DataType.BOOL; + } @Override public String toString() { 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 8cf304043bed..82accf6406d0 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 @@ -16,20 +16,24 @@ public LowerCaseExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new StringFieldValue(toLowerCase(String.valueOf(context.getValue())))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new StringFieldValue(toLowerCase(String.valueOf(context.getCurrentValue())))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.STRING; } + public DataType createdOutputType() { + return DataType.STRING; + } @Override - public String toString() { return "lowercase"; } + public String toString() { + return "lowercase"; + } @Override public boolean equals(Object obj) { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolver.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolver.java index e10e4f13294e..ad148f89d84c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolver.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolver.java @@ -51,7 +51,6 @@ private static class Item { this.op = Objects.requireNonNull(op); this.exp = exp; } - } } 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 8954951ce462..fdfadf654007 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 @@ -39,24 +39,23 @@ public NGramExpression(Linguistics linguistics, int gramSize) { this.gramSize = gramSize; } - public Linguistics getLinguistics() { return linguistics; } - - public int getGramSize() { return gramSize; } + public Linguistics getLinguistics() { + return linguistics; + } - @Override - protected void doVerify(VerificationContext context) { - // empty + public int getGramSize() { + return gramSize; } @Override protected void doExecute(ExecutionContext context) { - StringFieldValue input = (StringFieldValue) context.getCurrentValue(); + StringFieldValue input = (StringFieldValue) context.getValue(); if (input.getSpanTree(SpanTrees.LINGUISTICS) != null) { // This expression is already executed for this input instance return; } StringFieldValue output = input.clone(); - context.setCurrentValue(output); + context.setValue(output); SpanList spanList = output.setSpanTree(new SpanTree(SpanTrees.LINGUISTICS)).spanList(); int lastPosition = 0; @@ -87,6 +86,11 @@ private Span typedSpan(int from, int length, TokenType tokenType, SpanList spanL return (Span)spanList.span(from, length).annotate(AnnotationTypes.TOKEN_TYPE, tokenType.getValue()); } + @Override + protected void doVerify(VerificationContext context) { + // empty + } + @Override public DataType createdOutputType() { return null; 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 d269fa1fd4a9..0e6b77624cbb 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 @@ -22,24 +22,33 @@ public NormalizeExpression(Linguistics linguistics) { this.linguistics = linguistics; } - public Linguistics getLinguistics() { return linguistics; } + public Linguistics getLinguistics() { + return linguistics; + } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + private static String escape(String str) { + StringBuilder buf = new StringBuilder(); + for (char c : str.toCharArray()) { + if (c >= ' ') { + buf.append(c); + } else { + buf.append(String.format("U+%04X", (int)c)); + } + } + return buf.toString(); } @Override protected void doExecute(ExecutionContext context) { Transformer transformer = linguistics.getTransformer(); - var orig = String.valueOf(context.getCurrentValue()); + var orig = String.valueOf(context.getValue()); if (orig.isEmpty()) { return; // must be a no-op for all linguistics/language combinations } var lang = context.resolveLanguage(linguistics); var transformed = transformer.accentDrop(orig, lang); try { - context.setCurrentValue(new StringFieldValue(transformed)); + context.setValue(new StringFieldValue(transformed)); return; } catch (IllegalArgumentException ex) { String msg = ("bad normalize, \n" + @@ -48,20 +57,13 @@ protected void doExecute(ExecutionContext context) { "transformed: >>> " + escape(transformed) + " <<<"); logger.log(Level.SEVERE, msg); } - context.setCurrentValue(new StringFieldValue(transformer.accentDrop(String.valueOf(context.getCurrentValue()), - context.resolveLanguage(linguistics)))); + context.setValue(new StringFieldValue(transformer.accentDrop(String.valueOf(context.getValue()), + context.resolveLanguage(linguistics)))); } - private static String escape(String str) { - StringBuilder buf = new StringBuilder(); - for (char c : str.toCharArray()) { - if (c >= ' ') { - buf.append(c); - } else { - buf.append(String.format("U+%04X", (int)c)); - } - } - return buf.toString(); + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override 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 b00b38454628..039f123a6e7c 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/NowExpression.java @@ -20,23 +20,29 @@ public NowExpression(Timer timer) { this.timer = timer; } - public Timer getTimer() { return timer; } + public Timer getTimer() { + return timer; + } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new LongFieldValue(timer.currentTimeSeconds())); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new LongFieldValue(timer.currentTimeSeconds())); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.LONG; } + public DataType createdOutputType() { + return DataType.LONG; + } @Override - public String toString() { return "now"; } + public String toString() { + return "now"; + } @Override public boolean equals(Object obj) { @@ -64,7 +70,6 @@ private static class SystemTimer implements Timer { public long currentTimeSeconds() { return System.currentTimeMillis() / 1000; } - } } 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 56531b3aae94..91d88d929907 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,17 +29,9 @@ public OptimizePredicateExpression() { this.optimizer = optimizer; } - @Override - protected void doVerify(VerificationContext context) { - checkVariable(context, "arity", DataType.INT, true); - checkVariable(context, "lower_bound", DataType.LONG, false); - checkVariable(context, "upper_bound", DataType.LONG, false); - context.setCurrentType(DataType.PREDICATE); - } - @Override protected void doExecute(ExecutionContext context) { - PredicateFieldValue predicate = ((PredicateFieldValue) context.getCurrentValue()).clone(); + PredicateFieldValue predicate = ((PredicateFieldValue) context.getValue()).clone(); IntegerFieldValue arity = (IntegerFieldValue) context.getVariable("arity"); LongFieldValue lower_bound = (LongFieldValue) context.getVariable("lower_bound"); LongFieldValue upper_bound = (LongFieldValue) context.getVariable("upper_bound"); @@ -47,24 +39,37 @@ protected void doExecute(ExecutionContext context) { Long upper = upper_bound != null? upper_bound.getLong() : null; PredicateOptions options = new PredicateOptions(arity.getInteger(), lower, upper); predicate.setPredicate(optimizer.process(predicate.getPredicate(), options)); - context.setCurrentValue(predicate); + context.setValue(predicate); + } + + @Override + protected void doVerify(VerificationContext context) { + checkVariable(context, "arity", DataType.INT, true); + checkVariable(context, "lower_bound", DataType.LONG, false); + checkVariable(context, "upper_bound", DataType.LONG, false); + context.setValueType(DataType.PREDICATE); } private void checkVariable(VerificationContext ctx, String var, DataType type, boolean required) { DataType input = ctx.getVariable(var); if (input == null) { - if (required) + if (required) { throw new VerificationException(this, "Variable '" + var + "' must be set"); + } } else if (input != type) { throw new VerificationException(this, "Variable '" + var + "' must have type " + type.getName()); } } @Override - public DataType createdOutputType() { return null; } + public DataType createdOutputType() { + return null; + } @Override - public String toString() { return "optimize_predicate"; } + public String toString() { + return "optimize_predicate"; + } @Override public int hashCode() { 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 a050eee7413f..4320d25a0823 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 @@ -22,24 +22,23 @@ public OutputExpression(String image, String fieldName) { this.fieldName = fieldName; } - public String getFieldName() { return fieldName; } - - @Override - protected void doVerify(VerificationContext context) { - context.tryOutputType(fieldName, context.getCurrentType(), this); + public String getFieldName() { + return fieldName; } @Override protected void doExecute(ExecutionContext context) { - context.setFieldValue(fieldName, context.getCurrentValue(), this); + context.setOutputValue(this, fieldName, context.getValue()); } @Override - public DataType createdOutputType() { return null; } + protected void doVerify(VerificationContext context) { + context.tryOutputType(this, fieldName, context.getValueType()); + } @Override - public DataType getInputType(VerificationContext context) { - return context.getFieldType(fieldName, this); + public DataType createdOutputType() { + return null; } @Override 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 deleted file mode 100644 index 078639a8071b..000000000000 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/PackBitsExpression.java +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.indexinglanguage.expressions; - -import com.yahoo.document.DataType; -import com.yahoo.document.TensorDataType; -import com.yahoo.document.datatypes.TensorFieldValue; -import com.yahoo.tensor.Tensor; -import com.yahoo.tensor.TensorType; -import com.yahoo.tensor.Tensors; - -import java.util.Optional; - -/** - * Converts any tensor containing only ones and zeroes into one where each consecutive 8 values in the - * dense dimension are packed into a single byte. As a consequence the output type of this is a tensor - * where the dense dimension is 1/8th as large. - * - * @author bratseth - */ -public class PackBitsExpression extends Expression { - - private TensorType outputTensorType; - - /** Creates a pack_bits expression. */ - public PackBitsExpression() { - super(TensorDataType.any()); - } - - @Override - public DataType setInputType(DataType inputType, VerificationContext context) { - super.setInputType(inputType, context); - if ( ! validType(inputType)) - throw new IllegalArgumentException("pack_bits requires a tensor with one dense dimension, " + - "but got " + inputType); - outputTensorType = outputType(((TensorDataType)inputType).getTensorType()); - return new TensorDataType(outputTensorType); - } - - @Override - public DataType setOutputType(DataType outputType, VerificationContext context) { - super.setOutputType(outputType, context); - if ( ! validType(outputType)) - throw new IllegalArgumentException("pack_bits produces a tensor with one dense dimension, " + - "but need " + outputType); - outputTensorType = ((TensorDataType)outputType).getTensorType(); - return new TensorDataType(inputType(outputTensorType)); - } - - /** Returns whether this is a valid input or output from this. */ - private boolean validType(DataType type) { - if ( ! (type instanceof TensorDataType tensorType)) return false; - if ( tensorType.getTensorType().indexedSubtype().dimensions().size() != 1) return false; - return true; - } - - @Override - protected void doVerify(VerificationContext context) {} - - @Override - protected void doExecute(ExecutionContext context) { - Optional tensor = ((TensorFieldValue)context.getCurrentValue()).getTensor(); - if (tensor.isEmpty()) return; - Tensor packed = Tensors.packBits(tensor.get()); - context.setCurrentValue(new TensorFieldValue(packed)); - } - - @Override - public DataType createdOutputType() { return new TensorDataType(outputTensorType); } - - @Override - public String toString() { return "pack_bits"; } - - @Override - public int hashCode() { return toString().hashCode(); } - - @Override - public boolean equals(Object o) { return o instanceof PackBitsExpression; } - - /** Returns the type this requires when producing the given output type. */ - private TensorType inputType(TensorType givenType) { - var builder = new TensorType.Builder(TensorType.Value.INT8); // Any larger value type is also permissible - for (var d : givenType.dimensions()) - builder.dimension(d.size().isPresent() ? d.withSize(d.size().get() * 8) : d); - return builder.build(); - } - - /** Returns the type this produces from the given input type. */ - private TensorType outputType(TensorType givenType) { - var builder = new TensorType.Builder(TensorType.Value.INT8); - for (var d : givenType.dimensions()) - builder.dimension(d.size().isPresent() ? d.withSize((int) Math.ceil(d.size().get() / 8.0)) : d); - return builder.build(); - } - -} 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 ade7cc72d149..2f8917100a67 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 @@ -20,7 +20,9 @@ public ParenthesisExpression(Expression innerExp) { this.innerExp = innerExp; } - public Expression getInnerExpression() { return innerExp; } + public Expression getInnerExpression() { + return innerExp; + } @Override public ParenthesisExpression convertChildren(ExpressionConverter converter) { @@ -33,13 +35,13 @@ public void setStatementOutput(DocumentType documentType, Field field) { } @Override - protected void doVerify(VerificationContext context) { - innerExp.verify(context); + protected void doExecute(ExecutionContext context) { + innerExp.execute(context); } @Override - protected void doExecute(ExecutionContext context) { - innerExp.execute(context); + protected void doVerify(VerificationContext context) { + innerExp.verify(context); } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java index 31a44172a180..2972d3ee3ccd 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/RandomExpression.java @@ -23,22 +23,26 @@ public RandomExpression(Integer max) { this.max = max; } - public Integer getMaxValue() { return max; } - - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + public Integer getMaxValue() { + return max; } @Override protected void doExecute(ExecutionContext context) { int max; - max = Objects.requireNonNullElseGet(this.max, () -> Integer.parseInt(String.valueOf(context.getCurrentValue()))); - context.setCurrentValue(new IntegerFieldValue(ThreadLocalRandom.current().nextInt(max))); + max = Objects.requireNonNullElseGet(this.max, () -> Integer.parseInt(String.valueOf(context.getValue()))); + context.setValue(new IntegerFieldValue(ThreadLocalRandom.current().nextInt(max))); } @Override - public DataType createdOutputType() { return DataType.INT; } + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); + } + + @Override + public DataType createdOutputType() { + return DataType.INT; + } @Override public String toString() { @@ -56,5 +60,4 @@ public boolean equals(Object obj) { public int hashCode() { return getClass().hashCode(); } - } 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 bf241cf61784..810ff261f2d3 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,33 +43,33 @@ public ScriptExpression convertChildren(ExpressionConverter converter) { .toList()); } - @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); - for (Expression exp : this) - context.setCurrentType(input).verify(exp); - } - @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); + FieldValue input = context.getValue(); for (StatementExpression statement : this) { if (context.isComplete() || (statement.getInputFields().isEmpty() || containsAtLeastOneInputFrom(statement.getInputFields(), context))) { - context.setCurrentValue(input); + context.setValue(input); context.execute(statement); } } - context.setCurrentValue(input); + context.setValue(input); } private boolean containsAtLeastOneInputFrom(List inputFields, ExecutionContext context) { for (String inputField : inputFields) - if (context.getFieldValue(inputField) != null) + if (context.getInputValue(inputField) != null) return true; return false; } + @Override + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); + for (Expression exp : this) + context.setValueType(input).execute(exp); + } + private static DataType resolveInputType(Collection list) { DataType prev = null; for (Expression exp : list) { 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 d465d0aed66f..9c92dd452c32 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 @@ -10,6 +10,7 @@ import com.yahoo.vespa.objects.ObjectOperation; import com.yahoo.vespa.objects.ObjectPredicate; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -45,29 +46,29 @@ public void setStatementOutput(DocumentType documentType, Field field) { } @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); + protected void doExecute(ExecutionContext context) { + FieldValue input = context.getValue(); for (Pair entry : cases) { - DataType val = context.getFieldType(entry.getFirst(), this); - if (val == null) { - throw new VerificationException(this, "Field '" + entry.getFirst() + "' not found"); + FieldValue val = context.getInputValue(entry.getFirst()); + if (val != null) { + context.setValue(val).execute(entry.getSecond()); + break; } - context.setCurrentType(val).verify(entry.getSecond()); } - context.setCurrentType(input); + context.setValue(input); } @Override - protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); for (Pair entry : cases) { - FieldValue val = context.getFieldValue(entry.getFirst()); - if (val != null) { - context.setCurrentValue(val).execute(entry.getSecond()); - break; + DataType val = context.getInputType(this, entry.getFirst()); + if (val == null) { + throw new VerificationException(this, "Field '" + entry.getFirst() + "' not found"); } + context.setValueType(val).execute(entry.getSecond()); } - context.setCurrentValue(input); + context.setValueType(input); } @Override @@ -78,7 +79,9 @@ public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) } @Override - public DataType createdOutputType() { return null; } + public DataType createdOutputType() { + return null; + } public List> getCases() { return Collections.unmodifiableList(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 8dbbc0c974d6..da5338af6a6f 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 @@ -14,15 +14,14 @@ public final class SetLanguageExpression extends Expression { public SetLanguageExpression() { super(DataType.STRING); } - @Override - protected void doVerify(VerificationContext context) { - // empty + protected void doExecute(ExecutionContext context) { + context.setLanguage(Language.fromLanguageTag(String.valueOf(context.getValue()))); } @Override - protected void doExecute(ExecutionContext context) { - context.setLanguage(Language.fromLanguageTag(String.valueOf(context.getCurrentValue()))); + protected void doVerify(VerificationContext context) { + // empty } @Override @@ -31,7 +30,9 @@ public DataType createdOutputType() { } @Override - public String toString() { return "set_language"; } + public String toString() { + return "set_language"; + } @Override public boolean equals(Object obj) { 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 b4c92fc695b1..4f30e0b066f0 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 @@ -15,11 +15,18 @@ public SetVarExpression(String varName) { this.varName = varName; } - public String getVariableName() { return varName; } + public String getVariableName() { + return varName; + } + + @Override + protected void doExecute(ExecutionContext context) { + context.setVariable(varName, context.getValue()); + } @Override protected void doVerify(VerificationContext context) { - DataType next = context.getCurrentType(); + DataType next = context.getValueType(); DataType prev = context.getVariable(varName); if (prev != null && !prev.equals(next)) { throw new VerificationException(this, "Attempting to assign conflicting types to variable '" + varName + @@ -29,13 +36,10 @@ protected void doVerify(VerificationContext context) { } @Override - protected void doExecute(ExecutionContext context) { - context.setVariable(varName, context.getCurrentValue()); + public DataType createdOutputType() { + return null; } - @Override - public DataType createdOutputType() { return null; } - @Override public String toString() { return "set_var " + varName; diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java index cc43506539a1..f7216fc1c975 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SleepExpression.java @@ -6,22 +6,17 @@ /** * Utility expression that will sleep the amount of time given in the numeric field. - * Non-numeric fields will be ignored. - * + * Non-numeric fields will be ignored * @author baldersheim */ public final class SleepExpression extends Expression { - public SleepExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - protected void doVerify(VerificationContext context) { } - @Override protected void doExecute(ExecutionContext context) { - FieldValue value = context.getCurrentValue(); + FieldValue value = context.getValue(); if (value instanceof NumericFieldValue num) { double napSecs = num.getNumber().doubleValue(); long nanos = (long)(napSecs*1_000_000_000.0); @@ -33,6 +28,7 @@ protected void doExecute(ExecutionContext context) { } } + @Override protected void doVerify(VerificationContext context) { } @Override public DataType createdOutputType() { return null; } @Override public String toString() { return "sleep"; } @Override public boolean equals(Object obj) { return obj instanceof SleepExpression; } 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 b59273fc5ae2..f3a2b7ab4aee 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 @@ -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.Array; import com.yahoo.document.datatypes.StringFieldValue; @@ -21,32 +20,13 @@ public SplitExpression(String splitString) { this.splitPattern = Pattern.compile(splitString); } - public Pattern getSplitPattern() { return splitPattern; } - - @Override - public DataType setInputType(DataType input, VerificationContext context) { - super.setInputType(input, context); - if (input != DataType.STRING) - throw new IllegalArgumentException("split requires a string input, but got " + input); - return new ArrayDataType(DataType.STRING); - } - - @Override - public DataType setOutputType(DataType output, VerificationContext context) { - super.setOutputType(output, context); - if ( ! (output instanceof ArrayDataType) && output.getNestedType() == DataType.STRING) - throw new IllegalArgumentException("split produces a string array, but needs " + output); - return DataType.STRING; - } - - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + public Pattern getSplitPattern() { + return splitPattern; } @Override protected void doExecute(ExecutionContext context) { - String input = String.valueOf(context.getCurrentValue()); + String input = String.valueOf(context.getValue()); Array output = new Array<>(DataType.getArray(DataType.STRING)); if (!input.isEmpty()) { String[] splits = splitPattern.split(input); @@ -54,7 +34,12 @@ protected void doExecute(ExecutionContext context) { output.add(new StringFieldValue(split)); } } - context.setCurrentValue(output); + context.setValue(output); + } + + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override 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 e8ed41df7b9c..f9d8002100f5 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 @@ -11,16 +11,14 @@ import com.yahoo.vespa.indexinglanguage.parser.IndexingInput; import com.yahoo.vespa.indexinglanguage.parser.ParseException; -import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; /** - * An indexing statement consisting of a list of indexing expressions, e.g "input foo | index | attribute". - * * @author Simon Thoresen Hult */ public final class StatementExpression extends ExpressionList { @@ -31,12 +29,12 @@ public final class StatementExpression extends ExpressionList { /** 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 ? + public StatementExpression(Expression... lst) { + this(Arrays.asList(lst)); //TODO Can contain null - necessary ? } - public StatementExpression(Iterable list) { - this(filterList(list), null); + public StatementExpression(Iterable lst) { + this(filterList(lst), null); } private StatementExpression(Iterable list, Object unused) { @@ -55,37 +53,6 @@ public StatementExpression convertChildren(ExpressionConverter converter) { .toList()); } - @Override - protected void doVerify(VerificationContext context) { - if (expressions().isEmpty()) return; - - outputField = outputFieldName(); - if (outputField != null) - context.setOutputField(outputField); - - // 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); - // 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(--j).getInputType(context); - while (--j >= 0 && outputType != null) - outputType = expressions().get(j).setOutputType(outputType, context); - - for (Expression expression : expressions()) - context.verify(expression); - } - @Override protected void doExecute(ExecutionContext context) { for (Expression expression : this) { @@ -93,12 +60,16 @@ protected void doExecute(ExecutionContext context) { } } - private String outputFieldName() { + @Override + protected void doVerify(VerificationContext context) { for (Expression expression : this) { - if (expression instanceof OutputExpression output) - return output.getFieldName(); + if (expression instanceof OutputExpression) + outputField = ((OutputExpression)expression).getFieldName(); } - return null; + if (outputField != null) + context.setOutputField(outputField); + for (Expression expression : this) + context.execute(expression); } private static DataType resolveInputType(Iterable expressions) { @@ -144,16 +115,16 @@ public static StatementExpression newInstance(ScriptParserContext config) throws return ScriptParser.parseStatement(config); } - private static List filterList(Iterable list) { - List filtered = new ArrayList<>(); - for (Expression expression : list) { - if (expression instanceof StatementExpression statement) { - filtered.addAll(filterList(statement)); - } else if (expression != null) { - filtered.add(expression); + private static List filterList(Iterable lst) { + List ret = new LinkedList<>(); + for (Expression exp : lst) { + if (exp instanceof StatementExpression) { + ret.addAll(filterList((StatementExpression)exp)); + } else if (exp != null) { + ret.add(exp); } } - return filtered; + return ret; } } 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 00765e0b263c..ea9ed4098953 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 @@ -22,20 +22,24 @@ public SubstringExpression(int from, int to) { this.to = to; } - public int getFrom() { return from; } - - public int getTo() { return to; } + public int getFrom() { + return from; + } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + public int getTo() { + return to; } @Override protected void doExecute(ExecutionContext context) { - String input = String.valueOf(context.getCurrentValue()); + String input = String.valueOf(context.getValue()); String substring = Text.substringByCodepoints(input, from, to); - context.setCurrentValue(new StringFieldValue(substring)); + context.setValue(new StringFieldValue(substring)); + } + + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override 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 120f08847f5e..34849096b366 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 @@ -33,16 +33,6 @@ public SwitchExpression(Map cases, Expression this.cases.putAll(cases); } - public boolean isEmpty() { - return defaultExp == null && cases.isEmpty(); - } - - public Map getCases() { - return Collections.unmodifiableMap(cases); - } - - public Expression getDefaultExpression() { return defaultExp; } - @Override public SwitchExpression convertChildren(ExpressionConverter converter) { var convertedCases = new LinkedHashMap(); @@ -54,6 +44,18 @@ public SwitchExpression convertChildren(ExpressionConverter converter) { return new SwitchExpression(convertedCases, converter.branch().convert(defaultExp)); } + public boolean isEmpty() { + return defaultExp == null && cases.isEmpty(); + } + + public Map getCases() { + return Collections.unmodifiableMap(cases); + } + + public Expression getDefaultExpression() { + return defaultExp; + } + @Override public void setStatementOutput(DocumentType documentType, Field field) { defaultExp.setStatementOutput(documentType, field); @@ -61,26 +63,9 @@ public void setStatementOutput(DocumentType documentType, Field field) { expression.setStatementOutput(documentType, field); } - @Override - protected void doVerify(VerificationContext context) { - DataType input = context.getCurrentType(); - if (input == null) { - throw new VerificationException(this, "Expected " + DataType.STRING.getName() + " input, but no input is specified"); - } - if (input != DataType.STRING) { - throw new VerificationException(this, "Expected " + DataType.STRING.getName() + " input, got " + - input.getName()); - } - for (Expression exp : cases.values()) { - context.setCurrentType(input).verify(exp); - } - context.setCurrentType(input).verify(defaultExp); - context.setCurrentType(input); - } - @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); + FieldValue input = context.getValue(); Expression exp = null; if (input != null) { if (!(input instanceof StringFieldValue)) { @@ -95,7 +80,7 @@ protected void doExecute(ExecutionContext context) { if (exp != null) { exp.execute(context); } - context.setCurrentValue(input); + context.setValue(input); } @Override @@ -107,7 +92,26 @@ public void selectMembers(ObjectPredicate predicate, ObjectOperation operation) } @Override - public DataType createdOutputType() { return null; } + protected void doVerify(VerificationContext context) { + DataType input = context.getValueType(); + if (input == null) { + throw new VerificationException(this, "Expected " + DataType.STRING.getName() + " input, but no input is specified"); + } + if (input != DataType.STRING) { + throw new VerificationException(this, "Expected " + DataType.STRING.getName() + " input, got " + + input.getName()); + } + for (Expression exp : cases.values()) { + context.setValueType(input).execute(exp); + } + context.setValueType(input).execute(defaultExp); + context.setValueType(input); + } + + @Override + public DataType createdOutputType() { + return null; + } @Override public String toString() { diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java index b3e5e5c23f82..c74e408e05be 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/ThisExpression.java @@ -13,20 +13,24 @@ public ThisExpression() { } @Override - protected void doVerify(VerificationContext context) { + protected void doExecute(ExecutionContext context) { // empty } @Override - protected void doExecute(ExecutionContext context) { + protected void doVerify(VerificationContext context) { // empty } @Override - public DataType createdOutputType() { return UnresolvedDataType.INSTANCE; } + public DataType createdOutputType() { + return UnresolvedDataType.INSTANCE; + } @Override - public String toString() { return "this"; } + public String toString() { + return "this"; + } @Override public boolean equals(Object obj) { 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 303458a19ff7..779add656c01 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,22 +15,22 @@ public ToArrayExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(DataType.getArray(context.getCurrentType())); - } - @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); + FieldValue input = context.getValue(); DataType inputType = input.getDataType(); ArrayDataType outputType = DataType.getArray(inputType); Array output = outputType.createFieldValue(); output.add(input); - context.setCurrentValue(output); + context.setValue(output); + } + + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(DataType.getArray(context.getValueType())); } @Override @@ -39,7 +39,9 @@ public DataType createdOutputType() { } @Override - public String toString() { return "to_array"; } + public String toString() { + return "to_array"; + } @Override public boolean equals(Object obj) { 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 3e0523995322..fa9d93efd031 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 @@ -16,14 +16,9 @@ public ToBoolExpression() { super(UnresolvedDataType.INSTANCE); } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); - } - @Override protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new BoolFieldValue(toBooleanValue(context.getCurrentValue()))); + context.setValue(new BoolFieldValue(toBooleanValue(context.getValue()))); } private boolean toBooleanValue(FieldValue value) { @@ -35,10 +30,19 @@ private boolean toBooleanValue(FieldValue value) { } @Override - public DataType createdOutputType() { return DataType.BOOL; } + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); + } + + @Override + public DataType createdOutputType() { + return DataType.BOOL; + } @Override - public String toString() { return "to_bool"; } + public String toString() { + return "to_bool"; + } @Override public boolean equals(Object obj) { 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 1606a9a70f62..260138364681 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 @@ -14,20 +14,24 @@ public ToByteExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new ByteFieldValue(Byte.valueOf(String.valueOf(context.getValue())))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new ByteFieldValue(Byte.valueOf(String.valueOf(context.getCurrentValue())))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.BYTE; } + public DataType createdOutputType() { + return DataType.BYTE; + } @Override - public String toString() { return "to_byte"; } + public String toString() { + return "to_byte"; + } @Override public boolean equals(Object obj) { 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 4f0e75c3f770..7487c001e5bc 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 @@ -14,20 +14,24 @@ public ToDoubleExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new DoubleFieldValue(Double.valueOf(String.valueOf(context.getValue())))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new DoubleFieldValue(Double.valueOf(String.valueOf(context.getCurrentValue())))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.DOUBLE; } + public DataType createdOutputType() { + return DataType.DOUBLE; + } @Override - public String toString() { return "to_double"; } + public String toString() { + return "to_double"; + } @Override public boolean equals(Object obj) { 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 37032852b92e..ac3735188f4a 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 @@ -10,29 +10,33 @@ * * @author bergum */ -public class ToEpochSecondExpression extends Expression { +public class ToEpochSecondExpression extends Expression { public ToEpochSecondExpression() { super(DataType.STRING); //only accept string input } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + String inputString = String.valueOf(context.getValue()); + long epochTime = Instant.parse(inputString).getEpochSecond(); + context.setValue(new LongFieldValue(epochTime)); } @Override - protected void doExecute(ExecutionContext context) { - String inputString = String.valueOf(context.getCurrentValue()); - long epochTime = Instant.parse(inputString).getEpochSecond(); - context.setCurrentValue(new LongFieldValue(epochTime)); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.LONG; } + public DataType createdOutputType() { + return DataType.LONG; + } @Override - public String toString() { return "to_epoch_second"; } + public String toString() { + return "to_epoch_second"; + } @Override public boolean equals(Object obj) { 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 91b51e8b7e34..d61a04350934 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 @@ -14,20 +14,24 @@ public ToFloatExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new FloatFieldValue(Float.valueOf(String.valueOf(context.getValue())))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new FloatFieldValue(Float.valueOf(String.valueOf(context.getCurrentValue())))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.FLOAT; } + public DataType createdOutputType() { + return DataType.FLOAT; + } @Override - public String toString() { return "to_float"; } + public String toString() { + return "to_float"; + } @Override public boolean equals(Object obj) { 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 cbf1ff949ce8..1efa0542e8c0 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 @@ -14,20 +14,24 @@ public ToIntegerExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new IntegerFieldValue(Integer.valueOf(String.valueOf(context.getValue())))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new IntegerFieldValue(Integer.valueOf(String.valueOf(context.getCurrentValue())))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.INT; } + public DataType createdOutputType() { + return DataType.INT; + } @Override - public String toString() { return "to_int"; } + public String toString() { + return "to_int"; + } @Override public boolean equals(Object obj) { 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 dc601a9e2dd3..d7ffee3cdf6b 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 @@ -14,20 +14,24 @@ public ToLongExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new LongFieldValue(Long.valueOf(String.valueOf(context.getValue())))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new LongFieldValue(Long.valueOf(String.valueOf(context.getCurrentValue())))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.LONG; } + public DataType createdOutputType() { + return DataType.LONG; + } @Override - public String toString() { return "to_long"; } + public String toString() { + return "to_long"; + } @Override public boolean equals(Object obj) { 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 0d4bafaf8ed5..7e4b61ceda32 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 @@ -14,20 +14,24 @@ public ToPositionExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(PositionDataType.fromString(String.valueOf(context.getValue()))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(PositionDataType.fromString(String.valueOf(context.getCurrentValue()))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return PositionDataType.INSTANCE; } + public DataType createdOutputType() { + return PositionDataType.INSTANCE; + } @Override - public String toString() { return "to_pos"; } + public String toString() { + return "to_pos"; + } @Override public boolean equals(Object obj) { @@ -38,6 +42,5 @@ public boolean equals(Object obj) { public int hashCode() { return getClass().hashCode(); } - } 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 d1209e59710b..11e13477d62a 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 @@ -14,20 +14,24 @@ public ToStringExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new StringFieldValue(String.valueOf(context.getValue()))); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new StringFieldValue(String.valueOf(context.getCurrentValue()))); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.STRING; } + public DataType createdOutputType() { + return DataType.STRING; + } @Override - public String toString() { return "to_string"; } + public String toString() { + return "to_string"; + } @Override public boolean equals(Object obj) { 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 6ed50759e253..1154bf39c05d 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 @@ -20,30 +20,36 @@ public ToWsetExpression(boolean createIfNonExistent, boolean removeIfZero) { this.removeIfZero = removeIfZero; } - public boolean getCreateIfNonExistent() { return createIfNonExistent; } - - public boolean getRemoveIfZero() { return removeIfZero; } + public boolean getCreateIfNonExistent() { + return createIfNonExistent; + } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(DataType.getWeightedSet(context.getCurrentType(), createIfNonExistent, removeIfZero)); + public boolean getRemoveIfZero() { + return removeIfZero; } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void doExecute(ExecutionContext context) { - FieldValue input = context.getCurrentValue(); + FieldValue input = context.getValue(); DataType inputType = input.getDataType(); WeightedSetDataType outputType = DataType.getWeightedSet(inputType, createIfNonExistent, removeIfZero); WeightedSet output = outputType.createFieldValue(); output.add(input); - context.setCurrentValue(output); + context.setValue(output); + } + + @Override + protected void doVerify(VerificationContext context) { + context.setValueType(DataType.getWeightedSet(context.getValueType(), createIfNonExistent, removeIfZero)); } @Override - public DataType createdOutputType() { return UnresolvedDataType.INSTANCE; } + public DataType createdOutputType() { + return UnresolvedDataType.INSTANCE; + } @Override public String toString() { @@ -54,16 +60,24 @@ public String toString() { @Override public boolean equals(Object obj) { - if (!(obj instanceof ToWsetExpression rhs)) return false; - - if (createIfNonExistent != rhs.createIfNonExistent) return false; - if (removeIfZero != rhs.removeIfZero) return false; + if (!(obj instanceof ToWsetExpression)) { + return false; + } + ToWsetExpression rhs = (ToWsetExpression)obj; + if (createIfNonExistent != rhs.createIfNonExistent) { + return false; + } + if (removeIfZero != rhs.removeIfZero) { + return false; + } return true; } @Override public int hashCode() { - return getClass().hashCode() + createIfNonExistent.hashCode() + removeIfZero.hashCode(); + return getClass().hashCode() + + createIfNonExistent.hashCode() + + removeIfZero.hashCode(); } } 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 64d6c0a5a199..a3c404e50c39 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 @@ -23,20 +23,19 @@ public TokenizeExpression(Linguistics linguistics, AnnotatorConfig config) { this.config = config; } - public Linguistics getLinguistics() { return linguistics; } - - public AnnotatorConfig getConfig() { return config; } + public Linguistics getLinguistics() { + return linguistics; + } - @Override - protected void doVerify(VerificationContext context) { - // empty + public AnnotatorConfig getConfig() { + return config; } @Override protected void doExecute(ExecutionContext context) { - StringFieldValue input = (StringFieldValue)context.getCurrentValue(); + StringFieldValue input = (StringFieldValue)context.getValue(); StringFieldValue output = input.clone(); - context.setCurrentValue(output); + context.setValue(output); AnnotatorConfig cfg = new AnnotatorConfig(config); Language lang = context.resolveLanguage(linguistics); @@ -48,7 +47,14 @@ protected void doExecute(ExecutionContext context) { } @Override - public DataType createdOutputType() { return null; } + protected void doVerify(VerificationContext context) { + // empty + } + + @Override + public DataType createdOutputType() { + return null; + } @Override public String toString() { 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 78f89fabe460..3722791aa33d 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 @@ -14,25 +14,30 @@ public TrimExpression() { } @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); + protected void doExecute(ExecutionContext context) { + context.setValue(new StringFieldValue(String.valueOf(context.getValue()).trim())); } @Override - protected void doExecute(ExecutionContext context) { - context.setCurrentValue(new StringFieldValue(String.valueOf(context.getCurrentValue()).trim())); + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); } @Override - public DataType createdOutputType() { return DataType.STRING; } + public DataType createdOutputType() { + return DataType.STRING; + } @Override - public String toString() { return "trim"; } + public String toString() { + return "trim"; + } @Override public boolean equals(Object obj) { - if (!(obj instanceof TrimExpression)) return false; - + if (!(obj instanceof TrimExpression)) { + return false; + } return true; } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedFieldValue.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedFieldValue.java index 401b3b0978c0..f973f6a2fb82 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedFieldValue.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/UnresolvedFieldValue.java @@ -22,7 +22,9 @@ private static class Factory extends PrimitiveDataType.Factory { public static PrimitiveDataType.Factory getFactory() { return new Factory(); } @Override - public DataType getDataType() { return UnresolvedDataType.INSTANCE; } + public DataType getDataType() { + return UnresolvedDataType.INSTANCE; + } @Override @Deprecated diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java index ae49130f1ce7..a2926fb90398 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContext.java @@ -9,69 +9,69 @@ /** * @author Simon Thoresen Hult */ -public class VerificationContext { +public class VerificationContext implements FieldTypeAdapter, Cloneable { private final Map variables = new HashMap<>(); - private final FieldTypeAdapter fieldType; - private DataType currentType; + private final FieldTypeAdapter adapter; + private DataType value; private String outputField; public VerificationContext() { - this(null); + this.adapter = null; } - public VerificationContext(FieldTypeAdapter field) { - this.fieldType = field; + public VerificationContext(FieldTypeAdapter adapter) { + this.adapter = adapter; } - public VerificationContext verify(Expression expression) { - if (expression != null) - expression.verify(this); + public VerificationContext execute(Expression exp) { + if (exp != null) { + exp.verify(this); + } return this; } - /** Returns the type of the field processed by this. */ - public DataType getFieldType(Expression expression) { - return fieldType.getInputType(expression, getOutputField()); + @Override + public DataType getInputType(Expression exp, String fieldName) { + return adapter.getInputType(exp, fieldName); } - /** Returns the type of the given field. */ - public DataType getFieldType(String fieldName, Expression expression) { - return fieldType.getInputType(expression, fieldName); + @Override + public void tryOutputType(Expression exp, String fieldName, DataType valueType) { + adapter.tryOutputType(exp, fieldName, valueType); } - public void tryOutputType(String fieldName, DataType valueType, Expression expression) { - fieldType.tryOutputType(expression, fieldName, valueType); + public DataType getVariable(String name) { + return variables.get(name); } - /** Returns the current value type */ - public DataType getCurrentType() { return currentType; } - - /** Returns the current value type */ - public VerificationContext setCurrentType(DataType value) { - this.currentType = value; + public VerificationContext setVariable(String name, DataType value) { + variables.put(name, value); return this; } - public DataType getVariable(String name) { return variables.get(name); } + public DataType getValueType() { + return value; + } - public VerificationContext setVariable(String name, DataType value) { - variables.put(name, value); + /** Sets the output value type */ + public VerificationContext setValueType(DataType value) { + this.value = value; return this; } + /** Sets the name of the (last) output field of the statement this is executed as a part of */ + public void setOutputField(String outputField) { this.outputField = outputField; } + /** * Returns the name of the (last) output field of the statement this is executed as a part of, * or null if none or not yet verified */ public String getOutputField() { return outputField; } - /** Sets the name of the (last) output field of the statement this is executed as a part of */ - public void setOutputField(String outputField) { this.outputField = outputField; } - public VerificationContext clear() { variables.clear(); - currentType = null; + value = null; return this; } 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 cfc7273d0901..b2462b738210 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 @@ -20,15 +20,19 @@ public VerificationException(Expression exp, String msg) { } } + public VerificationException(Class exp, String msg) { super(msg); this.type = exp; this.exp = exp.getName(); } - public String getExpression() { return exp; } - - public Class getExpressionType() { return type; } + public String getExpression() { + return exp; + } + public Class getExpressionType() { + return type; + } @Override public String toString() { 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 9d6826ba2535..4ad1fc79790c 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 @@ -17,20 +17,15 @@ public ZCurveExpression() { super(PositionDataType.INSTANCE); } - @Override - protected void doVerify(VerificationContext context) { - context.setCurrentType(createdOutputType()); - } - @Override protected void doExecute(ExecutionContext context) { - Struct input = ((Struct) context.getCurrentValue()); + Struct input = ((Struct) context.getValue()); Integer x = getFieldValue(input, PositionDataType.FIELD_X); Integer y = getFieldValue(input, PositionDataType.FIELD_Y); if (x != null && y != null) { - context.setCurrentValue(new LongFieldValue(ZCurve.encode(x, y))); + context.setValue(new LongFieldValue(ZCurve.encode(x, y))); } else { - context.setCurrentValue(DataType.LONG.createFieldValue()); + context.setValue(DataType.LONG.createFieldValue()); } } @@ -40,14 +35,25 @@ private static Integer getFieldValue(Struct struct, String fieldName) { } @Override - public DataType createdOutputType() { return DataType.LONG; } + protected void doVerify(VerificationContext context) { + context.setValueType(createdOutputType()); + } @Override - public String toString() { return "zcurve"; } + public DataType createdOutputType() { + return DataType.LONG; + } + + @Override + public String toString() { + return "zcurve"; + } @Override public boolean equals(Object obj) { - if (!(obj instanceof ZCurveExpression)) return false; + if (!(obj instanceof ZCurveExpression)) { + return false; + } return true; } diff --git a/indexinglanguage/src/main/javacc/IndexingParser.jj b/indexinglanguage/src/main/javacc/IndexingParser.jj index fbf460ae6f6c..09aa3829ab91 100644 --- a/indexinglanguage/src/main/javacc/IndexingParser.jj +++ b/indexinglanguage/src/main/javacc/IndexingParser.jj @@ -149,7 +149,6 @@ TOKEN : | | | - | | | | @@ -180,7 +179,6 @@ TOKEN : | | | - | | | | @@ -210,6 +208,7 @@ TOKEN : | | | + | | } @@ -327,7 +326,6 @@ Expression value() : val = normalizeExp() | val = nowExp() | val = optimizePredicateExp() | - val = packBitsExp() | val = passthroughExp() | val = randomExp() | val = script() | @@ -572,12 +570,6 @@ Expression optimizePredicateExp() : { } { return new OptimizePredicateExpression(); } } -Expression packBitsExp() : { } -{ - ( ) - { return new PackBitsExpression(); } -} - Expression passthroughExp() : { String val = defaultFieldName; @@ -854,7 +846,6 @@ String identifier() : | | | - | | | | 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 b46232f0f2e1..0b0b00498860 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTestCase.java @@ -15,7 +15,6 @@ import com.yahoo.vespa.indexinglanguage.expressions.ExecutionContext; import com.yahoo.vespa.indexinglanguage.expressions.VerificationContext; import com.yahoo.vespa.indexinglanguage.expressions.VerificationException; -import org.junit.Ignore; import org.junit.Test; import java.util.Map; @@ -60,12 +59,6 @@ public void testEmbedAndBinarize() { tester.testStatement("input myText | embed | binarize 3.0 | attribute 'myTensor'", "input text", "[0, 0, 0, 1]"); } - @Test - public void testEmbedBinarizeAndPack_bits() { - var tester = new EmbeddingScriptTester(Map.of("emb1", new EmbeddingScriptTester.MockIndexedEmbedder("myDocument.myTensor", -111))); - tester.testStatement("input myText | embed | binarize | pack_bits | attribute 'myTensor'", "input text", "tensor(x[2])", "[58, 192]"); - } - @SuppressWarnings("unchecked") @Test public void testArrayEmbed() { @@ -91,7 +84,7 @@ public void testArrayEmbed() { assertEquals(new ArrayDataType(new TensorDataType(tensorType)), expression.verify(verificationContext)); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(array); + context.setValue(array); expression.execute(context); assertTrue(adapter.values.containsKey("myTensorArray")); var tensorArray = (Array)adapter.values.get("myTensorArray"); @@ -128,7 +121,7 @@ public void testArrayEmbedWithConcatenation() { assertEquals(new TensorDataType(tensorType), expression.verify(verificationContext)); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(array); + context.setValue(array); expression.execute(context); assertTrue(adapter.values.containsKey("mySparseTensor")); var sparseTensor = (TensorFieldValue)adapter.values.get("mySparseTensor"); @@ -161,7 +154,7 @@ public void testArrayEmbedTo2dMixedTensor() { assertEquals(new TensorDataType(tensorType), expression.verify(verificationContext)); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(array); + context.setValue(array); expression.execute(context); assertTrue(adapter.values.containsKey("mySparseTensor")); var sparseTensor = (TensorFieldValue)adapter.values.get("mySparseTensor"); @@ -192,7 +185,7 @@ public void testArrayEmbedTo3dMixedTensor() { assertEquals(new TensorDataType(tensorType), expression.verify(new VerificationContext(adapter))); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(array); + context.setValue(array); expression.execute(context); assertTrue(adapter.values.containsKey("mySparseTensor")); var sparseTensor = (TensorFieldValue)adapter.values.get("mySparseTensor"); @@ -296,7 +289,7 @@ public void testEmbedToSparseTensor() { assertEquals(new TensorDataType(tensorType), expression.verify(verificationContext)); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(text); + context.setValue(text); expression.execute(context); assertTrue(adapter.values.containsKey("mySparseTensor")); var sparseTensor = (TensorFieldValue)adapter.values.get("mySparseTensor"); @@ -352,7 +345,7 @@ public void testArrayEmbedTo2MappedTensor() { assertEquals(new TensorDataType(tensorType), expression.verify(new VerificationContext(adapter))); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(array); + context.setValue(array); expression.execute(context); assertTrue(adapter.values.containsKey("my2DSparseTensor")); var sparse2DTensor = (TensorFieldValue)adapter.values.get("my2DSparseTensor"); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTester.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTester.java index c4a53c1af683..b75834f1a163 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTester.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/EmbeddingScriptTester.java @@ -32,12 +32,8 @@ public EmbeddingScriptTester(Map embedders) { } public void testStatement(String expressionString, String input, String expected) { - testStatement(expressionString, input, "tensor(d[4])", expected); - } - - public void testStatement(String expressionString, String input, String targetTensorType, String expected) { var expression = expressionFrom(expressionString); - TensorType tensorType = TensorType.fromSpec(targetTensorType); + TensorType tensorType = TensorType.fromSpec("tensor(d[4])"); SimpleTestAdapter adapter = new SimpleTestAdapter(); adapter.createField(new Field("myText", DataType.STRING)); 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 2a145ae79e3f..c4bd69663df7 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -6,14 +6,23 @@ import com.yahoo.document.Document; import com.yahoo.document.DocumentType; import com.yahoo.document.Field; +import com.yahoo.document.TensorDataType; import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.BoolFieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.StringFieldValue; +import com.yahoo.document.datatypes.TensorFieldValue; +import com.yahoo.language.process.Embedder; +import com.yahoo.language.simple.SimpleLinguistics; +import com.yahoo.tensor.Tensor; +import com.yahoo.tensor.TensorType; import com.yahoo.vespa.indexinglanguage.expressions.*; import com.yahoo.vespa.indexinglanguage.parser.ParseException; import org.junit.Test; +import java.util.List; +import java.util.Map; + import static org.junit.Assert.*; /** @@ -109,7 +118,7 @@ public void testIntHash() throws ParseException { assertEquals(DataType.INT, expression.verify(verificationContext)); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(new StringFieldValue("input text")); + context.setValue(new StringFieldValue("input text")); expression.execute(context); assertTrue(adapter.values.containsKey("myInt")); assertEquals(-1425622096, adapter.values.get("myInt").getWrappedValue()); @@ -135,7 +144,7 @@ public void testIntArrayHash() throws ParseException { assertEquals(new ArrayDataType(DataType.INT), expression.verify(verificationContext)); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(array); + context.setValue(array); expression.execute(context); assertTrue(adapter.values.containsKey("myIntArray")); var intArray = (Array)adapter.values.get("myIntArray"); @@ -159,7 +168,7 @@ public void testLongHash() throws ParseException { assertEquals(DataType.LONG, expression.verify(verificationContext)); ExecutionContext context = new ExecutionContext(adapter); - context.setCurrentValue(new StringFieldValue("input text")); + context.setValue(new StringFieldValue("input text")); expression.execute(context); assertTrue(adapter.values.containsKey("myLong")); assertEquals(7678158186624760752L, adapter.values.get("myLong").getWrappedValue()); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleTestAdapter.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleTestAdapter.java index 458e1337eef0..07c6301339bb 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleTestAdapter.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/SimpleTestAdapter.java @@ -17,8 +17,8 @@ */ public class SimpleTestAdapter implements FieldValueAdapter { - public final Map types = new HashMap<>(); - public final Map values = new HashMap<>(); + final Map types = new HashMap<>(); + final Map values = new HashMap<>(); public SimpleTestAdapter(Field... fields) { for (Field field : fields) { 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 bee0add22c07..f7dafebba945 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 @@ -170,7 +170,7 @@ private void assertType(DataType lhs, Operator op, DataType rhs, DataType expect private static FieldValue evaluate(Expression lhs, Operator op, Expression rhs) { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); new ArithmeticExpression(lhs, op, rhs).execute(ctx); - return ctx.getCurrentValue(); + return ctx.getValue(); } private static ArithmeticExpression newArithmetic(long lhs, Operator op, long rhs) { 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 2d4f7afc6dc2..08a0d8353a70 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 @@ -28,10 +28,10 @@ public void requireThatHashCodeAndEqualsAreImplemented() { @Test public void requireThatInputIsDecoded() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("zcIoHQ")); + ctx.setValue(new StringFieldValue("zcIoHQ")); new Base64DecodeExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof LongFieldValue); assertEquals(489210573L, ((LongFieldValue)val).getLong()); } 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 2f73c07d3c8e..20dfd762057f 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 @@ -28,10 +28,10 @@ public void requireThatHashCodeAndEqualsAreImplemented() { @Test public void requireThatInputIsEncoded() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new LongFieldValue(489210573L)); + ctx.setValue(new LongFieldValue(489210573L)); new Base64EncodeExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("zcIoHQAAAAA=", ((StringFieldValue)val).getString()); } 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 cfaeafa5f6c5..17388f656567 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 @@ -234,16 +234,16 @@ private static FieldValue evaluate(FieldValue valA, FieldValue valB) { private static FieldValue evaluate(DataType typeA, FieldValue valA, DataType typeB, FieldValue valB) { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field("a", typeA), new Field("b", typeB))); - ctx.setFieldValue("a", valA, null); - ctx.setFieldValue("b", valB, null); + ctx.setOutputValue(null, "a", valA); + ctx.setOutputValue(null, "b", valB); new CatExpression(new InputExpression("a"), new InputExpression("b")).execute(ctx); - return ctx.getCurrentValue(); + return ctx.getValue(); } private static DataType evaluate(DataType typeA, DataType typeB) { SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("a", typeA), new Field("b", typeB)); VerificationContext ctx = new VerificationContext(adapter); new CatExpression(new InputExpression("a"), new InputExpression("b")).verify(ctx); - return ctx.getCurrentType(); + return ctx.getValueType(); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java index 05f3bfb9b117..f36ef96270cf 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ChoiceTestCase.java @@ -2,9 +2,11 @@ package com.yahoo.vespa.indexinglanguage.expressions; import com.yahoo.document.DataType; +import com.yahoo.document.Document; import com.yahoo.document.Field; import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.StringFieldValue; +import com.yahoo.language.Linguistics; import com.yahoo.language.process.Embedder; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.vespa.indexinglanguage.ExpressionSearcher; @@ -29,7 +31,7 @@ public void testChoiceExecution() { adapter.setValue("foo", new StringFieldValue("foo1")); ExecutionContext context = new ExecutionContext(adapter); choice.execute(context); - assertEquals("foo1", context.getCurrentValue().getWrappedValue()); + assertEquals("foo1", context.getValue().getWrappedValue()); } { // bar only @@ -37,7 +39,7 @@ public void testChoiceExecution() { adapter.setValue("bar", new StringFieldValue("bar1")); ExecutionContext context = new ExecutionContext(adapter); choice.execute(context); - assertEquals("bar1", context.getCurrentValue().getWrappedValue()); + assertEquals("bar1", context.getValue().getWrappedValue()); } { // both foo and bar @@ -47,7 +49,7 @@ public void testChoiceExecution() { choice.verify(adapter); ExecutionContext context = new ExecutionContext(adapter); choice.execute(context); - assertEquals("foo1", context.getCurrentValue().getWrappedValue()); + assertEquals("foo1", context.getValue().getWrappedValue()); } } @@ -61,7 +63,7 @@ public void testChoiceWithConstant() throws ParseException { adapter.setValue("timestamp", new LongFieldValue(34)); ExecutionContext context = new ExecutionContext(adapter); choice.execute(context); - assertEquals(34L, context.getCurrentValue().getWrappedValue()); + assertEquals(34L, context.getValue().getWrappedValue()); } { // fallback to default @@ -69,7 +71,7 @@ public void testChoiceWithConstant() throws ParseException { choice.verify(adapter); ExecutionContext context = new ExecutionContext(adapter); choice.execute(context); - assertEquals(99999999L, context.getCurrentValue().getWrappedValue()); + assertEquals(99999999L, context.getValue().getWrappedValue()); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java index cb480a36bf4d..c9c24c0ecf03 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ClearStateTestCase.java @@ -38,7 +38,7 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatVerificationContextIsCleared() { MyVerification ctx = new MyVerification(); - ctx.verify(new ClearStateExpression()); + ctx.execute(new ClearStateExpression()); assertTrue(ctx.cleared); } 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 9bce89b62330..6a7e88be51a0 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 @@ -42,7 +42,7 @@ public void requireThatValueIsEchoed() { ByteArrayOutputStream out = new ByteArrayOutputStream(); ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("69")); + ctx.setValue(new StringFieldValue("69")); new EchoExpression(new PrintStream(out)).execute(ctx); assertEquals("69" + System.getProperty("line.separator"), out.toString()); 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 bff8b81d4fd1..b338c45f7a40 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 @@ -29,55 +29,55 @@ public void requireThatHashCodeAndEqualsAreImplemented() { @Test public void requireThatValueIsNotChanged() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("FOO")); + ctx.setValue(new StringFieldValue("FOO")); new ExactExpression().execute(ctx); - assertEquals("FOO", String.valueOf(ctx.getCurrentValue())); + assertEquals("FOO", String.valueOf(ctx.getValue())); } @Test public void requireThatValueIsAnnotated() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("FOO")); + ctx.setValue(new StringFieldValue("FOO")); new ExactExpression().execute(ctx); - assertAnnotation(0, 3, new StringFieldValue("foo"), (StringFieldValue)ctx.getCurrentValue()); + assertAnnotation(0, 3, new StringFieldValue("foo"), (StringFieldValue)ctx.getValue()); } @Test public void requireThatThereIsNoSegmentation() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("FOO BAR")); + ctx.setValue(new StringFieldValue("FOO BAR")); new ExactExpression().execute(ctx); - assertAnnotation(0, 7, new StringFieldValue("foo bar"), (StringFieldValue)ctx.getCurrentValue()); + assertAnnotation(0, 7, new StringFieldValue("foo bar"), (StringFieldValue)ctx.getValue()); } @Test public void requireThatRedundantAnnotationValueIsIgnored() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("foo")); + ctx.setValue(new StringFieldValue("foo")); new ExactExpression().execute(ctx); - assertAnnotation(0, 3, null, (StringFieldValue)ctx.getCurrentValue()); + assertAnnotation(0, 3, null, (StringFieldValue)ctx.getValue()); } @Test public void requireThatLongStringsAreNotAnnotated() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("foo")); + ctx.setValue(new StringFieldValue("foo")); new ExactExpression(2).execute(ctx); - assertNull(((StringFieldValue)ctx.getCurrentValue()).getSpanTree(SpanTrees.LINGUISTICS)); + assertNull(((StringFieldValue)ctx.getValue()).getSpanTree(SpanTrees.LINGUISTICS)); } @Test public void requireThatEmptyStringsAreNotAnnotated() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("")); + ctx.setValue(new StringFieldValue("")); new ExactExpression().execute(ctx); - assertNull(((StringFieldValue)ctx.getCurrentValue()).getSpanTree(SpanTrees.LINGUISTICS)); + assertNull(((StringFieldValue)ctx.getValue()).getSpanTree(SpanTrees.LINGUISTICS)); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContextTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContextTestCase.java index be048ba67fcc..6d14b34bfb84 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContextTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/ExecutionContextTestCase.java @@ -4,6 +4,7 @@ import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.language.Language; +import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import org.junit.Test; @@ -18,8 +19,8 @@ public class ExecutionContextTestCase { public void requireThatValueCanBeSet() { ExecutionContext ctx = new ExecutionContext(); FieldValue val = new StringFieldValue("foo"); - ctx.setCurrentValue(val); - assertSame(val, ctx.getCurrentValue()); + ctx.setValue(val); + assertSame(val, ctx.getValue()); } @Test @@ -51,9 +52,9 @@ public void requireThatNullLanguageThrowsException() { @Test public void requireThatClearRemovesValue() { ExecutionContext ctx = new ExecutionContext(); - ctx.setCurrentValue(new StringFieldValue("foo")); + ctx.setValue(new StringFieldValue("foo")); ctx.clear(); - assertNull(ctx.getCurrentValue()); + assertNull(ctx.getValue()); } @Test @@ -87,9 +88,9 @@ public void requireThatResolveLanguageDefaultsToEnglishWithoutValue() { @Test public void requireThatLanguageCanBeResolved() { ExecutionContext ctx = new ExecutionContext(); - ctx.setCurrentValue(new StringFieldValue("\u3072\u3089\u304c\u306a")); + ctx.setValue(new StringFieldValue("\u3072\u3089\u304c\u306a")); assertEquals(Language.JAPANESE, ctx.resolveLanguage(new SimpleLinguistics())); - ctx.setCurrentValue(new StringFieldValue("\ud55c\uae00\uacfc")); + ctx.setValue(new StringFieldValue("\ud55c\uae00\uacfc")); assertEquals(Language.KOREAN, ctx.resolveLanguage(new SimpleLinguistics())); } @@ -97,9 +98,9 @@ public void requireThatLanguageCanBeResolved() { public void requireThatExplicitLanguagePreventsDetection() { ExecutionContext ctx = new ExecutionContext(); ctx.setLanguage(Language.ARABIC); - ctx.setCurrentValue(new StringFieldValue("\u3072\u3089\u304c\u306a")); + ctx.setValue(new StringFieldValue("\u3072\u3089\u304c\u306a")); assertEquals(Language.ARABIC, ctx.resolveLanguage(new SimpleLinguistics())); - ctx.setCurrentValue(new StringFieldValue("\ud55c\uae00\uacfc")); + ctx.setValue(new StringFieldValue("\ud55c\uae00\uacfc")); assertEquals(Language.ARABIC, ctx.resolveLanguage(new SimpleLinguistics())); } } 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 755e47d64086..05c4ae33cfce 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 @@ -18,18 +18,18 @@ public static void assertVerifyCtx(VerificationContext ctx, Expression exp, Data } public static void assertVerify(DataType valueBefore, Expression exp, DataType expectedValueAfter) { - assertVerifyCtx(new VerificationContext().setCurrentType(valueBefore), exp, expectedValueAfter); + assertVerifyCtx(new VerificationContext().setValueType(valueBefore), exp, expectedValueAfter); } public static void assertVerifyThrows(DataType valueBefore, Expression exp, String expectedException) { - assertVerifyCtxThrows(new VerificationContext().setCurrentType(valueBefore), exp, expectedException); + assertVerifyCtxThrows(new VerificationContext().setValueType(valueBefore), exp, expectedException); } interface CreateExpression { Expression create(); } public static void assertVerifyThrows(DataType valueBefore, CreateExpression createExp, String expectedException) { - assertVerifyCtxThrows(new VerificationContext().setCurrentType(valueBefore), createExp, expectedException); + assertVerifyCtxThrows(new VerificationContext().setValueType(valueBefore), createExp, expectedException); } public static void assertVerifyCtxThrows(VerificationContext ctx, CreateExpression createExp, String expectedException) { 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 07adc4190af7..4d77721a3f6e 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 @@ -75,7 +75,7 @@ public void requireThatEachTokenIsExecutedSeparately() { Array arr = new Array<>(DataType.getArray(DataType.STRING)); arr.add(new StringFieldValue("6")); arr.add(new StringFieldValue("9")); - ctx.setCurrentValue(arr); + ctx.setValue(arr); MyCollector exp = new MyCollector(); new ForEachExpression(exp).execute(ctx); @@ -103,10 +103,10 @@ public void requireThatArrayCanBeConverted() { Array before = new Array<>(DataType.getArray(DataType.STRING)); before.add(new StringFieldValue("6")); before.add(new StringFieldValue("9")); - ctx.setCurrentValue(before); + ctx.setValue(before); new ForEachExpression(new ToIntegerExpression()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof Array); Array after = (Array)val; @@ -118,11 +118,11 @@ public void requireThatArrayCanBeConverted() { @Test public void requireThatEmptyArrayCanBeConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new Array(DataType.getArray(DataType.STRING))); + ctx.setValue(new Array(DataType.getArray(DataType.STRING))); new ForEachExpression(new ToIntegerExpression()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof Array); assertEquals(DataType.INT, ((Array)val).getDataType().getNestedType()); assertTrue(((Array)val).isEmpty()); @@ -143,12 +143,12 @@ public void requireThatArrayWithNullCanBeConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); Array arr = new Array<>(DataType.getArray(DataType.STRING)); arr.add(new StringFieldValue("foo")); - ctx.setCurrentValue(arr); + ctx.setValue(arr); new ForEachExpression(SimpleExpression.newConversion(DataType.STRING, DataType.INT) .setExecuteValue(null)).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof Array); assertEquals(DataType.INT, ((Array)val).getDataType().getNestedType()); assertTrue(((Array)val).isEmpty()); @@ -160,10 +160,10 @@ public void requireThatWsetCanBeConverted() { WeightedSet before = new WeightedSet<>(DataType.getWeightedSet(DataType.STRING)); before.put(new StringFieldValue("6"), 9); before.put(new StringFieldValue("9"), 6); - ctx.setCurrentValue(before); + ctx.setValue(before); new ForEachExpression(new ToIntegerExpression()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof WeightedSet); WeightedSet after = (WeightedSet)val; @@ -175,11 +175,11 @@ public void requireThatWsetCanBeConverted() { @Test public void requireThatEmptyWsetCanBeConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new WeightedSet(DataType.getWeightedSet(DataType.STRING))); + ctx.setValue(new WeightedSet(DataType.getWeightedSet(DataType.STRING))); new ForEachExpression(new ToIntegerExpression()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof WeightedSet); assertEquals(DataType.INT, ((WeightedSet)val).getDataType().getNestedType()); assertTrue(((WeightedSet)val).isEmpty()); @@ -193,11 +193,11 @@ public void requireThatStructContentCanBeConverted() { struct.setFieldValue("my_str", new StringFieldValue(" foo ")); ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(struct); + ctx.setValue(struct); new ForEachExpression(new TrimExpression()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof Struct); assertEquals(type, val.getDataType()); assertEquals(new StringFieldValue("foo"), ((Struct)val).getFieldValue("my_str")); @@ -209,7 +209,7 @@ public void requireThatIncompatibleStructFieldsFailToValidate() { type.addField(new Field("my_int", DataType.INT)); VerificationContext ctx = new VerificationContext(new SimpleTestAdapter()); - ctx.setCurrentType(type); + ctx.setValueType(type); try { new ForEachExpression(new ToArrayExpression()).verify(ctx); @@ -227,7 +227,7 @@ public void requireThatIncompatibleStructFieldsFailToExecute() { struct.setFieldValue("my_int", new IntegerFieldValue(69)); ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(struct); + ctx.setValue(struct); try { new ForEachExpression(new ToArrayExpression()).execute(ctx); @@ -247,7 +247,7 @@ private static class MyCollector extends Expression { } @Override protected void doExecute(ExecutionContext context) { - lst.add(context.getCurrentValue()); + lst.add(context.getValue()); } @Override 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 20fdf562ff1c..768f312b27c8 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 @@ -51,7 +51,7 @@ public void requireThatSymbolIsRead() { ctx.setVariable("in", new IntegerFieldValue(69)); new GetVarExpression("in").execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof IntegerFieldValue); assertEquals(69, ((IntegerFieldValue)val).getInteger()); } @@ -59,12 +59,12 @@ public void requireThatSymbolIsRead() { @Test public void requireThatGetVarCanBeUsedToImplementSum() throws ParseException { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setFieldValue("in", new StringFieldValue("0;1;2;3;4;5;6;7;8;9"), null); + ctx.setOutputValue(null, "in", new StringFieldValue("0;1;2;3;4;5;6;7;8;9")); ScriptExpression.fromString("{ 0 | set_var tmp; " + " input in | split ';' | for_each { to_int + get_var tmp | set_var tmp };" + " get_var tmp | attribute out; }").execute(ctx); - FieldValue val = ctx.getFieldValue("out"); + FieldValue val = ctx.getInputValue("out"); assertTrue(val instanceof IntegerFieldValue); assertEquals(45, ((IntegerFieldValue)val).getInteger()); } 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 9cb8977afd7b..eed3185d7d83 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 @@ -36,10 +36,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireInputIsDecoded() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("1d28c2cd")); + ctx.setValue(new StringFieldValue("1d28c2cd")); new HexDecodeExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof LongFieldValue); assertEquals(489210573L, ((LongFieldValue)val).getLong()); } @@ -47,10 +47,10 @@ public void requireInputIsDecoded() { @Test public void requireThatLargeInputIsDecoded() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("ff7a3c87fd74abff")); + ctx.setValue(new StringFieldValue("ff7a3c87fd74abff")); new HexDecodeExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof LongFieldValue); assertEquals(-37651092108694529L, ((LongFieldValue)val).getLong()); } 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 670172319101..fb9e4c9b3793 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 @@ -36,10 +36,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatInputIsEncoded() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new LongFieldValue(489210573L)); + ctx.setValue(new LongFieldValue(489210573L)); new HexEncodeExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("1d28c2cd", ((StringFieldValue)val).getString()); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameTestCase.java index 82d8d6e5393a..d331adffd55f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/HostNameTestCase.java @@ -38,7 +38,7 @@ public void requireThatHostnameIsSet() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); new HostNameExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals(HostNameExpression.normalizeHostName(getDefaults().vespaHostname()), ((StringFieldValue)val).getString()); 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 932652e65717..c45b16beadb7 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 @@ -146,7 +146,7 @@ public void requireThatElseExpIsOptional() { Comparator.GT, new ConstantExpression(new IntegerFieldValue(9)), new ConstantExpression(new StringFieldValue("69"))); - FieldValue val = ctx.setCurrentValue(new IntegerFieldValue(96)).execute(exp).getCurrentValue(); + FieldValue val = ctx.setValue(new IntegerFieldValue(96)).execute(exp).getValue(); assertTrue(val instanceof IntegerFieldValue); assertEquals(96, ((IntegerFieldValue)val).getInteger()); } 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 4c2fd545b6c6..c3739be747f6 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 @@ -47,10 +47,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatFieldIsRead() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field("in", DataType.STRING))); - ctx.setFieldValue("in", new StringFieldValue("69"), null); + ctx.setOutputValue(null, "in", new StringFieldValue("69")); new InputExpression("in").execute(ctx); - assertEquals(new StringFieldValue("69"), ctx.getCurrentValue()); + assertEquals(new StringFieldValue("69"), ctx.getValue()); } @Test 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 7c997ecebf26..fd28a3aebef8 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 @@ -46,10 +46,10 @@ public void requireThatValueIsJoined() { Array arr = new Array<>(DataType.getArray(DataType.STRING)); arr.add(new StringFieldValue("6")); arr.add(new StringFieldValue("9")); - ctx.setCurrentValue(arr); + ctx.setValue(arr); new JoinExpression(";").execute(ctx); - assertEquals(new StringFieldValue("6;9"), ctx.getCurrentValue()); + assertEquals(new StringFieldValue("6;9"), ctx.getValue()); } @Test diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpressionTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpressionTestCase.java index ab45136f4d71..514f79d88f22 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpressionTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/LiteralBoolExpressionTestCase.java @@ -46,7 +46,7 @@ public void testToString() { public void requireThatTrueBecomesTrue() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); context.execute(new LiteralBoolExpression(true)); - FieldValue value = context.getCurrentValue(); + FieldValue value = context.getValue(); assertTrue(value instanceof BoolFieldValue); assertTrue(((BoolFieldValue)value).getBoolean()); } @@ -55,7 +55,7 @@ public void requireThatTrueBecomesTrue() { public void requireThatFalseBecomesFalse() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); context.execute(new LiteralBoolExpression(false)); - FieldValue value = context.getCurrentValue(); + FieldValue value = context.getValue(); assertTrue(value instanceof BoolFieldValue); assertFalse(((BoolFieldValue)value).getBoolean()); } 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 49085ec7da18..89f782ed5258 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 @@ -35,10 +35,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatStringIsLowerCased() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("FOO")); + ctx.setValue(new StringFieldValue("FOO")); new LowerCaseExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("foo", ((StringFieldValue)val).getString()); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolverTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolverTestCase.java index 88c8b1f8bd36..ebb39257a84f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolverTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/MathResolverTestCase.java @@ -97,7 +97,7 @@ private static Expression newInteger(int val) { } private static int evaluate(Expression exp) { - FieldValue val = new ExecutionContext(new SimpleTestAdapter()).execute(exp).getCurrentValue(); + FieldValue val = new ExecutionContext(new SimpleTestAdapter()).execute(exp).getValue(); assertTrue(val instanceof IntegerFieldValue); return ((IntegerFieldValue)val).getInteger(); } 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 a3ce6a204b24..b4e266ab3ebb 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 @@ -53,10 +53,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void testNGrams() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); - context.setCurrentValue(new StringFieldValue("en gul Bille sang... ")); + context.setValue(new StringFieldValue("en gul Bille sang... ")); new NGramExpression(new SimpleLinguistics(), 3).execute(context); - StringFieldValue value = (StringFieldValue)context.getCurrentValue(); + StringFieldValue value = (StringFieldValue)context.getValue(); assertEquals("Grams are pure annotations - field value is unchanged", "en gul Bille sang... ", value.getString()); SpanTree gramTree = value.getSpanTree(SpanTrees.LINGUISTICS); @@ -80,15 +80,15 @@ public void testNGrams() { @Test public void requireThatExecuteCanBeCalledMultipleTimes() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); - context.setCurrentValue(new StringFieldValue("some random text string")); + context.setValue(new StringFieldValue("some random text string")); NGramExpression expression = new NGramExpression(new SimpleLinguistics(), 3); expression.execute(context); - SpanTree firstTree = ((StringFieldValue)context.getCurrentValue()).getSpanTree(SpanTrees.LINGUISTICS); + SpanTree firstTree = ((StringFieldValue)context.getValue()).getSpanTree(SpanTrees.LINGUISTICS); assertNotNull(firstTree); expression.execute(context); - SpanTree secondTree = ((StringFieldValue)context.getCurrentValue()).getSpanTree(SpanTrees.LINGUISTICS); + SpanTree secondTree = ((StringFieldValue)context.getValue()).getSpanTree(SpanTrees.LINGUISTICS); // The span tree instance should be the same. assertEquals(firstTree, secondTree); } 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 2c8e2c029e2a..441b9f57b39c 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 @@ -51,10 +51,10 @@ public void requireThatExpressionCanBeVerified() { public void requireThatInputIsNormalized() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); ctx.setLanguage(Language.ENGLISH); - ctx.setCurrentValue(new StringFieldValue("b\u00e9yonc\u00e8")); + ctx.setValue(new StringFieldValue("b\u00e9yonc\u00e8")); new NormalizeExpression(new SimpleLinguistics()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("beyonce", ((StringFieldValue)val).getString()); } @@ -93,11 +93,11 @@ public Transformer getTransformer() { public void requireThatBadNormalizeRetries() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); ctx.setLanguage(Language.ENGLISH); - ctx.setCurrentValue(new StringFieldValue("bad norm")); + ctx.setValue(new StringFieldValue("bad norm")); var linguistics = new MyMockLinguistics(); assertTrue(getFirst(linguistics.getTransformer())); new NormalizeExpression(linguistics).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("bad/norm", ((StringFieldValue)val).getString()); assertFalse(getFirst(linguistics.getTransformer())); @@ -108,11 +108,11 @@ public void requireThatEmptyIsNop() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); ctx.setLanguage(Language.ENGLISH); var orig = new StringFieldValue(""); - ctx.setCurrentValue(orig); + ctx.setValue(orig); var linguistics = new MyMockLinguistics(); assertTrue(getFirst(linguistics.getTransformer())); new NormalizeExpression(linguistics).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val == orig); assertTrue(getFirst(linguistics.getTransformer())); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NowTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NowTestCase.java index 4e9d51744b14..45ac36d9100a 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NowTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/NowTestCase.java @@ -45,7 +45,7 @@ public void requireThatCurrentTimeIsSet() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); new NowExpression(new MyTimer()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof LongFieldValue); assertEquals(69L, ((LongFieldValue)val).getLong()); } 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 750e3114b624..73a906ad3385 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 @@ -26,7 +26,7 @@ public void requireThatOptimizerIsCalledWithCloneOfInput() { final Predicate predicateB = Mockito.mock(Predicate.class); final PredicateFieldValue input = new PredicateFieldValue(predicateA); ExecutionContext ctx = new ExecutionContext() - .setCurrentValue(input) + .setValue(input) .setVariable("arity", new IntegerFieldValue(10)); FieldValue output = new OptimizePredicateExpression( (predicate, options) -> { @@ -44,7 +44,7 @@ public void requireThatPredicateOptionsAreSet() { final Predicate predicate = Mockito.mock(Predicate.class); final PredicateFieldValue input = new PredicateFieldValue(predicate); ExecutionContext ctx = new ExecutionContext() - .setCurrentValue(input) + .setValue(input) .setVariable("arity", new IntegerFieldValue(10)); new OptimizePredicateExpression((predicate1, options) -> { assertEquals(10, options.getArity()); @@ -80,7 +80,7 @@ public void requireThatExpressionCanBeVerified() { 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); + VerificationContext context = new VerificationContext().setValueType(DataType.PREDICATE); context.setVariable("arity", DataType.STRING); assertVerifyCtxThrows(context, exp, "Variable 'arity' must have type int"); context.setVariable("arity", DataType.INT); diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/OutputAssert.java index 23cbc0ab9760..2f41ffcfc6fc 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 @@ -16,10 +16,10 @@ class OutputAssert { public static void assertExecute(OutputExpression exp) { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field(exp.getFieldName(), DataType.STRING))); - ctx.setCurrentValue(new StringFieldValue("69")); + ctx.setValue(new StringFieldValue("69")); ctx.execute(exp); - FieldValue out = ctx.getFieldValue(exp.getFieldName()); + FieldValue out = ctx.getInputValue(exp.getFieldName()); assertTrue(out instanceof StringFieldValue); assertEquals("69", ((StringFieldValue)out).getString()); } @@ -32,14 +32,14 @@ public static void assertVerify(OutputExpression exp) { } public static void assertVerify(FieldTypeAdapter adapter, DataType value, Expression exp) { - assertEquals(value, new VerificationContext(adapter).setCurrentType(value).verify(exp).getCurrentType()); + assertEquals(value, new VerificationContext(adapter).setValueType(value).execute(exp).getValueType()); } public static void assertVerifyThrows(FieldTypeAdapter adapter, DataType value, Expression exp, String expectedException) { try { - new VerificationContext(adapter).setCurrentType(value).verify(exp); + new VerificationContext(adapter).setValueType(value).execute(exp); fail(); } catch (VerificationException e) { assertEquals(expectedException, e.getMessage()); 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 54aaba282742..9742dcadb3a7 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 @@ -44,10 +44,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatNestedExpressionIsRun() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field("in", DataType.STRING))); - ctx.setFieldValue("in", new StringFieldValue("69"), null); + ctx.setOutputValue(null, "in", new StringFieldValue("69")); new ParenthesisExpression(new InputExpression("in")).execute(ctx); - assertTrue(ctx.getCurrentValue() instanceof StringFieldValue); - assertEquals("69", ((StringFieldValue)ctx.getCurrentValue()).getString()); + assertTrue(ctx.getValue() instanceof StringFieldValue); + assertEquals("69", ((StringFieldValue)ctx.getValue()).getString()); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/RandomTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/RandomTestCase.java index ada30f7d5ae7..20c2521d94e7 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/RandomTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/RandomTestCase.java @@ -45,7 +45,7 @@ public void requireThatRandomValueIsSet() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); new RandomExpression(69).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof IntegerFieldValue); assertTrue(((IntegerFieldValue)val).getInteger() < 69); } @@ -54,10 +54,10 @@ public void requireThatRandomValueIsSet() { @Test public void requireThatInputValueIsParsedAsMaxIfNoneIsConfigured() { for (int i = 0; i < 666; ++i) { - ExecutionContext ctx = new ExecutionContext().setCurrentValue(new IntegerFieldValue(69)); + ExecutionContext ctx = new ExecutionContext().setValue(new IntegerFieldValue(69)); new RandomExpression().execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof IntegerFieldValue); assertTrue(((IntegerFieldValue)val).getInteger() < 69); } @@ -72,7 +72,7 @@ public void requireThatIllegalInputThrowsNumberFormatException() { } try { - new RandomExpression().execute(new ExecutionContext().setCurrentValue(new StringFieldValue("foo"))); + new RandomExpression().execute(new ExecutionContext().setValue(new StringFieldValue("foo"))); fail(); } catch (NumberFormatException e) { 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 a6fdf9db90e8..c6fb7c1db8c4 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 @@ -1,10 +1,8 @@ // 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.Field; -import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; @@ -145,24 +143,6 @@ public void requireThatVariablesReplaceOthersOutsideScript() { assertEquals(new IntegerFieldValue(9), adapter.getInputValue("out")); } - @Test - // input debug_src | lowercase | summary | index | split ";" | for_each { - public void testSplitAndForEach() { - var adapter = new SimpleTestAdapter(); - adapter.createField(new Field("myString", DataType.STRING)); - adapter.createField(new Field("myArray", new ArrayDataType(DataType.STRING))); - adapter.setValue("myString", new StringFieldValue("my;test;values")); - var statement = - newStatement(new InputExpression("myString"), - new LowerCaseExpression(), - new SplitExpression(";"), - new ForEachExpression(new StatementExpression(new SubstringExpression(0, 1))), - new AttributeExpression("myArray")); - statement.verify(adapter); - statement.execute(adapter); - assertEquals("[m, t, v]", adapter.values.get("myArray").toString()); - } - private static ScriptExpression newScript(StatementExpression... args) { return new ScriptExpression(args); } 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 963a84b6990b..23392c001102 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 @@ -73,7 +73,7 @@ public void requireThatSelectedExpressionIsRun() { } private static void assertVerify(FieldTypeAdapter adapter, DataType value, Expression exp) { - assertEquals(value, exp.verify(new VerificationContext(adapter).setCurrentType(value))); + assertEquals(value, exp.verify(new VerificationContext(adapter).setValueType(value))); } private static void assertVerifyThrows(FieldTypeAdapter adapter, Expression exp, String expectedException) { @@ -98,7 +98,7 @@ private static void assertSelect(List inputField, List available ExecutionContext ctx = new ExecutionContext(adapter); for (String fieldName : availableFields) { adapter.createField(new Field(fieldName, DataType.STRING)); - ctx.setFieldValue(fieldName, new StringFieldValue(fieldName), null); + ctx.setOutputValue(null, fieldName, new StringFieldValue(fieldName)); } List> cases = new LinkedList<>(); for (String fieldName : inputField) { 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 fae3b0c25d4e..2efa67c54a44 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 @@ -36,7 +36,7 @@ public void requireThatExpressionCanBeVerified() { @Test public void testsettingEnglish() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("en")); + ctx.setValue(new StringFieldValue("en")); new SetLanguageExpression().execute(ctx); assertEquals(Language.ENGLISH, ctx.getLanguage()); } @@ -44,7 +44,7 @@ public void testsettingEnglish() { @Test public void testSettingUnknown() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("unknown")); + ctx.setValue(new StringFieldValue("unknown")); new SetLanguageExpression().execute(ctx); assertEquals(Language.UNKNOWN, ctx.getLanguage()); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetValueTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetValueTestCase.java index 7ef79efa62cf..b7a9e795888f 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetValueTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetValueTestCase.java @@ -55,7 +55,7 @@ public void requireThatNullValueThrowsException() { public void requireThatValueIsSet() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); new ConstantExpression(new StringFieldValue("69")).execute(ctx); - assertEquals(new StringFieldValue("69"), ctx.getCurrentValue()); + assertEquals(new StringFieldValue("69"), ctx.getValue()); } @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 4364865ba24e..28c9ba65dad3 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarTestCase.java @@ -39,7 +39,7 @@ public void requireThatExpressionCanBeVerified() { assertVerifyThrows(null, exp, "Expected any input, but no input is specified"); try { - new VerificationContext().setVariable("foo", DataType.INT).setCurrentType(DataType.STRING).verify(exp); + new VerificationContext().setVariable("foo", DataType.INT).setValueType(DataType.STRING).execute(exp); fail(); } catch (VerificationException e) { assertEquals("Attempting to assign conflicting types to variable 'foo', int vs string", e.getMessage()); @@ -49,7 +49,7 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatSymbolIsWritten() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new IntegerFieldValue(69)); + ctx.setValue(new IntegerFieldValue(69)); new SetVarExpression("out").execute(ctx); FieldValue val = ctx.getVariable("out"); @@ -60,11 +60,11 @@ public void requireThatSymbolIsWritten() { @Test public void requireThatVariableTypeCanNotChange() { VerificationContext ctx = new VerificationContext(new SimpleTestAdapter()); - ctx.setCurrentType(DataType.INT); + ctx.setValueType(DataType.INT); new SetVarExpression("out").verify(ctx); try { - ctx.setCurrentType(DataType.STRING); + ctx.setValueType(DataType.STRING); new SetVarExpression("out").verify(ctx); fail(); } catch (VerificationException e) { diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java index e505b4e51931..db9aa1898f53 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SimpleExpression.java @@ -42,14 +42,14 @@ public SimpleExpression setCreatedOutput(DataType createdOutput) { @Override protected void doExecute(ExecutionContext context) { if (hasExecuteValue) { - context.setCurrentValue(executeValue); + context.setValue(executeValue); } } @Override protected void doVerify(VerificationContext context) { if (hasVerifyValue) { - context.setCurrentType(verifyValue); + context.setValueType(verifyValue); } } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SplitTestCase.java index e7df02f9be25..76bafec93890 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 @@ -44,10 +44,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsSplit() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("6;9")); + ctx.setValue(new StringFieldValue("6;9")); new SplitExpression(";").execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val.getDataType().equals(DataType.getArray(DataType.STRING))); assertTrue(val instanceof Array); @@ -61,16 +61,16 @@ public void requireThatNullInputProducesNullOutput() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); new SplitExpression(";").execute(ctx); - assertNull(ctx.getCurrentValue()); + assertNull(ctx.getValue()); } @Test public void requireThatEmptyInputProducesEmptyArray() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("")); + ctx.setValue(new StringFieldValue("")); new SplitExpression(";").execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val.getDataType().equals(DataType.getArray(DataType.STRING))); assertTrue(val instanceof Array); assertEquals(0, ((Array)val).size()); 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 f134191c4a3d..3612e3bd9fca 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 @@ -108,7 +108,7 @@ public void requireThatStatementIsExecuted() { StatementExpression statement = newStatement(new ConstantExpression(new IntegerFieldValue(69))); newStatement(statement).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof IntegerFieldValue); assertEquals(69, ((IntegerFieldValue)val).getInteger()); } 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 f05e3117ba70..aeb1947e97ca 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 @@ -67,10 +67,10 @@ private static void assertIndexOutOfBounds(int from, int to) { @Test public void requireThatStringIsSliced() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("666999")); + ctx.setValue(new StringFieldValue("666999")); new SubstringExpression(2, 4).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("69", ((StringFieldValue)val).getString()); } 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 dddc8762b553..376677b6f57a 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 @@ -126,6 +126,6 @@ public void requireThatDefaultExpressionIsExecuted() { } private static void assertEvaluate(FieldValue input, Expression exp, FieldValue expectedOutVar) { - assertEquals(expectedOutVar, new ExecutionContext().setCurrentValue(input).execute(exp).getVariable("out")); + assertEquals(expectedOutVar, new ExecutionContext().setValue(input).execute(exp).getVariable("out")); } } 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 21c399b8c0cf..a04dfc82a595 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 @@ -35,9 +35,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsPreserved() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("69")); + ctx.setValue(new StringFieldValue("69")); new ThisExpression().execute(ctx); - assertEquals(new StringFieldValue("69"), ctx.getCurrentValue()); + assertEquals(new StringFieldValue("69"), ctx.getValue()); } } 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 d1ac4152ee36..6f024e3547d5 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 @@ -39,9 +39,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("69")).execute(new ToArrayExpression()); + ctx.setValue(new StringFieldValue("69")).execute(new ToArrayExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertEquals(Array.class, val.getClass()); Array arr = (Array)val; 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 6ac0a27c11be..1452dc447b2a 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 @@ -5,6 +5,7 @@ import com.yahoo.document.datatypes.BoolFieldValue; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; +import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test; @@ -39,8 +40,8 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatNonEmptyStringBecomesTrue() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); - context.setCurrentValue(new StringFieldValue("false")).execute(new ToBoolExpression()); - FieldValue value = context.getCurrentValue(); + context.setValue(new StringFieldValue("false")).execute(new ToBoolExpression()); + FieldValue value = context.getValue(); assertTrue(value instanceof BoolFieldValue); assertTrue(((BoolFieldValue)value).getBoolean()); } @@ -48,8 +49,8 @@ public void requireThatNonEmptyStringBecomesTrue() { @Test public void requireThatEmptyStringBecomesFalse() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); - context.setCurrentValue(new StringFieldValue("")).execute(new ToBoolExpression()); - FieldValue value = context.getCurrentValue(); + context.setValue(new StringFieldValue("")).execute(new ToBoolExpression()); + FieldValue value = context.getValue(); assertTrue(value instanceof BoolFieldValue); assertFalse(((BoolFieldValue)value).getBoolean()); } @@ -57,8 +58,8 @@ public void requireThatEmptyStringBecomesFalse() { @Test public void requireThatNonZeroBecomesTrue() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); - context.setCurrentValue(new IntegerFieldValue(37)).execute(new ToBoolExpression()); - FieldValue value = context.getCurrentValue(); + context.setValue(new IntegerFieldValue(37)).execute(new ToBoolExpression()); + FieldValue value = context.getValue(); assertTrue(value instanceof BoolFieldValue); assertTrue(((BoolFieldValue)value).getBoolean()); } @@ -66,8 +67,8 @@ public void requireThatNonZeroBecomesTrue() { @Test public void requireThatZeroBecomesFalse() { ExecutionContext context = new ExecutionContext(new SimpleTestAdapter()); - context.setCurrentValue(new IntegerFieldValue(0)).execute(new ToBoolExpression()); - FieldValue value = context.getCurrentValue(); + context.setValue(new IntegerFieldValue(0)).execute(new ToBoolExpression()); + FieldValue value = context.getValue(); assertTrue(value instanceof BoolFieldValue); assertFalse(((BoolFieldValue)value).getBoolean()); } 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 43f53c45e09c..f536c37d12e3 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 @@ -36,9 +36,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("69")).execute(new ToByteExpression()); + ctx.setValue(new StringFieldValue("69")).execute(new ToByteExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof ByteFieldValue); assertEquals(69, ((ByteFieldValue)val).getByte()); } 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 60d3f83c77a1..3a3576f8524a 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 @@ -36,9 +36,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("6.9")).execute(new ToDoubleExpression()); + ctx.setValue(new StringFieldValue("6.9")).execute(new ToDoubleExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof DoubleFieldValue); assertEquals(6.9, ((DoubleFieldValue)val).getDouble(), 1e-6); } 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 0a98ef845996..f07f9304ba95 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 @@ -34,8 +34,8 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConvertedWithMs() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("2023-12-24T17:00:43.000Z")).execute(new ToEpochSecondExpression()); - FieldValue val = ctx.getCurrentValue(); + ctx.setValue(new StringFieldValue("2023-12-24T17:00:43.000Z")).execute(new ToEpochSecondExpression()); + FieldValue val = ctx.getValue(); assertTrue(val instanceof LongFieldValue); assertEquals(1703437243L, ((LongFieldValue)val).getLong()); } @@ -43,8 +43,8 @@ public void requireThatValueIsConvertedWithMs() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("2023-12-24T17:00:43Z")).execute(new ToEpochSecondExpression()); - FieldValue val = ctx.getCurrentValue(); + ctx.setValue(new StringFieldValue("2023-12-24T17:00:43Z")).execute(new ToEpochSecondExpression()); + FieldValue val = ctx.getValue(); assertTrue(val instanceof LongFieldValue); assertEquals(1703437243L, ((LongFieldValue)val).getLong()); } 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 32677aea11f5..bba48158e928 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 @@ -36,9 +36,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("6.9f")).execute(new ToFloatExpression()); + ctx.setValue(new StringFieldValue("6.9f")).execute(new ToFloatExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof FloatFieldValue); assertEquals(6.9f, ((FloatFieldValue)val).getFloat(), 1e-6); } 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 6812848e0100..d7f3f9093630 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 @@ -36,9 +36,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("69")).execute(new ToIntegerExpression()); + ctx.setValue(new StringFieldValue("69")).execute(new ToIntegerExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof IntegerFieldValue); assertEquals(69, ((IntegerFieldValue)val).getInteger()); } 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 d88d1c6691d7..03de90e70dc0 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 @@ -36,9 +36,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("69")).execute(new ToLongExpression()); + ctx.setValue(new StringFieldValue("69")).execute(new ToLongExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof LongFieldValue); assertEquals(69L, ((LongFieldValue)val).getLong()); } 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 bd7fe2fe78bc..03cb6aa37c49 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 @@ -38,9 +38,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatPositionIsParsed() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("6;9")).execute(new ToPositionExpression()); + ctx.setValue(new StringFieldValue("6;9")).execute(new ToPositionExpression()); - FieldValue out = ctx.getCurrentValue(); + FieldValue out = ctx.getValue(); assertTrue(out instanceof StructuredFieldValue); assertEquals(PositionDataType.INSTANCE, out.getDataType()); 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 70ef2302e099..5e410d079f67 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 @@ -36,9 +36,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsConverted() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new IntegerFieldValue(69)).execute(new ToStringExpression()); + ctx.setValue(new IntegerFieldValue(69)).execute(new ToStringExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("69", ((StringFieldValue)val).getString()); } 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 0c86fc462209..7df0667cc2db 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 @@ -65,9 +65,9 @@ private static void assertVerify(boolean createIfNonExistent, boolean removeIfZe private static void assertConvert(boolean createIfNonExistent, boolean removeIfZero) { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("69")).execute(new ToWsetExpression(createIfNonExistent, removeIfZero)); + ctx.setValue(new StringFieldValue("69")).execute(new ToWsetExpression(createIfNonExistent, removeIfZero)); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertEquals(WeightedSet.class, val.getClass()); WeightedSet wset = (WeightedSet)val; 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 9c0b17dd1220..7ed3ab410a32 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 @@ -55,10 +55,10 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatValueIsAnnotated() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("foo")); + ctx.setValue(new StringFieldValue("foo")); new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertNotNull(((StringFieldValue)val).getSpanTree(SpanTrees.LINGUISTICS)); } @@ -66,10 +66,10 @@ public void requireThatValueIsAnnotated() { @Test public void requireThatLongWordIsDropped() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue("foo")); + ctx.setValue(new StringFieldValue("foo")); new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig().setMaxTokenLength(2)).execute(ctx); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertNull(((StringFieldValue)val).getSpanTree(SpanTrees.LINGUISTICS)); } 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 c2f9d4b126f4..8584bae87084 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 @@ -35,9 +35,9 @@ public void requireThatExpressionCanBeVerified() { @Test public void requireThatStringIsTrimmed() { ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter()); - ctx.setCurrentValue(new StringFieldValue(" 69 ")).execute(new TrimExpression()); + ctx.setValue(new StringFieldValue(" 69 ")).execute(new TrimExpression()); - FieldValue val = ctx.getCurrentValue(); + FieldValue val = ctx.getValue(); assertTrue(val instanceof StringFieldValue); assertEquals("69", ((StringFieldValue)val).getString()); } diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java index a24ba1343bc0..98d74dc2a6a4 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/VerificationContextTestCase.java @@ -16,8 +16,8 @@ public class VerificationContextTestCase { public void requireThatValueCanBeSet() { VerificationContext ctx = new VerificationContext(); DataType val = DataType.STRING; - ctx.setCurrentType(val); - assertSame(val, ctx.getCurrentType()); + ctx.setValueType(val); + assertSame(val, ctx.getValueType()); } @Test @@ -31,9 +31,9 @@ public void requireThatVariablesCanBeSet() { @Test public void requireThatClearRemovesValue() { VerificationContext ctx = new VerificationContext(); - ctx.setCurrentType(DataType.STRING); + ctx.setValueType(DataType.STRING); ctx.clear(); - assertNull(ctx.getCurrentType()); + assertNull(ctx.getValueType()); } @Test diff --git a/integration/schema-language-server/language-server/src/main/ccc/indexinglanguage/IndexingParser.ccc b/integration/schema-language-server/language-server/src/main/ccc/indexinglanguage/IndexingParser.ccc index 9237ff5cd143..a398b9d9199f 100644 --- a/integration/schema-language-server/language-server/src/main/ccc/indexinglanguage/IndexingParser.ccc +++ b/integration/schema-language-server/language-server/src/main/ccc/indexinglanguage/IndexingParser.ccc @@ -205,7 +205,6 @@ TOKEN : | | | - | | | | @@ -356,7 +355,6 @@ Expression value() : val = normalizeExp() | val = nowExp() | val = optimizePredicateExp() | - val = packBitsExp() | val = passthroughExp() | val = randomExp() | val = script() | @@ -614,12 +612,6 @@ Expression optimizePredicateExp() : { } { return new OptimizePredicateExpression(); } ; -Expression packBitsExp() : { } - - ( ) - { return new PackBitsExpression(); } -; - Expression passthroughExp() : { String val = defaultFieldName; diff --git a/vespajlib/abi-spec.json b/vespajlib/abi-spec.json index b5308884f40d..e400a336ad00 100644 --- a/vespajlib/abi-spec.json +++ b/vespajlib/abi-spec.json @@ -1390,7 +1390,6 @@ "public abstract java.util.Optional size()", "public abstract com.yahoo.tensor.TensorType$Dimension$Type type()", "public abstract com.yahoo.tensor.TensorType$Dimension withName(java.lang.String)", - "public com.yahoo.tensor.TensorType$Dimension withSize(long)", "public boolean isIndexed()", "public boolean isMapped()", "public abstract java.lang.String toString()", @@ -1532,8 +1531,7 @@ ], "methods" : [ "public void ()", - "public static varargs com.yahoo.tensor.Tensor toSparse(com.yahoo.tensor.Tensor, java.lang.String[])", - "public static com.yahoo.tensor.Tensor packBits(com.yahoo.tensor.Tensor)" + "public static varargs com.yahoo.tensor.Tensor toSparse(com.yahoo.tensor.Tensor, java.lang.String[])" ], "fields" : [ ] }, diff --git a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java index 5b800aa58eeb..fc0473c635a4 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java @@ -97,7 +97,6 @@ public double get(DirectIndexedAddress address) { return get(address.getDirectIndex()); } public DirectIndexedAddress directAddress() { return DirectIndexedAddress.of(dimensionSizes); } - /** * Returns the value at the given indexes as a float * diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java index 386f24bfe623..65c6677e7e36 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java @@ -344,7 +344,7 @@ public Tensor.Builder block(TensorAddress sparsePart, double[] values) { @Override public MixedTensor build() { - // TODO: This can be solved more efficiently with a single map. + //TODO This can be solved more efficiently with a single map. Set> entrySet = denseSubspaceMap.entrySet(); for (Map.Entry entry : entrySet) { TensorAddress sparsePart = entry.getKey(); @@ -356,7 +356,7 @@ public MixedTensor build() { } public static BoundBuilder of(TensorType type) { - // TODO: Wire in expected map size to avoid expensive resize + //TODO Wire in expected map size to avoid expensive resize return new BoundBuilder(type, INITIAL_HASH_CAPACITY); } } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java index 15c20e1a883f..d225d6f46412 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java @@ -96,7 +96,7 @@ default int sizeAsInt() { /** * Returns the cell of this in some undefined order. - * A cell instance is only valid until next() is called. + * A cell instances is only valid until next() is called. * Call detach() on the cell to obtain a long-lived instance. */ Iterator cellIterator(); diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java index c96a8decd161..0421f6a6a9da 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorAddress.java @@ -111,15 +111,15 @@ public TensorAddress partialCopy(int[] indexMap) { return TensorAddressAny.ofUnsafe(labels); } - /** Creates a complete address by taking the mapped dimensions of this and adding the indexed from the indexedPart */ - public TensorAddress fullAddressOf(List dimensions, int[] indexedPart) { + /** Creates a complete address by taking the mapped dimmensions from this and the indexed from the indexedPart */ + public TensorAddress fullAddressOf(List dimensions, int[] densePart) { long[] labels = new long[dimensions.size()]; int mappedIndex = 0; int indexedIndex = 0; for (int i = 0; i < labels.length; i++) { TensorType.Dimension d = dimensions.get(i); if (d.isIndexed()) { - labels[i] = indexedPart[indexedIndex]; + labels[i] = densePart[indexedIndex]; indexedIndex++; } else { labels[i] = numericLabel(mappedIndex); diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java index 37b8d8d60018..a90dab6d185e 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorType.java @@ -373,11 +373,6 @@ private Dimension(String name) { /** Returns a copy of this with the name set to the given name */ public abstract Dimension withName(String name); - /** Returns a copy of this with the size set to the given value */ - public Dimension withSize(long size) { - return IndexedBoundDimension.indexed(name, size); - } - /** Returns true if this is an indexed bound or unbound type */ public boolean isIndexed() { return type() == Type.indexedBound || type() == Type.indexedUnbound; } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/Tensors.java b/vespajlib/src/main/java/com/yahoo/tensor/Tensors.java index 34743e4d0655..92cba5b9bd37 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/Tensors.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/Tensors.java @@ -46,60 +46,4 @@ public static Tensor toSparse(Tensor tensor, String ... dimensions) { return builder.build(); } - /** - * Converts any tensor containing only ones and zeroes into one where each consecutive 8 values in the - * dense dimension are packed into a single byte. As a consequence the output type of this is a tensor - * where the dense dimension is 1/8th as large. - * - * @throws IllegalArgumentException if the tensor has the wrong type or contains any other value than 0 or 1 - */ - public static Tensor packBits(Tensor tensor) { - if (tensor.type().indexedSubtype().dimensions().size() != 1) - throw new IllegalArgumentException("packBits requires a tensor with one dense dimensions, but got " + tensor.type()); - - // Create the packed type - var typeBuilder = new TensorType.Builder(TensorType.Value.INT8); - for (var d : tensor.type().dimensions()) - typeBuilder.dimension(d.size().isPresent() ? d.withSize((int) Math.ceil(d.size().get() / 8.0)) : d); - var packedType = typeBuilder.build(); - - // Pack it - Tensor.Builder builder = Tensor.Builder.of(packedType); - if (tensor instanceof IndexedTensor indexed) { - for (long i = 0; i < indexed.size(); ) { - long packedIndex = i / 8; - int packedValue = 0; - for (int j = 0; j < 8 && i < indexed.size(); j++) - packedValue = packInto(packedValue, indexed.get(i), j, i++); - builder.cell(packedValue, packedIndex); - } - } - else if (tensor instanceof MixedTensor mixed) { - for (var denseSubspace : mixed.getInternalDenseSubspaces()) { - for (int i = 0; i < denseSubspace.cells.length; ) { - var packedAddress = denseSubspace.sparseAddress.fullAddressOf(mixed.type().dimensions(), new int[]{i / 8}); - int packedValue = 0; - for (int j = 0; j < 8 && i < denseSubspace.cells.length; j++) - packedValue = packInto(packedValue, denseSubspace.cells[i], j, i++); - builder.cell(packedAddress, packedValue); - } - } - } - else { - throw new IllegalArgumentException("The argument is neither of type IndexedTensor or MixedTensor, but " + - tensor.getClass()); - } - return builder.build(); - } - - private static int packInto(int packedValue, double value, int bitPosition, long sourcePosition) { - if (value == 0.0) - return packedValue; - else if (value == 1.0) - return packedValue | ( 1 << ( 7 - bitPosition )); - else - throw new IllegalArgumentException("The tensor to be packed can only contain 0 or 1 values, " + - "but has " + value + " at position " + sourcePosition); - } - } diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorsTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorsTestCase.java index 6d146ca9c9fa..84d337deeb70 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorsTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorsTestCase.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; /** * @author bratseth @@ -25,43 +24,9 @@ void testToSparse() { } } - @Test - void testPackBits() { - assertPacked("tensor(x[2]):[129,14]", "tensor(x[16]):[1,0,0,0,0,0,0,1, 0,0,0,0,1,1,1,0]"); - assertPacked("tensor(x[2]):[129,14]", "tensor(x[15]):[1,0,0,0,0,0,0,1, 0,0,0,0,1,1,1]"); - assertPacked("tensor(x[1]):[128]", "tensor(x[1]):[1]"); - assertPacked("tensor(key{},x[2]):{a:[129,14], b:[12, 7]}", - "tensor(key{},x[16]):{a:[1,0,0,0,0,0,0,1, 0,0,0,0,1,1,1,0]," + - " b:[0,0,0,0,1,1,0,0, 0,0,0,0,0,1,1,1]}"); - assertPacked("tensor(key{},x[1]):{a:[160],b:[32]}", - "tensor(key{},x[3]):{a:[1,0,1],b:[0,0,1]}"); - assertPacked("tensor(key{},x[1]):{a:[128]}", "tensor(key{}, x[1]):{a:[1]}"); - - try { - Tensors.packBits(Tensor.from("tensor(x[1],y[1]):[1]")); - fail("Expected exception"); - } - catch (IllegalArgumentException e) { - assertEquals("packBits requires a tensor with one dense dimensions, but got tensor(x[1],y[1])", - e.getMessage()); - } - try { - Tensors.packBits(Tensor.from("tensor(x[3]):[0, 1, 2]")); - fail("Expected exception"); - } - catch (IllegalArgumentException e) { - assertEquals("The tensor to be packed can only contain 0 or 1 values, but has 2.0 at position 2", - e.getMessage()); - } - } - void assertConvertedToSparse(String inputType, String outputType, String tensorValue, String ... dimensions) { var tensor = Tensor.from(inputType + ":" + tensorValue); assertEquals(outputType + ":" + tensorValue, Tensors.toSparse(tensor, dimensions).toString(true, false)); } - void assertPacked(String expected, String input) { - assertEquals(Tensor.from(expected), Tensors.packBits(Tensor.from(input))); - } - }