Search in sources :

Example 1 with MapFieldValue

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")));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Test(org.junit.Test)

Example 2 with MapFieldValue

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));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Array(com.yahoo.document.datatypes.Array) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Test(org.junit.Test)

Example 3 with MapFieldValue

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));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Array(com.yahoo.document.datatypes.Array) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Example 4 with MapFieldValue

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));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Array(com.yahoo.document.datatypes.Array) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Example 5 with MapFieldValue

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);
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Document(com.yahoo.document.Document) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Aggregations

MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)16 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)11 Test (org.junit.Test)11 FieldValue (com.yahoo.document.datatypes.FieldValue)8 Array (com.yahoo.document.datatypes.Array)7 Document (com.yahoo.document.Document)6 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)5 WeightedSet (com.yahoo.document.datatypes.WeightedSet)5 DocumentPut (com.yahoo.document.DocumentPut)4 DocumentType (com.yahoo.document.DocumentType)4 Struct (com.yahoo.document.datatypes.Struct)4 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)4 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 JsonToken (com.fasterxml.jackson.core.JsonToken)3 DataType (com.yahoo.document.DataType)3 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)3 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)3