Search in sources :

Example 26 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method emptyDocTest.

@Test
public final void emptyDocTest() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": {}}"));
    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);
    assertEquals("id:unittest:smoke::whee", parseInfo.documentId.toString());
}
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 27 with Document

use of com.yahoo.document.Document 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 28 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method assertTensorField.

private static Tensor assertTensorField(String expectedTensor, DocumentPut put, String tensorFieldName) {
    final Document doc = put.getDocument();
    assertEquals("testtensor", doc.getId().getDocType());
    assertEquals(TENSOR_DOC_ID, doc.getId().toString());
    TensorFieldValue fieldValue = (TensorFieldValue) doc.getFieldValue(doc.getField(tensorFieldName));
    assertEquals(Tensor.from(expectedTensor), fieldValue.getTensor().get());
    return fieldValue.getTensor().get();
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Document(com.yahoo.document.Document)

Example 29 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method testParsingWithoutTensorField.

@Test
public void testParsingWithoutTensorField() {
    Document doc = createPutWithoutTensor().getDocument();
    assertEquals("testtensor", doc.getId().getDocType());
    assertEquals("id:unittest:testtensor::0", doc.getId().toString());
    TensorFieldValue fieldValue = (TensorFieldValue) doc.getFieldValue(doc.getField("mappedtensorfield"));
    assertNull(fieldValue);
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 30 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class ReferenceFieldValueSerializationTestCase method empty_reference_serialization_matches_cpp.

@Test
public void empty_reference_serialization_matches_cpp() throws IOException {
    final Fixture fixture = new Fixture();
    final Document document = fixture.createDocumentWithReference(fixture.createEmptyReferenceFieldValue());
    SerializationTestUtils.assertSerializationMatchesCpp(Fixture.CROSS_LANGUAGE_PATH, "empty_reference", document, fixture.documentFactory);
}
Also used : Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

Document (com.yahoo.document.Document)109 Test (org.junit.Test)63 DocumentType (com.yahoo.document.DocumentType)41 DocumentPut (com.yahoo.document.DocumentPut)40 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)33 ByteArrayInputStream (java.io.ByteArrayInputStream)23 InputStream (java.io.InputStream)18 DocumentId (com.yahoo.document.DocumentId)16 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)13 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)13 HashMap (java.util.HashMap)13 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)12 FieldValue (com.yahoo.document.datatypes.FieldValue)12 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)12 DocumentOperation (com.yahoo.document.DocumentOperation)10 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Array (com.yahoo.document.datatypes.Array)8