Search in sources :

Example 1 with StructuredDataType

use of com.yahoo.document.StructuredDataType 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 2 with StructuredDataType

use of com.yahoo.document.StructuredDataType 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 3 with StructuredDataType

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

the class MapValueUpdate method checkCompatibility.

@Override
protected void checkCompatibility(DataType fieldType) {
    if (fieldType instanceof ArrayDataType) {
        if (!(value instanceof IntegerFieldValue)) {
            throw new IllegalArgumentException("Expected integer, got " + value.getClass().getName() + ".");
        }
        update.checkCompatibility(((ArrayDataType) fieldType).getNestedType());
    } else if (fieldType instanceof WeightedSetDataType) {
        ((WeightedSetDataType) fieldType).getNestedType().createFieldValue().assign(value);
        update.checkCompatibility(DataType.INT);
    } else if (fieldType instanceof StructuredDataType) {
        if (!(value instanceof StringFieldValue)) {
            throw new IllegalArgumentException("Expected string, got " + value.getClass().getName() + ".");
        }
        Field field = ((StructuredDataType) fieldType).getField(((StringFieldValue) value).getString());
        if (field == null) {
            throw new IllegalArgumentException("Field '" + value + "' not found.");
        }
        update.checkCompatibility(field.getDataType());
    } else {
        throw new UnsupportedOperationException("Field type " + fieldType.getName() + " not supported.");
    }
}
Also used : Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StructuredDataType(com.yahoo.document.StructuredDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 4 with StructuredDataType

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

the class GetFieldExpression method doVerify.

@Override
protected void doVerify(VerificationContext context) {
    DataType input = context.getValue();
    if (!(input instanceof StructuredDataType)) {
        throw new VerificationException(this, "Expected structured input, got " + input.getName() + ".");
    }
    Field field = ((StructuredDataType) input).getField(fieldName);
    if (field == null) {
        throw new VerificationException(this, "Field '" + fieldName + "' not found.");
    }
    context.setValue(field.getDataType());
}
Also used : Field(com.yahoo.document.Field) StructuredDataType(com.yahoo.document.StructuredDataType) DataType(com.yahoo.document.DataType) StructuredDataType(com.yahoo.document.StructuredDataType)

Aggregations

Field (com.yahoo.document.Field)4 StructuredDataType (com.yahoo.document.StructuredDataType)4 DataType (com.yahoo.document.DataType)3 ArrayDataType (com.yahoo.document.ArrayDataType)2 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)2 CollectionDataType (com.yahoo.document.CollectionDataType)1 MapDataType (com.yahoo.document.MapDataType)1 ReferenceDataType (com.yahoo.document.ReferenceDataType)1 StructDataType (com.yahoo.document.StructDataType)1 TemporaryStructuredDataType (com.yahoo.document.TemporaryStructuredDataType)1 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)1 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)1 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)1 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)1 ImmutableSDField (com.yahoo.searchdefinition.document.ImmutableSDField)1 SDField (com.yahoo.searchdefinition.document.SDField)1 TemporaryAnnotationReferenceDataType (com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType)1 SearchField (com.yahoo.vespa.documentmodel.SearchField)1 LinkedList (java.util.LinkedList)1