use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class IfThenExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
FieldValue lhsVal = ctx.setValue(input).execute(lhs).getValue();
if (lhsVal == null) {
ctx.setValue(null);
return;
}
FieldValue rhsVal = ctx.setValue(input).execute(rhs).getValue();
if (rhsVal == null) {
ctx.setValue(null);
return;
}
ctx.setValue(input);
if (isTrue(lhsVal, cmp, rhsVal)) {
ifTrue.execute(ctx);
} else if (ifFalse != null) {
ifFalse.execute(ctx);
}
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class SelectInputExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
for (Pair<String, Expression> entry : cases) {
FieldValue val = ctx.getInputValue(entry.getFirst());
if (val != null) {
ctx.setValue(val).execute(entry.getSecond());
break;
}
}
ctx.setValue(input);
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class ScriptExpression method doExecute.
@Override
protected void doExecute(ExecutionContext ctx) {
FieldValue input = ctx.getValue();
for (Expression exp : this) {
ctx.setValue(input).execute(exp);
}
ctx.setValue(input);
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testMap.
@Test
public final void testMap() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testmap::whee\"," + " \"fields\": { \"actualmap\": {" + " \"nalle\": \"kalle\", \"tralle\": \"skalle\"}}}"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
Document doc = put.getDocument();
FieldValue f = doc.getFieldValue(doc.getField("actualmap"));
assertSame(MapFieldValue.class, f.getClass());
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) f;
assertEquals(2, m.size());
assertEquals(new StringFieldValue("kalle"), m.get(new StringFieldValue("nalle")));
assertEquals(new StringFieldValue("skalle"), m.get(new StringFieldValue("tralle")));
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testMapStringToArrayOfInt.
@Test
public final void testMapStringToArrayOfInt() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": { \"bamse\": [1, 2, 3] }}}"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
Document doc = put.getDocument();
FieldValue f = doc.getFieldValue("actualMapStringToArrayOfInt");
assertSame(MapFieldValue.class, f.getClass());
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) f;
Array<?> a = (Array<?>) m.get(new StringFieldValue("bamse"));
assertEquals(3, a.size());
assertEquals(new IntegerFieldValue(1), a.get(0));
assertEquals(new IntegerFieldValue(2), a.get(1));
assertEquals(new IntegerFieldValue(3), a.get(2));
}
Aggregations