Search in sources :

Example 76 with DocumentType

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

the class VespaDocumentSerializerTestCase method predicate_field_values_are_serialized.

@Test
public void predicate_field_values_are_serialized() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_predicate", DataType.PREDICATE);
    docType.addField(field);
    Document doc = new Document(docType, "doc:scheme:");
    PredicateFieldValue predicate = Mockito.mock(PredicateFieldValue.class);
    doc.setFieldValue("my_predicate", predicate);
    DocumentSerializerFactory.create42(new GrowableByteBuffer()).write(doc);
    Mockito.verify(predicate, Mockito.times(1)).serialize(Mockito.same(field), Mockito.any(FieldWriter.class));
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Example 77 with DocumentType

use of com.yahoo.document.DocumentType 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 78 with DocumentType

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

the class PositionParserTestCase method requireThatPositionStringsCanBeParsed.

@Test
public void requireThatPositionStringsCanBeParsed() throws Exception {
    DocumentTypeManager mgr = new DocumentTypeManager();
    mgr.register(PositionDataType.INSTANCE);
    DocumentType docType = new DocumentType("my_doc");
    docType.addField("my_pos", PositionDataType.INSTANCE);
    mgr.registerDocumentType(docType);
    VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_position.xml", mgr);
    Iterator<VespaXMLFeedReader.Operation> it = parser.readAll().iterator();
    assertTrue(it.hasNext());
    assertDocument(PositionDataType.valueOf(1, 2), it.next());
    assertTrue(it.hasNext());
    assertDocument(PositionDataType.fromString("E3;N4"), it.next());
    assertTrue(it.hasNext());
    assertDocument(PositionDataType.fromString("5;6"), it.next());
    assertTrue(it.hasNext());
    assertDocument(PositionDataType.fromString("7;8"), it.next());
    assertFalse(it.hasNext());
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 79 with DocumentType

use of com.yahoo.document.DocumentType 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 80 with DocumentType

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

the class JsonWriterTestCase method registerSetDocumentType.

private void registerSetDocumentType() {
    DocumentType x = new DocumentType("testset");
    DataType d = new WeightedSetDataType(DataType.STRING, true, true);
    x.addField(new Field("actualset", d));
    types.registerDocumentType(x);
}
Also used : Field(com.yahoo.document.Field) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) PositionDataType(com.yahoo.document.PositionDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType)

Aggregations

DocumentType (com.yahoo.document.DocumentType)98 Test (org.junit.Test)45 Document (com.yahoo.document.Document)41 DocumentPut (com.yahoo.document.DocumentPut)35 Field (com.yahoo.document.Field)24 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)24 DocumentId (com.yahoo.document.DocumentId)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStream (java.io.InputStream)19 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)17 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)17 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)17 DocumentUpdate (com.yahoo.document.DocumentUpdate)15 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)15 StructDataType (com.yahoo.document.StructDataType)14 TensorDataType (com.yahoo.document.TensorDataType)12 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)11 ArrayDataType (com.yahoo.document.ArrayDataType)10 MapDataType (com.yahoo.document.MapDataType)10 ReferenceDataType (com.yahoo.document.ReferenceDataType)10