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());
}
}
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();
}
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);
}
Aggregations