Search in sources :

Example 1 with ReferenceDataType

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

the class DocumentReferenceResolver method createDocumentReference.

private DocumentReference createDocumentReference(Field field) {
    if (!isAttribute(field)) {
        throw new IllegalArgumentException(String.format("The field '%s' is an invalid document reference. The field must be an attribute.", field.getName()));
    }
    ReferenceDataType reference = (ReferenceDataType) field.getDataType();
    String targetDocumentName = getTargetDocumentName(reference);
    Search search = searchMapping.get(targetDocumentName);
    if (search == null) {
        throw new IllegalArgumentException(String.format("The field '%s' is an invalid document reference. " + "Could not find document with '%s' in any search definitions", field.getName(), targetDocumentName));
    }
    return new DocumentReference(field, search);
}
Also used : ReferenceDataType(com.yahoo.document.ReferenceDataType)

Example 2 with ReferenceDataType

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

the class ReferenceFieldsProcessor method clearSummaryAttributeAspectForConcreteFields.

private void clearSummaryAttributeAspectForConcreteFields() {
    for (SDField field : search.allConcreteFields()) {
        if (field.getDataType() instanceof ReferenceDataType) {
            removeFromAttributePrefetchSummaryClass(field);
            clearSummaryTransformOnSummaryFields(field);
        }
    }
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) ReferenceDataType(com.yahoo.document.ReferenceDataType)

Example 3 with ReferenceDataType

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

the class DocumentTypeChangeValidatorTest method createDocumentTypeWithReferenceField.

private static NewDocumentType createDocumentTypeWithReferenceField(String nameReferencedDocumentType) {
    StructDataType headerfields = new StructDataType("headerfields");
    headerfields.addField(new Field("ref", new ReferenceDataType(new DocumentType(nameReferencedDocumentType), 0)));
    return new NewDocumentType(new NewDocumentType.Name("mydoc"), headerfields, new StructDataType("bodyfields"), new FieldSets(), Collections.emptySet());
}
Also used : Field(com.yahoo.document.Field) FieldSets(com.yahoo.searchdefinition.FieldSets) ReferenceDataType(com.yahoo.document.ReferenceDataType) StructDataType(com.yahoo.document.StructDataType) DocumentType(com.yahoo.document.DocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType)

Example 4 with ReferenceDataType

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

the class DocumentModelBuilderReferenceTypeTestCase method reference_data_type_has_a_concrete_target_type.

@Test
public void reference_data_type_has_a_concrete_target_type() throws ParseException {
    DocumentModel model = new TestDocumentModelBuilder().addCampaign().build(joinLines("search ad {", "  document ad {", "    field campaign_ref type reference<campaign> { indexing: attribute }", "  }", "}"));
    NewDocumentType campaignType = model.getDocumentManager().getDocumentType("campaign");
    NewDocumentType adType = model.getDocumentManager().getDocumentType("ad");
    ReferenceDataType campaignRefType = (ReferenceDataType) adType.getField("campaign_ref").getDataType();
    assertEquals(campaignRefType.getTargetType(), campaignType);
}
Also used : ReferenceDataType(com.yahoo.document.ReferenceDataType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) Test(org.junit.Test)

Example 5 with ReferenceDataType

use of com.yahoo.document.ReferenceDataType 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)

Aggregations

ReferenceDataType (com.yahoo.document.ReferenceDataType)7 Field (com.yahoo.document.Field)4 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)3 DataType (com.yahoo.document.DataType)2 DocumentType (com.yahoo.document.DocumentType)2 StructDataType (com.yahoo.document.StructDataType)2 SDField (com.yahoo.searchdefinition.document.SDField)2 CollectionDataType (com.yahoo.document.CollectionDataType)1 MapDataType (com.yahoo.document.MapDataType)1 StructuredDataType (com.yahoo.document.StructuredDataType)1 TemporaryStructuredDataType (com.yahoo.document.TemporaryStructuredDataType)1 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)1 FieldSets (com.yahoo.searchdefinition.FieldSets)1 TemporaryAnnotationReferenceDataType (com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType)1 SearchField (com.yahoo.vespa.documentmodel.SearchField)1 Test (org.junit.Test)1