Search in sources :

Example 21 with NewDocumentType

use of com.yahoo.documentmodel.NewDocumentType in project vespa by vespa-engine.

the class DocumentManager method buildConfig.

private void buildConfig(DataType type, Datatype.Builder builder) {
    builder.id(type.getId());
    if (type instanceof ArrayDataType) {
        CollectionDataType dt = (CollectionDataType) type;
        builder.arraytype(new Datatype.Arraytype.Builder().datatype(dt.getNestedType().getId()));
    } else if (type instanceof WeightedSetDataType) {
        WeightedSetDataType dt = (WeightedSetDataType) type;
        builder.weightedsettype(new Datatype.Weightedsettype.Builder().datatype(dt.getNestedType().getId()).createifnonexistant(dt.createIfNonExistent()).removeifzero(dt.removeIfZero()));
    } else if (type instanceof MapDataType) {
        MapDataType mtype = (MapDataType) type;
        builder.maptype(new Datatype.Maptype.Builder().keytype(mtype.getKeyType().getId()).valtype(mtype.getValueType().getId()));
    } else if (type instanceof DocumentType) {
        DocumentType dt = (DocumentType) type;
        Datatype.Documenttype.Builder doc = new Datatype.Documenttype.Builder();
        builder.documenttype(doc);
        doc.name(dt.getName()).headerstruct(dt.getHeaderType().getId()).bodystruct(dt.getBodyType().getId());
        for (DocumentType inherited : dt.getInheritedTypes()) {
            doc.inherits(new Datatype.Documenttype.Inherits.Builder().name(inherited.getName()));
        }
    } else if (type instanceof NewDocumentType) {
        NewDocumentType dt = (NewDocumentType) type;
        Datatype.Documenttype.Builder doc = new Datatype.Documenttype.Builder();
        builder.documenttype(doc);
        doc.name(dt.getName()).headerstruct(dt.getHeader().getId()).bodystruct(dt.getBody().getId());
        for (NewDocumentType inherited : dt.getInherited()) {
            doc.inherits(new Datatype.Documenttype.Inherits.Builder().name(inherited.getName()));
        }
        buildConfig(dt.getFieldSets(), doc);
    } else if (type instanceof TemporaryStructuredDataType) {
    // Ignored
    } else if (type instanceof StructDataType) {
        StructDataType structType = (StructDataType) type;
        Datatype.Structtype.Builder structBuilder = new Datatype.Structtype.Builder();
        builder.structtype(structBuilder);
        structBuilder.name(structType.getName());
        if (structType.getCompressionConfig().type.getCode() != 0) {
            structBuilder.compresstype(Datatype.Structtype.Compresstype.Enum.valueOf(structType.getCompressionConfig().type.toString())).compresslevel(structType.getCompressionConfig().compressionLevel).compressthreshold((int) structType.getCompressionConfig().threshold).compressminsize((int) structType.getCompressionConfig().minsize);
        }
        for (com.yahoo.document.Field field : structType.getFieldsThisTypeOnly()) {
            Datatype.Structtype.Field.Builder fieldBuilder = new Datatype.Structtype.Field.Builder();
            structBuilder.field(fieldBuilder);
            fieldBuilder.name(field.getName());
            if (field.hasForcedId()) {
                fieldBuilder.id(new Datatype.Structtype.Field.Id.Builder().id(field.getId()));
            }
            fieldBuilder.datatype(field.getDataType().getId());
            if (field.getDataType() instanceof TensorDataType)
                fieldBuilder.detailedtype(((TensorDataType) field.getDataType()).getTensorType().toString());
        }
        for (StructDataType inherited : structType.getInheritedTypes()) {
            structBuilder.inherits(new Datatype.Structtype.Inherits.Builder().name(inherited.getName()));
        }
    } else if (type instanceof AnnotationReferenceDataType) {
        AnnotationReferenceDataType annotationRef = (AnnotationReferenceDataType) type;
        builder.annotationreftype(new Datatype.Annotationreftype.Builder().annotation(annotationRef.getAnnotationType().getName()));
    } else if (type instanceof TensorDataType) {
    // Nothing to do; the type of the tensor is instead stored in each field as detailed type information
    // to provide better compatibility. A tensor field can have its tensorType changed (in compatible ways)
    // without changing the field type and thus requiring data refeed
    } else if (type instanceof ReferenceDataType) {
        ReferenceDataType refType = (ReferenceDataType) type;
        builder.referencetype(new Datatype.Referencetype.Builder().target_type_id(refType.getTargetType().getId()));
    } else {
        throw new IllegalArgumentException("Can not create config for data type '" + type.getName());
    }
}
Also used : com.yahoo.document(com.yahoo.document) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) VespaDocumentType(com.yahoo.documentmodel.VespaDocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType)

