use of com.yahoo.document.annotation.AnnotationReferenceDataType in project vespa by vespa-engine.
the class SDDocumentTypeOrderer method visit.
private void visit(DataType type) {
if (type instanceof StructuredDataType) {
StructuredDataType structType = (StructuredDataType) type;
SDDocumentType sdDocType = find(structType.getName());
if (sdDocType == null) {
throw new IllegalArgumentException("Could not find struct '" + type.getName() + "'.");
}
visit(sdDocType);
return;
}
if (type instanceof MapDataType) {
MapDataType mType = (MapDataType) type;
visit(mType.getValueType());
visit(mType.getKeyType());
} else if (type instanceof WeightedSetDataType) {
WeightedSetDataType wType = (WeightedSetDataType) type;
visit(wType.getNestedType());
} else if (type instanceof CollectionDataType) {
CollectionDataType cType = (CollectionDataType) type;
visit(cType.getNestedType());
} else if (type instanceof AnnotationReferenceDataType) {
// do nothing
} else if (type instanceof PrimitiveDataType) {
// do nothing
} else if (type instanceof TensorDataType) {
// do nothing
} else if (type instanceof ReferenceDataType) {
// do nothing
} else {
deployLogger.log(Level.WARNING, "Unknown type : " + type);
}
}
use of com.yahoo.document.annotation.AnnotationReferenceDataType in project vespa by vespa-engine.
the class DocumentTypeManagerConfigurer method setupAnnotationRefTypes.
private static void setupAnnotationRefTypes(DocumentmanagerConfig config, DocumentTypeManager manager) {
for (int i = 0; i < config.datatype().size(); i++) {
DocumentmanagerConfig.Datatype thisDataType = config.datatype(i);
int id = thisDataType.id();
for (Object o : thisDataType.annotationreftype()) {
DocumentmanagerConfig.Datatype.Annotationreftype annRefType = (DocumentmanagerConfig.Datatype.Annotationreftype) o;
AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annRefType.annotation());
if (annotationType == null) {
throw new IllegalArgumentException("Found reference to " + annRefType.annotation() + ", which does not exist!");
}
AnnotationReferenceDataType type = new AnnotationReferenceDataType(annotationType, id);
manager.register(type);
}
}
}
use of com.yahoo.document.annotation.AnnotationReferenceDataType in project vespa by vespa-engine.
the class DocumentModelBuilder method specialHandleAnnotationReferenceRecurse.
private static DataType specialHandleAnnotationReferenceRecurse(NewDocumentType docType, String fieldName, DataType dataType) {
if (dataType instanceof TemporaryAnnotationReferenceDataType) {
TemporaryAnnotationReferenceDataType refType = (TemporaryAnnotationReferenceDataType) dataType;
if (refType.getId() != 0) {
return null;
}
AnnotationType target = docType.getAnnotationType(refType.getTarget());
if (target == null) {
throw new RetryLaterException("Annotation '" + refType.getTarget() + "' in reference '" + fieldName + "' does not exist.");
}
dataType = new AnnotationReferenceDataType(target);
addType(docType, dataType);
return dataType;
} else if (dataType instanceof MapDataType) {
MapDataType mapType = (MapDataType) dataType;
DataType valueType = specialHandleAnnotationReferenceRecurse(docType, fieldName, mapType.getValueType());
if (valueType == null) {
return null;
}
mapType = mapType.clone();
mapType.setValueType(valueType);
addType(docType, mapType);
return mapType;
} else if (dataType instanceof CollectionDataType) {
CollectionDataType lstType = (CollectionDataType) dataType;
DataType nestedType = specialHandleAnnotationReferenceRecurse(docType, fieldName, lstType.getNestedType());
if (nestedType == null) {
return null;
}
lstType = lstType.clone();
lstType.setNestedType(nestedType);
addType(docType, lstType);
return lstType;
}
return null;
}
use of com.yahoo.document.annotation.AnnotationReferenceDataType 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.document.annotation.AnnotationReferenceDataType in project vespa by vespa-engine.
the class DocumentGenMojo method exportImportProvidedAnnotationRefs.
/**
* Handle the case of an annotation reference with a type that is user provided, we need to know the class name then
*/
private String exportImportProvidedAnnotationRefs(AnnotationType annType) {
String ret = "";
if (annType.getDataType() == null)
return ret;
for (Field f : ((StructDataType) annType.getDataType()).getFields()) {
if (f.getDataType() instanceof AnnotationReferenceDataType) {
AnnotationReferenceDataType refType = (AnnotationReferenceDataType) f.getDataType();
AnnotationType referenced = refType.getAnnotationType();
String providedClass = provided(referenced.getName());
if (providedClass != null) {
// Annotationreference is to a type that is user-provided
ret = ret + "import " + providedClass + ";\n";
}
}
}
return ret;
}
Aggregations