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));
}
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;
}
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;
}
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());
}
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);
}
}
}
Aggregations