Search in sources :

Example 21 with Field

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

the class ScriptTestCase method requireThatInputValueIsAvailableToAllStatements.

@Test
public void requireThatInputValueIsAvailableToAllStatements() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out-1", DataType.INT), new Field("out-2", DataType.INT));
    newStatement(new SetValueExpression(new IntegerFieldValue(69)), newScript(newStatement(new AttributeExpression("out-1"), new AttributeExpression("out-2")))).execute(adapter);
    assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out-1"));
    assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out-2"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 22 with Field

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

the class ScriptTestCase method requireThatVariablesAreAvailableOutsideScript.

@Test
public void requireThatVariablesAreAvailableOutsideScript() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newStatement(newScript(newStatement(new SetValueExpression(new IntegerFieldValue(69)), new SetVarExpression("tmp"))), new GetVarExpression("tmp"), new AttributeExpression("out")).execute(adapter);
    assertEquals(new IntegerFieldValue(69), 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)

Example 23 with Field

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

the class FieldSetRepo method parseFieldCollection.

FieldSet parseFieldCollection(DocumentTypeManager docMan, String docType, String fieldNames) {
    DocumentType type = docMan.getDocumentType(docType);
    if (type == null) {
        throw new IllegalArgumentException("Unknown document type " + docType);
    }
    StringTokenizer tokenizer = new StringTokenizer(fieldNames, ",");
    FieldCollection collection = new FieldCollection(type);
    for (; tokenizer.hasMoreTokens(); ) {
        String token = tokenizer.nextToken();
        Field f = type.getField(token);
        if (f == null) {
            throw new IllegalArgumentException("No such field " + token);
        }
        collection.add(f);
    }
    return collection;
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) String(java.lang.String)

Example 24 with Field

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

the class FieldValueConverterTestCase method requireThatStructElementsAreConverted.

@Test
public void requireThatStructElementsAreConverted() {
    StructDataType type = new StructDataType("foo");
    type.addField(new Field("bar", DataType.STRING));
    type.addField(new Field("baz", DataType.STRING));
    Struct before = type.createFieldValue();
    before.setFieldValue("bar", new StringFieldValue("6"));
    before.setFieldValue("baz", new StringFieldValue("9"));
    FieldValue after = new StringMarker().convert(before);
    assertTrue(after instanceof Struct);
    assertEquals(new StringFieldValue("6'"), ((Struct) after).getFieldValue("bar"));
    assertEquals(new StringFieldValue("9'"), ((Struct) after).getFieldValue("baz"));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 25 with Field

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

the class FieldValueConverterTestCase method requireThatStructArrayElementsAreConverted.

@Test
public void requireThatStructArrayElementsAreConverted() {
    StructDataType type = new StructDataType("foo");
    type.addField(new Field("bar", DataType.STRING));
    type.addField(new Field("baz", DataType.STRING));
    Array<Struct> before = new Array<>(DataType.getArray(type));
    Struct elem = type.createFieldValue();
    elem.setFieldValue("bar", new StringFieldValue("6"));
    elem.setFieldValue("baz", new StringFieldValue("9"));
    before.add(elem);
    elem = type.createFieldValue();
    elem.setFieldValue("bar", new StringFieldValue("9"));
    elem.setFieldValue("baz", new StringFieldValue("6"));
    before.add(elem);
    FieldValue after = new StringMarker().convert(before);
    assertTrue(after instanceof Array);
    FieldValue val = ((Array) after).getFieldValue(0);
    assertTrue(val instanceof Struct);
    assertEquals(new StringFieldValue("6'"), ((Struct) val).getFieldValue("bar"));
    assertEquals(new StringFieldValue("9'"), ((Struct) val).getFieldValue("baz"));
    val = ((Array) after).getFieldValue(1);
    assertTrue(val instanceof Struct);
    assertEquals(new StringFieldValue("9'"), ((Struct) val).getFieldValue("bar"));
    assertEquals(new StringFieldValue("6'"), ((Struct) val).getFieldValue("baz"));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) 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