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);
}
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);
}
}
}
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());
}
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);
}
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;
}
Aggregations