Search in sources :

Example 26 with DataType

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

the class DocumentModelBuilder method resolveTemporariesRecurse.

@SuppressWarnings("deprecation")
private static DataType resolveTemporariesRecurse(DataType type, DataTypeCollection repo, Collection<NewDocumentType> docs) {
    if (type instanceof TemporaryStructuredDataType) {
        NewDocumentType docType = getDocumentType(docs, type.getId());
        if (docType != null) {
            type = docType;
            return type;
        }
        DataType real = repo.getDataType(type.getId());
        if (real == null) {
            throw new NullPointerException("Can not find type '" + type.toString() + "', impossible.");
        }
        type = real;
    } else if (type instanceof StructDataType) {
        StructDataType dt = (StructDataType) type;
        for (com.yahoo.document.Field field : dt.getFields()) {
            if (field.getDataType() != type) {
                // XXX deprecated:
                field.setDataType(resolveTemporariesRecurse(field.getDataType(), repo, docs));
            }
        }
    } else if (type instanceof MapDataType) {
        MapDataType t = (MapDataType) type;
        t.setKeyType(resolveTemporariesRecurse(t.getKeyType(), repo, docs));
        t.setValueType(resolveTemporariesRecurse(t.getValueType(), repo, docs));
    } else if (type instanceof CollectionDataType) {
        CollectionDataType t = (CollectionDataType) type;
        t.setNestedType(resolveTemporariesRecurse(t.getNestedType(), repo, docs));
    } else if (type instanceof ReferenceDataType) {
        ReferenceDataType t = (ReferenceDataType) type;
        if (t.getTargetType() instanceof TemporaryStructuredDataType) {
            DataType targetType = resolveTemporariesRecurse(t.getTargetType(), repo, docs);
            t.setTargetType((StructuredDataType) targetType);
        }
    }
    return type;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SearchField(com.yahoo.vespa.documentmodel.SearchField) Field(com.yahoo.document.Field) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) StructuredDataType(com.yahoo.document.StructuredDataType) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) DataType(com.yahoo.document.DataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) MapDataType(com.yahoo.document.MapDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) MapDataType(com.yahoo.document.MapDataType)

Example 27 with DataType

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

the class DocumentModelBuilder method specialHandleAnnotationReference.

@SuppressWarnings("deprecation")
private static void specialHandleAnnotationReference(NewDocumentType docType, Field field) {
    DataType fieldType = specialHandleAnnotationReferenceRecurse(docType, field.getName(), field.getDataType());
    if (fieldType == null) {
        return;
    }
    // XXX deprecated
    field.setDataType(fieldType);
}
Also used : StructuredDataType(com.yahoo.document.StructuredDataType) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) DataType(com.yahoo.document.DataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) MapDataType(com.yahoo.document.MapDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType)

Example 28 with DataType

use of com.yahoo.document.DataType 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;
}
Also used : AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) CollectionDataType(com.yahoo.document.CollectionDataType) StructuredDataType(com.yahoo.document.StructuredDataType) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) DataType(com.yahoo.document.DataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) MapDataType(com.yahoo.document.MapDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) MapDataType(com.yahoo.document.MapDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 29 with DataType

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

the class IndexSchema method flattenField.

static List<Field> flattenField(Field field) {
    DataType fieldType = field.getDataType();
    if (fieldType.getPrimitiveType() != null) {
        return Collections.singletonList(field);
    }
    if (fieldType instanceof ArrayDataType) {
        boolean header = field.isHeader();
        List<Field> ret = new LinkedList<>();
        Field innerField = new Field(field.getName(), ((ArrayDataType) fieldType).getNestedType(), header);
        for (Field flatField : flattenField(innerField)) {
            ret.add(new Field(flatField.getName(), DataType.getArray(flatField.getDataType()), header));
        }
        return ret;
    }
    if (fieldType instanceof StructuredDataType) {
        List<Field> ret = new LinkedList<>();
        String fieldName = field.getName();
        for (Field childField : ((StructuredDataType) fieldType).getFields()) {
            for (Field flatField : flattenField(childField)) {
                ret.add(new Field(fieldName + "." + flatField.getName(), flatField));
            }
        }
        return ret;
    }
    throw new UnsupportedOperationException(fieldType.getName());
}
Also used : Field(com.yahoo.document.Field) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField) StructuredDataType(com.yahoo.document.StructuredDataType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) StructuredDataType(com.yahoo.document.StructuredDataType) ArrayDataType(com.yahoo.document.ArrayDataType) LinkedList(java.util.LinkedList)

Example 30 with DataType

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

the class ReferenceFieldTestCase method assertSearchContainsReferenceField.

private static void assertSearchContainsReferenceField(String expectedFieldname, String referencedDocType, SDDocumentType documentType) {
    Field field = documentType.getDocumentType().getField(expectedFieldname);
    assertNotNull("Field does not exist in document type: " + expectedFieldname, field);
    DataType dataType = field.getDataType();
    assertThat(dataType, instanceOf(ReferenceDataType.class));
    ReferenceDataType refField = (ReferenceDataType) dataType;
    assertEquals(referencedDocType, refField.getTargetType().getName());
}
Also used : Field(com.yahoo.document.Field) ReferenceDataType(com.yahoo.document.ReferenceDataType) DataType(com.yahoo.document.DataType) ReferenceDataType(com.yahoo.document.ReferenceDataType)

Aggregations

DataType (com.yahoo.document.DataType)62 ArrayDataType (com.yahoo.document.ArrayDataType)20 MapDataType (com.yahoo.document.MapDataType)19 Field (com.yahoo.document.Field)17 StructDataType (com.yahoo.document.StructDataType)17 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)17 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 PositionDataType (com.yahoo.document.PositionDataType)12 CollectionDataType (com.yahoo.document.CollectionDataType)11 FieldValue (com.yahoo.document.datatypes.FieldValue)11 TensorDataType (com.yahoo.document.TensorDataType)10 DocumentType (com.yahoo.document.DocumentType)9 StructuredDataType (com.yahoo.document.StructuredDataType)7 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)6 SDField (com.yahoo.searchdefinition.document.SDField)6 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)5 TemporaryStructuredDataType (com.yahoo.document.TemporaryStructuredDataType)4 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4