use of com.yahoo.document.Field in project vespa by vespa-engine.
the class SimpleDocumentAdapter method setOutputValue.
@SuppressWarnings({ "unchecked" })
@Override
public SimpleDocumentAdapter setOutputValue(Expression exp, String fieldName, FieldValue fieldValue) {
Field field = output.getField(fieldName);
if (field == null) {
throw new IllegalArgumentException("Field '" + fieldName + "' not found in document type '" + output.getDataType().getName() + "'.");
}
output.setFieldValue(field, fieldValue);
return this;
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class SelectInputTestCase method assertSelect.
private static void assertSelect(List<String> inputField, List<String> availableFields, String expected) {
SimpleTestAdapter adapter = new SimpleTestAdapter();
ExecutionContext ctx = new ExecutionContext(adapter);
for (String fieldName : availableFields) {
adapter.createField(new Field(fieldName, DataType.STRING));
ctx.setOutputValue(null, fieldName, new StringFieldValue(fieldName));
}
List<Pair<String, Expression>> cases = new LinkedList<>();
for (String fieldName : inputField) {
cases.add(new Pair<String, Expression>(fieldName, new SetVarExpression("out")));
}
new SelectInputExpression(cases).execute(ctx);
assertEquals(expected != null ? new StringFieldValue(expected) : null, ctx.getVariable("out"));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class SelectInputTestCase method requireThatExpressionCanBeVerified.
@Test
public void requireThatExpressionCanBeVerified() {
SimpleTestAdapter adapter = new SimpleTestAdapter();
adapter.createField(new Field("my_int", DataType.INT));
adapter.createField(new Field("my_str", DataType.STRING));
Expression exp = newSelectInput(new AttributeExpression("my_int"), "my_int");
assertVerify(adapter, null, exp);
assertVerify(adapter, DataType.INT, exp);
assertVerify(adapter, DataType.STRING, exp);
assertVerifyThrows(adapter, newSelectInput(new AttributeExpression("my_int"), "my_str"), "Can not assign string to field 'my_int' which is int.");
assertVerifyThrows(adapter, newSelectInput(new AttributeExpression("my_int"), "my_unknown"), "Field 'my_unknown' not found.");
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ParenthesisTestCase method requireThatNestedExpressionIsRun.
@Test
public void requireThatNestedExpressionIsRun() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field("in", DataType.STRING)));
ctx.setOutputValue(null, "in", new StringFieldValue("69"));
new ParenthesisExpression(new InputExpression("in")).execute(ctx);
assertTrue(ctx.getValue() instanceof StringFieldValue);
assertEquals("69", ((StringFieldValue) ctx.getValue()).getString());
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class ScriptTestCase method requireThatVariablesReplaceOthersOutsideScript.
@Test
public void requireThatVariablesReplaceOthersOutsideScript() {
SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
newStatement(new SetValueExpression(new IntegerFieldValue(6)), new SetVarExpression("tmp"), newScript(newStatement(new SetValueExpression(new IntegerFieldValue(9)), new SetVarExpression("tmp"))), new GetVarExpression("tmp"), new AttributeExpression("out")).execute(adapter);
assertEquals(new IntegerFieldValue(9), adapter.getInputValue("out"));
}
Aggregations