Search in sources :

Example 91 with Field

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

Example 92 with Field

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"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LinkedList(java.util.LinkedList) Pair(com.yahoo.collections.Pair)

Example 93 with Field

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.");
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) Test(org.junit.Test)

Example 94 with Field

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());
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Test(org.junit.Test)

Example 95 with Field

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"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Aggregations

Field (com.yahoo.document.Field)115 Test (org.junit.Test)50 StructDataType (com.yahoo.document.StructDataType)46 DocumentType (com.yahoo.document.DocumentType)24 DataType (com.yahoo.document.DataType)17 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 ArrayDataType (com.yahoo.document.ArrayDataType)12 MapDataType (com.yahoo.document.MapDataType)12 TensorDataType (com.yahoo.document.TensorDataType)11 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)11 SDField (com.yahoo.searchdefinition.document.SDField)10 PositionDataType (com.yahoo.document.PositionDataType)9 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)9 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Struct (com.yahoo.document.datatypes.Struct)7 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)6 Document (com.yahoo.document.Document)5