Search in sources :

Example 6 with DataType

use of com.yahoo.document.DataType in project vespa by vespa-engine.

the class VerificationContextTestCase method requireThatVariablesCanBeSet.

@Test
public void requireThatVariablesCanBeSet() {
    VerificationContext ctx = new VerificationContext();
    DataType val = DataType.STRING;
    ctx.setVariable("foo", val);
    assertSame(val, ctx.getVariable("foo"));
}
Also used : DataType(com.yahoo.document.DataType) Test(org.junit.Test)

Example 7 with DataType

use of com.yahoo.document.DataType in project vespa by vespa-engine.

the class VerificationContextTestCase method requireThatValueCanBeSet.

@Test
public void requireThatValueCanBeSet() {
    VerificationContext ctx = new VerificationContext();
    DataType val = DataType.STRING;
    ctx.setValue(val);
    assertSame(val, ctx.getValue());
}
Also used : DataType(com.yahoo.document.DataType) Test(org.junit.Test)

Example 8 with DataType

use of com.yahoo.document.DataType in project vespa by vespa-engine.

the class Expression method verify.

public final DataType verify(VerificationContext context) {
    DataType inputType = requiredInputType();
    if (inputType != null) {
        DataType input = context.getValue();
        if (input == null) {
            throw new VerificationException(this, "Expected " + inputType.getName() + " input, got null.");
        }
        if (input.getPrimitiveType() == UnresolvedDataType.INSTANCE) {
            throw new VerificationException(this, "Failed to resolve input type.");
        }
        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.getValue();
        if (output == null) {
            throw new VerificationException(this, "Expected " + outputType.getName() + " output, got null.");
        }
        if (output.getPrimitiveType() == UnresolvedDataType.INSTANCE) {
            throw new VerificationException(this, "Failed to resolve output type.");
        }
        if (!outputType.isAssignableFrom(output)) {
            throw new VerificationException(this, "Expected " + outputType.getName() + " output, got " + output.getName() + ".");
        }
    }
    return context.getValue();
}
Also used : DataType(com.yahoo.document.DataType)

Example 9 with DataType

use of com.yahoo.document.DataType in project vespa by vespa-engine.

the class Expression method execute.

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();
}
Also used : DataType(com.yahoo.document.DataType) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 10 with DataType

use of com.yahoo.document.DataType in project vespa by vespa-engine.

the class ArithmeticExpression method doVerify.

@Override
protected void doVerify(VerificationContext context) {
    DataType input = context.getValue();
    context.setValue(evaluate(context.setValue(input).execute(lhs).getValue(), context.setValue(input).execute(rhs).getValue()));
}
Also used : NumericDataType(com.yahoo.document.NumericDataType) DataType(com.yahoo.document.DataType)

Aggregations

DataType (com.yahoo.document.DataType)62 ArrayDataType (com.yahoo.document.ArrayDataType)20 MapDataType (com.yahoo.document.MapDataType)19 Field (com.yahoo.document.Field)17 StructDataType (com.yahoo.document.StructDataType)17 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)17 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 PositionDataType (com.yahoo.document.PositionDataType)12 CollectionDataType (com.yahoo.document.CollectionDataType)11 FieldValue (com.yahoo.document.datatypes.FieldValue)11 TensorDataType (com.yahoo.document.TensorDataType)10 DocumentType (com.yahoo.document.DocumentType)9 StructuredDataType (com.yahoo.document.StructuredDataType)7 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)6 SDField (com.yahoo.searchdefinition.document.SDField)6 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)5 TemporaryStructuredDataType (com.yahoo.document.TemporaryStructuredDataType)4 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4