Example 22 with NewDocumentType

use of com.yahoo.documentmodel.NewDocumentType in project vespa by vespa-engine.

the class StorageClusterTest method parse.

StorageCluster parse(String xml) throws Exception {
    MockRoot root = new MockRoot();
    root.getDeployState().getDocumentModel().getDocumentManager().add(new NewDocumentType(new NewDocumentType.Name("music")));
    root.getDeployState().getDocumentModel().getDocumentManager().add(new NewDocumentType(new NewDocumentType.Name("movies")));
    ContentCluster cluster = ContentClusterUtils.createCluster(xml, root);
    root.freezeModelTopology();
    return cluster.getStorageNodes();
}
Also used : MockRoot(com.yahoo.config.model.test.MockRoot) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) ContentCluster(com.yahoo.vespa.model.content.cluster.ContentCluster)

Example 23 with NewDocumentType

use of com.yahoo.documentmodel.NewDocumentType in project vespa by vespa-engine.

the class GlobalDistributionBuilderTest method global_documents_are_identified.

@Test
public void global_documents_are_identified() {
    GlobalDistributionBuilder builder = new GlobalDistributionBuilder(createDocumentDefinitions());
    String documentsElement = "<documents>" + "  <document type=\"" + NON_GLOBAL_EXPLICIT.getName() + "\" global=\"false\"/>" + "  <document type=\"" + GLOBAL_1.getName() + "\" global=\"true\"/>" + "  <document type=\"" + NON_GLOBAL_IMPLICIT.getName() + "\"/>" + "  <document type=\"" + GLOBAL_2.getName() + "\" global=\"true\"/>" + "</documents>";
    Set<NewDocumentType> expectedResult = new HashSet<>(Arrays.asList(GLOBAL_1, GLOBAL_2));
    Set<NewDocumentType> actualResult = builder.build(new ModelElement(XML.getDocument(documentsElement).getDocumentElement()));
    assertEquals(expectedResult, actualResult);
}
Also used : ModelElement(com.yahoo.vespa.model.builder.xml.dom.ModelElement) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NewDocumentType (com.yahoo.documentmodel.NewDocumentType)23 Test (org.junit.Test)7 StructDataType (com.yahoo.document.StructDataType)4 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)4 ReferenceDataType (com.yahoo.document.ReferenceDataType)3 AnnotationType (com.yahoo.document.annotation.AnnotationType)3 SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)3 MockRoot (com.yahoo.config.model.test.MockRoot)2 CollectionDataType (com.yahoo.document.CollectionDataType)2 DocumentType (com.yahoo.document.DocumentType)2 Field (com.yahoo.document.Field)2 MapDataType (com.yahoo.document.MapDataType)2 VespaDocumentType (com.yahoo.documentmodel.VespaDocumentType)2 TemporaryAnnotationReferenceDataType (com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType)2 ModelElement (com.yahoo.vespa.model.builder.xml.dom.ModelElement)2 HashSet (java.util.HashSet)2 DeployState (com.yahoo.config.model.deploy.DeployState)1 com.yahoo.document (com.yahoo.document)1 DataType (com.yahoo.document.DataType)1 StructuredDataType (com.yahoo.document.StructuredDataType)1