Search in sources :

Example 6 with DocumentParseInfo

use of com.yahoo.document.json.readers.DocumentParseInfo 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 7 with DocumentParseInfo

use of com.yahoo.document.json.readers.DocumentParseInfo in project vespa by vespa-engine.

the class JsonWriterTestCase method readDocumentFromJson.

private Document readDocumentFromJson(String docId, String fields) throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(asFeed(docId, fields));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentParseInfo raw = r.parseDocument().get();
    DocumentType docType = r.readDocumentType(raw.documentId);
    DocumentPut put = new DocumentPut(new Document(docType, raw.documentId));
    new VespaJsonDocumentReader().readPut(raw.fieldsBuffer, put);
    return put.getDocument();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader)

Example 8 with DocumentParseInfo

use of com.yahoo.document.json.readers.DocumentParseInfo in project vespa by vespa-engine.

the class JsonReaderTestCase method smokeTest.

@Test
public final void smokeTest() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}"));
    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);
    smokeTestDoc(put.getDocument());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Test(org.junit.Test)

Example 9 with DocumentParseInfo

use of com.yahoo.document.json.readers.DocumentParseInfo in project vespa by vespa-engine.

the class JsonReaderTestCase method docIdLookaheadTest.

@Test
public final void docIdLookaheadTest() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{" + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}," + "\"put\": \"id:unittest:smoke::whee\"" + "}"));
    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);
    smokeTestDoc(put.getDocument());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Test(org.junit.Test)

Example 10 with DocumentParseInfo

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

Aggregations

DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)20 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)19 DocumentType (com.yahoo.document.DocumentType)17 ByteArrayInputStream (java.io.ByteArrayInputStream)17 InputStream (java.io.InputStream)17 Document (com.yahoo.document.Document)16 DocumentPut (com.yahoo.document.DocumentPut)16 Test (org.junit.Test)15 FieldValue (com.yahoo.document.datatypes.FieldValue)10 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)10 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)10 Array (com.yahoo.document.datatypes.Array)3 DocumentOperation (com.yahoo.document.DocumentOperation)2 IOException (java.io.IOException)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 JsonStringEncoder (com.fasterxml.jackson.core.io.JsonStringEncoder)1 DocumentId (com.yahoo.document.DocumentId)1 DocumentUpdate (com.yahoo.document.DocumentUpdate)1