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"));
}
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());
}
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();
}
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();
}
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()));
}
Aggregations