use of com.yahoo.document.datatypes.MapFieldValue 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.MapFieldValue 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));
}
use of com.yahoo.document.datatypes.MapFieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testOldAssignToArray.
@Test
public final void testOldAssignToArray() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": {" + " \"assign\": [" + "{ \"key\": \"bamse\", \"value\": [1, 2, 3] }" + "]}}}");
FieldUpdate f = doc.getFieldUpdate("actualMapStringToArrayOfInt");
assertEquals(1, f.size());
AssignValueUpdate assign = (AssignValueUpdate) f.getValueUpdate(0);
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) assign.getValue();
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));
}
use of com.yahoo.document.datatypes.MapFieldValue in project vespa by vespa-engine.
the class JsonReaderTestCase method testAssignToArray.
@Test
public final void testAssignToArray() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": {" + " \"assign\": { \"bamse\": [1, 2, 3] }}}}");
FieldUpdate f = doc.getFieldUpdate("actualMapStringToArrayOfInt");
assertEquals(1, f.size());
AssignValueUpdate assign = (AssignValueUpdate) f.getValueUpdate(0);
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) assign.getValue();
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));
}
use of com.yahoo.document.datatypes.MapFieldValue in project vespa by vespa-engine.
the class VespaDocumentSerializerTestCase method compressed_map_of_compressed_structs_is_supported.
@Test
public void compressed_map_of_compressed_structs_is_supported() {
CompressionFixture fixture = new CompressionFixture();
Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn");
Struct nested = new Struct(fixture.nestedType);
nested.setFieldValue("str", new StringFieldValue(CompressionFixture.COMPRESSABLE_STRING));
MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
map.put(new StringFieldValue("foo"), nested);
map.put(new StringFieldValue("bar"), nested);
doc.setFieldValue("map", map);
// Should _not_ throw any deserialization exceptions
Document result = fixture.roundtripSerialize(doc);
assertEquals(doc, result);
}
Aggregations