Search in sources :

Example 51 with Field

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

the class DocumentModelBuilder method handleStruct.

private static StructDataType handleStruct(NewDocumentType dt, SDDocumentType type) {
    StructDataType s = new StructDataType(type.getName());
    for (Field f : type.getDocumentType().getHeaderType().getFieldsThisTypeOnly()) {
        specialHandleAnnotationReference(dt, f);
        s.addField(f);
    }
    for (StructDataType inherited : type.getDocumentType().getHeaderType().getInheritedTypes()) {
        s.inherit(inherited);
    }
    extractNestedTypes(dt, s);
    addType(dt, s);
    return s;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SearchField(com.yahoo.vespa.documentmodel.SearchField) Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType)

Example 52 with Field

use of com.yahoo.document.Field 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 53 with Field

use of com.yahoo.document.Field 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 54 with Field

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

the class Search method allConcreteFields.

/**
 * Returns a list of all the fields of this search definition, that is all fields in all documents, in the documents
 * they inherit, and all extra fields. The caller receives ownership to the list - subsequent changes to it will not
 * impact this
 */
public List<SDField> allConcreteFields() {
    List<SDField> allFields = new ArrayList<>();
    allFields.addAll(extraFieldList());
    for (Field field : docType.fieldSet()) {
        allFields.add((SDField) field);
    }
    return allFields;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) ImmutableImportedSDField(com.yahoo.searchdefinition.document.ImmutableImportedSDField) SummaryField(com.yahoo.vespa.documentmodel.SummaryField) Field(com.yahoo.document.Field) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField) SDField(com.yahoo.searchdefinition.document.SDField) ImmutableImportedSDField(com.yahoo.searchdefinition.document.ImmutableImportedSDField) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField) ArrayList(java.util.ArrayList)

Example 55 with Field

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

the class SDDocumentType method fieldSet.

public Set<Field> fieldSet() {
    Map<String, Field> map = fieldsInherited();
    Iterator<Field> it = docType.fieldIteratorThisTypeOnly();
    while (it.hasNext()) {
        Field field = it.next();
        map.put(field.getName(), field);
    }
    return new LinkedHashSet<>(map.values());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Field(com.yahoo.document.Field)

Aggregations

Field (com.yahoo.document.Field)115 Test (org.junit.Test)50 StructDataType (com.yahoo.document.StructDataType)46 DocumentType (com.yahoo.document.DocumentType)24 DataType (com.yahoo.document.DataType)17 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 ArrayDataType (com.yahoo.document.ArrayDataType)12 MapDataType (com.yahoo.document.MapDataType)12 TensorDataType (com.yahoo.document.TensorDataType)11 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)11 SDField (com.yahoo.searchdefinition.document.SDField)10 PositionDataType (com.yahoo.document.PositionDataType)9 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)9 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Struct (com.yahoo.document.datatypes.Struct)7 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)6 Document (com.yahoo.document.Document)5