Search in sources :

Example 81 with Document

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

the class VespaDocumentSerializerTestCase method get_serialized_size_uses_latest_serializer.

@Test
public void get_serialized_size_uses_latest_serializer() {
    DocumentType docType = new DocumentType("my_type");
    docType.addField("my_str", DataType.STRING);
    docType.addField("my_int", DataType.INT);
    Document doc = new Document(docType, "doc:scheme:");
    doc.setFieldValue("my_str", new StringFieldValue("foo"));
    doc.setFieldValue("my_int", new IntegerFieldValue(69));
    GrowableByteBuffer buf = new GrowableByteBuffer();
    doc.serialize(buf);
    assertEquals(buf.position(), VespaDocumentSerializer42.getSerializedSize(doc));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 82 with Document

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

the class PositionParserTestCase method assertDocument.

private static void assertDocument(Struct expected, VespaXMLFeedReader.Operation operation) {
    assertNotNull(operation);
    assertEquals(VespaXMLFeedReader.OperationType.DOCUMENT, operation.getType());
    Document doc = operation.getDocument();
    assertNotNull(doc);
    assertEquals(expected, doc.getFieldValue("my_pos"));
}
Also used : Document(com.yahoo.document.Document)

Example 83 with Document

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

the class JsonWriterTestCase method testWritingOfTensorFieldValueWithoutTensor.

@Test
public void testWritingOfTensorFieldValueWithoutTensor() throws IOException {
    DocumentType documentTypeWithTensor = types.getDocumentType("testtensor");
    String docId = "id:unittest:testtensor::0";
    Document doc = new Document(documentTypeWithTensor, docId);
    Field tensorField = documentTypeWithTensor.getField("tensorfield");
    doc.setFieldValue(tensorField, new TensorFieldValue(((TensorDataType) tensorField.getDataType()).getTensorType()));
    assertEqualJson(asDocument(docId, "{ \"tensorfield\": {} }"), JsonWriter.toByteArray(doc));
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Field(com.yahoo.document.Field) TensorDataType(com.yahoo.document.TensorDataType) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 84 with Document

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

the class JsonWriterTestCase method assertTensorRoundTripEquality.

private void assertTensorRoundTripEquality(String inputTensorField, String outputTensorField) throws IOException {
    String inputFields = "{ \"tensorfield\": " + inputTensorField + " }";
    String outputFields = "{ \"tensorfield\": " + outputTensorField + " }";
    String docId = "id:unittest:testtensor::0";
    Document doc = readDocumentFromJson(docId, inputFields);
    assertEqualJson(asDocument(docId, outputFields), JsonWriter.toByteArray(doc));
}
Also used : Document(com.yahoo.document.Document)

Example 85 with Document

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

the class JsonWriterTestCase method non_empty_reference_field_results_in_reference_value_with_doc_id_present.

@Test
public void non_empty_reference_field_results_in_reference_value_with_doc_id_present() throws IOException {
    final Document doc = readDocumentFromJson("id:unittest:testrefs::helloworld", "{ \"ref_field\": \"id:unittest:smoke::and_mirrors_too\" }");
    ReferenceFieldValue ref = (ReferenceFieldValue) doc.getFieldValue("ref_field");
    assertTrue(ref.getDocumentId().isPresent());
    assertEquals(new DocumentId("id:unittest:smoke::and_mirrors_too"), ref.getDocumentId().get());
}
Also used : DocumentId(com.yahoo.document.DocumentId) ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) 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