use of com.yahoo.document.datatypes.FieldValue 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.FieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testWeightedSet.
@Test
public final void testWeightedSet() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testset::whee\"," + " \"fields\": { \"actualset\": {" + " \"nalle\": 2," + " \"tralle\": 7 }}}"));
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("actualset"));
assertSame(WeightedSet.class, f.getClass());
WeightedSet<?> w = (WeightedSet<?>) f;
assertEquals(2, w.size());
assertEquals(new Integer(2), w.get(new StringFieldValue("nalle")));
assertEquals(new Integer(7), w.get(new StringFieldValue("tralle")));
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testRaw.
@Test
public final void testRaw() throws IOException {
String stuff = new String(new JsonStringEncoder().quoteAsString(new Base64().encodeToString(Utf8.toBytes("smoketest"))));
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testraw::whee\"," + " \"fields\": { \"actualraw\": \"" + stuff + "\"" + " }}"));
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("actualraw"));
assertSame(Raw.class, f.getClass());
Raw s = (Raw) f;
ByteBuffer b = s.getByteBuffer();
assertEquals("smoketest", Utf8.toString(b));
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testArray.
@Test
public final void testArray() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testarray::whee\"," + " \"fields\": { \"actualarray\": [" + " \"nalle\"," + " \"tralle\"]}}"));
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("actualarray"));
assertSame(Array.class, f.getClass());
Array<?> a = (Array<?>) f;
assertEquals(2, a.size());
assertEquals(new StringFieldValue("nalle"), a.get(0));
assertEquals(new StringFieldValue("tralle"), a.get(1));
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testPositionPositive.
@Test
public final void testPositionPositive() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testsinglepos::bamf\"," + " \"fields\": { \"singlepos\": \"N63.429722;E10.393333\" }}"));
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("singlepos"));
assertSame(Struct.class, f.getClass());
assertEquals(10393333, PositionDataType.getXValue(f).getInteger());
assertEquals(63429722, PositionDataType.getYValue(f).getInteger());
}
Aggregations