Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Bratseth/indexing type inference 2" #32823

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<string> input type, but got " + type);
return getOutputType(context); // embed cannot determine the output type from the input
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down