From 47db3e29de7b3a6d53a2d69568f5ca6e1324447e Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Sat, 9 Nov 2024 14:04:55 +0100 Subject: [PATCH] Revert "Bratseth/indexing type inference 2" --- .../expressions/AnyNumericDataType.java | 52 ------------------- .../expressions/ArithmeticExpression.java | 13 +++-- .../expressions/ConstantExpression.java | 7 +-- .../expressions/EmbedExpression.java | 8 +-- .../expressions/Expression.java | 14 ++--- .../expressions/SetVarExpression.java | 14 ++--- .../expressions/SplitExpression.java | 5 +- .../indexinglanguage/ScriptTestCase.java | 18 ------- .../expressions/StatementTestCase.java | 1 - 9 files changed, 29 insertions(+), 103 deletions(-) delete mode 100644 indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyNumericDataType.java diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyNumericDataType.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyNumericDataType.java deleted file mode 100644 index 8cfde6c79ab..00000000000 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/AnyNumericDataType.java +++ /dev/null @@ -1,52 +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.NumericDataType; -import com.yahoo.document.datatypes.DoubleFieldValue; -import com.yahoo.document.datatypes.FieldValue; - -/** - * A DataType representing any numeric type. This is (so far) only needed during type resolution of indexing pipelines - * so it is placed here. - * - * @author bratseth - */ -class AnyNumericDataType extends NumericDataType { - - static final AnyNumericDataType instance = new AnyNumericDataType(); - - private AnyNumericDataType() { - super("numeric", DataType.lastPredefinedDataTypeId() + 2, DoubleFieldValue.class, new UnsupportedFactory()); - } - - @Override - public boolean isAssignableFrom(DataType other) { - return other instanceof NumericDataType; - } - - @Override - public boolean isAssignableTo(DataType other) { - return other instanceof AnyNumericDataType || other instanceof AnyDataType; - } - - @Override - public boolean isValueCompatible(FieldValue value) { - return isAssignableFrom(value.getDataType()); - } - - @Override - public FieldValue createFieldValue() { throw new UnsupportedOperationException(); } - - private static class UnsupportedFactory extends Factory { - - public FieldValue create() { - throw new UnsupportedOperationException(); - } - - public FieldValue create(String value) { - throw new UnsupportedOperationException(); - } - - } -} 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 dd7ccd36093..d7bc6afff39 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 @@ -62,6 +62,7 @@ public ArithmeticExpression(Expression left, Operator op, Expression right) { @Override public ArithmeticExpression convertChildren(ExpressionConverter converter) { + // TODO: branch()? return new ArithmeticExpression(converter.convert(left), op, converter.convert(right)); } @@ -76,11 +77,9 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { super.setOutputType(outputType, context); - DataType leftInput = left.setOutputType(AnyNumericDataType.instance, context); - DataType rightInput = right.setOutputType(AnyNumericDataType.instance, context); - if (leftInput.isAssignableTo(rightInput)) - return rightInput; - else if (rightInput.isAssignableTo(leftInput)) + DataType leftInput = left.setOutputType(outputType, context); + DataType rightInput = right.setOutputType(outputType, context); + if (leftInput == rightInput) // TODO: Generalize return leftInput; else return getInputType(context); @@ -96,9 +95,9 @@ protected void doVerify(VerificationContext context) { private DataType resultingType(DataType left, DataType right) { if (left == null || right == null) return null; - if ( ! (left instanceof NumericDataType)) + if (!(left instanceof NumericDataType)) throw new VerificationException(this, "The first argument must be a number, but has type " + left.getName()); - if ( ! (right instanceof NumericDataType)) + if (!(right instanceof NumericDataType)) throw new VerificationException(this, "The second argument must be a number, but has type " + right.getName()); if (left == DataType.FLOAT || left == DataType.DOUBLE || right == DataType.FLOAT || right == DataType.DOUBLE) { 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 d7af8669b3a..6576648ea5f 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 @@ -31,9 +31,10 @@ public DataType setInputType(DataType inputType, VerificationContext context) { @Override public DataType setOutputType(DataType outputType, VerificationContext context) { - if ( ! value.getDataType().isAssignableTo(outputType)) - throw new VerificationException(this, "Produces type " + value.getDataType().getName() + ", but type " + - outputType.getName() + " is required"); + // TODO: + //if (outputType != value.getDataType()) + // throw new VerificationException(this, "Produces type " + value.getDataType() + ", but type " + + // outputType + " is required"); return super.setOutputType(outputType, context); } diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/EmbedExpression.java index 71e471b03a6..87e07444765 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 @@ -67,10 +67,10 @@ 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 VerificationException(this, "This requires either a string or array input type, but got " + - type.getName()); + // TODO: Activate type checking + // if ( ! (type == DataType.STRING) + // && ! (type instanceof ArrayDataType array && array.getNestedType() == DataType.STRING)) + // throw new VerificationException(this, "This requires either a string or array input type, but got " + type); return getOutputType(context); // embed cannot determine the output type from the input } 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 4b5d8875ac9..42c2a3c538e 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 @@ -64,8 +64,9 @@ public void setStatementOutput(DocumentType documentType, Field field) {} * @throws IllegalArgumentException if inputType isn't assignable to requiredType */ protected final DataType setInputType(DataType inputType, DataType requiredType, VerificationContext context) { - if ( ! (inputType.isAssignableTo(requiredType))) - throw new VerificationException(this, "This requires type " + requiredType.getName() + ", but gets " + inputType.getName()); + // TODO: Activate type checking + // if ( ! (inputType.isAssignableTo(requiredType)) + // throw new VerificationException(this, "This requires type " + requiredType.getName() + ", but gets " + inputType.getName()); return assignInputType(inputType); } @@ -118,10 +119,11 @@ public DataType requireOutputType() { */ protected final DataType setOutputType(DataType actualOutput, DataType requiredOutput, DataType requiredType, VerificationContext context) { - if (actualOutput != null && requiredOutput != null && ! actualOutput.isAssignableTo(requiredOutput)) - throw new VerificationException(this, "This produces type " + actualOutput.getName() + " but " + requiredOutput.getName() + " is required"); - if (requiredType != null && requiredOutput != null && ! requiredOutput.isAssignableTo(requiredType)) - throw new VerificationException(this, "This is required to produce type " + requiredOutput.getName() + " but is produces " + requiredType.getName());; + // TODO: Activate type checking + // if (actualOutput != null && requiredOutput != null && ! actualOutput.isAssignableTo(requiredOutput)) + // throw new VerificationException(this, "This produces type " + actualOutput.getName() + " but " + requiredOutput.getName() + " is required"); + // if (requiredType != null && requiredOutput != null && ! requiredOutputOutput.isAssignableTo(requiredType)) + // throw new VerificationException(this, "This is required to produce type " + requiredOutput.getName() + " but is produces " + requiredType.getName());; return assignOutputType(actualOutput != null ? actualOutput : requiredOutput); // Use the more precise type when known } 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 3169563818c..06342cbd03e 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 @@ -36,17 +36,11 @@ protected void doVerify(VerificationContext context) { private void setVariableType(DataType newType, VerificationContext context) { DataType existingType = context.getVariable(varName); - DataType mostGeneralType = newType; - if (existingType != null) { - if (existingType.isAssignableTo(newType)) - mostGeneralType = newType; - else if (newType.isAssignableTo(existingType)) - mostGeneralType = existingType; - else - throw new VerificationException(this, "Cannot set variable '" + varName + "' to type " + newType.getName() + - ": It is already set to type " + existingType.getName()); + if (existingType != null && ! newType.equals(existingType)) { + throw new VerificationException(this, "Cannot set variable '" + varName + "' to type " + newType.getName() + + ": It is already set to type " + existingType.getName()); } - context.setVariable(varName, mostGeneralType); + context.setVariable(varName, newType); } @Override diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SplitExpression.java index 3f2fe7d7b8e..7884e7632dd 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 @@ -32,8 +32,9 @@ public DataType setInputType(DataType input, VerificationContext context) { @Override public DataType setOutputType(DataType output, VerificationContext context) { super.setOutputType(output, context); - if ( ! (output instanceof ArrayDataType) && output.getNestedType() == DataType.STRING) - throw new VerificationException(this, "This produces a string array, but " + output.getName() + " is required"); + // TODO: Activate type checking + // if ( ! (output instanceof ArrayDataType) && output.getNestedType() == DataType.STRING) + // throw new VerificationException(this, "This produces a string array, but needs type " + output.getName()); return 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 c9b9e0c01fb..13d3f9d29ce 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ScriptTestCase.java @@ -8,7 +8,6 @@ import com.yahoo.document.Field; import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.BoolFieldValue; -import com.yahoo.document.datatypes.FloatFieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.LongFieldValue; import com.yahoo.document.datatypes.MapFieldValue; @@ -219,21 +218,4 @@ public void testForEachFollowedByGetVar() { assertEquals("value2", ((StringFieldValue)adapter.values.get("id")).getString()); } - @Test - public void testFloatAndIntArithmetic() { - var tester = new ScriptTester(); - var expression = tester.expressionFrom("input myFloat * 10 | attribute myFloat"); - - SimpleTestAdapter adapter = new SimpleTestAdapter(); - var myFloat = new Field("myFloat", DataType.FLOAT); - adapter.createField(myFloat); - adapter.setValue("myFloat", new FloatFieldValue(1.3f)); - - expression.verify(adapter); - - ExecutionContext context = new ExecutionContext(adapter); - expression.execute(context); - assertEquals(13.0f, ((FloatFieldValue)adapter.values.get("myFloat")).getFloat(), 0.000001); - } - } 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 8dea0126d56..351df9af3fc 100644 --- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java +++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/StatementTestCase.java @@ -4,7 +4,6 @@ import com.yahoo.document.DataType; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; -import com.yahoo.vespa.indexinglanguage.ScriptTester; import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter; import org.junit.Test;