Search in sources :

Example 1 with StructuredFieldValue

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

the class GetFieldExpression method doExecute.

@Override
protected void doExecute(ExecutionContext ctx) {
    FieldValue input = ctx.getValue();
    if (!(input instanceof StructuredFieldValue)) {
        throw new IllegalArgumentException("Expected structured input, got " + input.getDataType().getName() + ".");
    }
    StructuredFieldValue struct = (StructuredFieldValue) input;
    Field field = struct.getField(fieldName);
    if (field == null) {
        throw new IllegalArgumentException("Field '" + fieldName + "' not found.");
    }
    ctx.setValue(struct.getFieldValue(field));
}
Also used : StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) Field(com.yahoo.document.Field) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 2 with StructuredFieldValue

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

the class ExtendedField method setFieldValue.

public FieldValue setFieldValue(StructuredFieldValue doc, FieldValue fv) {
    FieldValue old = getFieldValue(doc);
    extract.set(doc, (fv == null) ? null : fv.getWrappedValue());
    return old;
}
Also used : StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 3 with StructuredFieldValue

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

the class ExtendedStringField method setFieldValue.

@Override
public FieldValue setFieldValue(StructuredFieldValue doc, FieldValue fv) {
    FieldValue old = getFieldValue(doc);
    StringFieldValue sfv = (StringFieldValue) fv;
    super.setFieldValue(doc, sfv);
    Map<String, SpanTree> trees = null;
    if (sfv != null) {
        trees = sfv.getSpanTreeMap();
        if (trees == null) {
            trees = new HashMap<>();
        }
    }
    extractSpanTrees.set(doc, trees);
    return old;
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 4 with StructuredFieldValue

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

the class ToPositionTestCase method requireThatPositionIsParsed.

@Test
public void requireThatPositionIsParsed() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("6;9")).execute(new ToPositionExpression());
    FieldValue out = ctx.getValue();
    assertTrue(out instanceof StructuredFieldValue);
    assertEquals(PositionDataType.INSTANCE, out.getDataType());
    FieldValue val = ((StructuredFieldValue) out).getFieldValue("x");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(6, ((IntegerFieldValue) val).getInteger());
    val = ((StructuredFieldValue) out).getFieldValue("y");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(9, ((IntegerFieldValue) val).getInteger());
}
Also used : StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 5 with StructuredFieldValue

use of com.yahoo.document.datatypes.StructuredFieldValue 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)

Aggregations

StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)6 FieldValue (com.yahoo.document.datatypes.FieldValue)5 Field (com.yahoo.document.Field)2 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 DataType (com.yahoo.document.DataType)1 SpanTree (com.yahoo.document.annotation.SpanTree)1 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)1 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)1 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)1 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)1 WeightedSet (com.yahoo.document.datatypes.WeightedSet)1 JsonReaderException (com.yahoo.document.json.JsonReaderException)1 WeightedSetReader.fillWeightedSet (com.yahoo.document.json.readers.WeightedSetReader.fillWeightedSet)1 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)1 Test (org.junit.Test)1