Search in sources :

Example 56 with DocumentType

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

the class SimpleDocumentProcessorTestCase method requireThatProcessingSingleOperationWorks.

@Test
public void requireThatProcessingSingleOperationWorks() {
    DocumentType type = new DocumentType("foobar");
    type.addField("title", DataType.STRING);
    Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"));
    DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor());
    service.getExecutor().process(p);
    assertThat(p.getDocumentOperations().size(), is(1));
    assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 57 with DocumentType

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

the class SimpleDocumentProcessorTestCase method requireThatThrowingTerminatesIteration.

@Test
public void requireThatThrowingTerminatesIteration() {
    DocumentType type = new DocumentType("foobar");
    type.addField("title", DataType.STRING);
    Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")), new DocumentPut(type, "doc:this:is:a:document2"));
    DocprocService service = setupDocprocService(new SimpleDocumentProcessorThrowingOnRemovesAndUpdates());
    try {
        service.getExecutor().process(p);
    } catch (RuntimeException re) {
    // ok
    }
    assertThat(p.getDocumentOperations().size(), is(3));
    assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
    assertThat(p.getDocumentOperations().get(1) instanceof DocumentRemove, is(true));
    assertThat(p.getDocumentOperations().get(1).getId().toString(), is("doc:this:is:a:remove"));
    assertThat(p.getDocumentOperations().get(2) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(2)).getDocument().getFieldValue("title"), nullValue());
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 58 with DocumentType

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

the class SplitterDocumentProcessor method doProcessOuterDocument.

static boolean doProcessOuterDocument(Object o, String documentTypeName) {
    if (!(o instanceof DocumentOperation)) {
        if (log.isLoggable(LogLevel.DEBUG)) {
            log.log(LogLevel.DEBUG, o + " is not a DocumentOperation.");
        }
        return false;
    }
    DocumentOperation outerDocOp = (DocumentOperation) o;
    if (!(outerDocOp instanceof DocumentPut)) {
        // this is not a put, return
        if (log.isLoggable(LogLevel.DEBUG)) {
            log.log(LogLevel.DEBUG, "Given DocumentOperation is not a DocumentPut, returning. (Was given " + outerDocOp + ").");
        }
        return false;
    }
    Document outerDoc = ((DocumentPut) outerDocOp).getDocument();
    DocumentType type = outerDoc.getDataType();
    if (!type.getName().equalsIgnoreCase(documentTypeName)) {
        // this is not the right document type
        if (log.isLoggable(LogLevel.DEBUG)) {
            log.log(LogLevel.DEBUG, "Given Document is of wrong type, returning. (Was given " + outerDoc + ").");
        }
        return false;
    }
    return true;
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document)

Example 59 with DocumentType

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

the class SplitterDocumentProcessor method validate.

static void validate(DocumentTypeManager manager, String documentTypeName, String arrayFieldName) {
    DocumentType docType = manager.getDocumentType(documentTypeName);
    if (docType == null) {
        // the document type does not exist, return
        throw new IllegalStateException("The document type " + documentTypeName + " is not deployed.");
    }
    if (docType.getField(arrayFieldName) == null) {
        // the document type does not have the field, return
        throw new IllegalStateException("The document type " + documentTypeName + " does not have a field named " + arrayFieldName + ".");
    }
    if (!(docType.getField(arrayFieldName).getDataType() instanceof ArrayDataType)) {
        // the data type of the field is wrong, return
        throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array type");
    }
    ArrayDataType fieldDataType = (ArrayDataType) docType.getField(arrayFieldName).getDataType();
    if (!(fieldDataType.getNestedType() instanceof DocumentType)) {
        // the subtype of tye array data type of the field is wrong, return
        throw new IllegalStateException("The data type of the field named " + arrayFieldName + " in document type " + documentTypeName + " is not an array of Document.");
    }
}
Also used : DocumentType(com.yahoo.document.DocumentType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 60 with DocumentType

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

the class AccessesAnnotationTestCase method requireThatFieldsAreRestricted.

@Test
public void requireThatFieldsAreRestricted() {
    DocumentType type = new DocumentType("album");
    type.addField("title", DataType.STRING);
    type.addField("artist", DataType.STRING);
    type.addField("year", DataType.INT);
    Document doc = new Document(type, new DocumentId("doc:map:test:1"));
    MyDocProc docProc = new MyDocProc();
    DocumentPut put = new DocumentPut(doc);
    Document proxy = new Call(docProc).configDoc(docProc, put).getDocument();
    proxy.setFieldValue("title", new StringFieldValue("foo"));
    try {
        proxy.setFieldValue("year", new IntegerFieldValue(69));
        fail("Should have failed");
    } catch (Exception e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().matches(".*not allowed.*"));
    }
    proxy.getFieldValue("title");
    try {
        proxy.getFieldValue("year");
        fail("Should have failed");
    } catch (Exception e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().matches(".*not allowed.*"));
    }
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

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