Search in sources :

Example 96 with Field

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

the class ScriptTestCase method requireThatVariablesAreAvailableInScript.

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

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

the class ScriptTestCase method requireThatScriptEvaluatesToInputValue.

@Test
public void requireThatScriptEvaluatesToInputValue() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newStatement(new SetValueExpression(new IntegerFieldValue(6)), newScript(newStatement(new SetValueExpression(new IntegerFieldValue(9)))), new AttributeExpression("out")).execute(adapter);
    assertEquals(new IntegerFieldValue(6), 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 98 with Field

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

the class StructReader method fillStruct.

public static void fillStruct(TokenBuffer buffer, StructuredFieldValue parent) {
    // do note the order of initializing initNesting and token is relevant for empty docs
    int initNesting = buffer.nesting();
    buffer.next();
    while (buffer.nesting() >= initNesting) {
        Field f = getField(buffer, parent);
        try {
            FieldValue v = readSingleValue(buffer, f.getDataType());
            parent.setFieldValue(f, v);
            buffer.next();
        } catch (IllegalArgumentException e) {
            throw new JsonReaderException(f, e);
        }
    }
}
Also used : Field(com.yahoo.document.Field) JsonReaderException(com.yahoo.document.json.JsonReaderException) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 99 with Field

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

the class MapValueUpdate method checkCompatibility.

@Override
protected void checkCompatibility(DataType fieldType) {
    if (fieldType instanceof ArrayDataType) {
        if (!(value instanceof IntegerFieldValue)) {
            throw new IllegalArgumentException("Expected integer, got " + value.getClass().getName() + ".");
        }
        update.checkCompatibility(((ArrayDataType) fieldType).getNestedType());
    } else if (fieldType instanceof WeightedSetDataType) {
        ((WeightedSetDataType) fieldType).getNestedType().createFieldValue().assign(value);
        update.checkCompatibility(DataType.INT);
    } else if (fieldType instanceof StructuredDataType) {
        if (!(value instanceof StringFieldValue)) {
            throw new IllegalArgumentException("Expected string, got " + value.getClass().getName() + ".");
        }
        Field field = ((StructuredDataType) fieldType).getField(((StringFieldValue) value).getString());
        if (field == null) {
            throw new IllegalArgumentException("Field '" + value + "' not found.");
        }
        update.checkCompatibility(field.getDataType());
    } else {
        throw new UnsupportedOperationException("Field type " + fieldType.getName() + " not supported.");
    }
}
Also used : Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StructuredDataType(com.yahoo.document.StructuredDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 100 with Field

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

the class VespaDocumentDeserializer42 method read.

public void read(FieldUpdate fieldUpdate) {
    int fieldId = getInt(null);
    Field field = fieldUpdate.getDocumentType().getField(fieldId, fieldUpdate.getSerializationVersion());
    if (field == null) {
        throw new DeserializationException("Cannot deserialize FieldUpdate, field fieldId " + fieldId + " not found in " + fieldUpdate.getDocumentType());
    }
    fieldUpdate.setField(field);
    int size = getInt(null);
    for (int i = 0; i < size; i++) {
        if (field.getDataType() instanceof CollectionDataType) {
            CollectionDataType collType = (CollectionDataType) field.getDataType();
            fieldUpdate.addValueUpdate(getValueUpdate(collType, collType.getNestedType()));
        } else {
            fieldUpdate.addValueUpdate(getValueUpdate(field.getDataType(), null));
        }
    }
}
Also used : Field(com.yahoo.document.Field) CollectionDataType(com.yahoo.document.CollectionDataType)

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