diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-03-17 10:09:46 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-03-17 10:09:46 +0000 |
commit | da2394528ea86f38bb2d00bbbe09142ac61d0faf (patch) | |
tree | eff5edd9ad715ae8f5900f416df0e671c9fe4e2c /config-model/src/main/java/com | |
parent | 66cd9e646c66b255d2259ec39a72f5b3fd8ce100 (diff) |
switch to NewDocumentReferenceDataType
Diffstat (limited to 'config-model/src/main/java/com')
13 files changed, 63 insertions, 52 deletions
diff --git a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java index 4ff54d7ff1c..a6571ef819d 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java @@ -4,7 +4,7 @@ package com.yahoo.documentmodel; import com.yahoo.document.DataType; import com.yahoo.document.Document; import com.yahoo.document.Field; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.StructuredDataType; import com.yahoo.document.TemporaryStructuredDataType; @@ -385,16 +385,12 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp } - private ReferenceDataType refToThis = null; + private NewDocumentReferenceDataType refToThis = null; @SuppressWarnings("deprecation") - public ReferenceDataType getReferenceDataType() { + public NewDocumentReferenceDataType getReferenceDataType() { if (refToThis == null) { - // super ugly, the APIs for this are horribly inconsistent - var tmptmp = TemporaryStructuredDataType.create(getName()); - var tmp = ReferenceDataType.createWithInferredId(tmptmp); - tmp.setTargetType((StructuredDataType) this); - refToThis = tmp; + refToThis = new NewDocumentReferenceDataType(this); } return refToThis; } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java index 2edf4e57105..16f60e40809 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java @@ -7,7 +7,7 @@ import com.yahoo.document.DataType; import com.yahoo.document.DocumentType; import com.yahoo.document.Field; import com.yahoo.document.MapDataType; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.StructuredDataType; import com.yahoo.document.TemporaryStructuredDataType; @@ -304,8 +304,8 @@ public class DocumentModelBuilder { type = new WeightedSetDataType(nt, c, r, t.getId()); } } - else if (type instanceof ReferenceDataType) { - ReferenceDataType t = (ReferenceDataType) type; + else if (type instanceof NewDocumentReferenceDataType) { + var t = (NewDocumentReferenceDataType) type; var tt = t.getTargetType(); var doc = getDocumentType(docs, tt.getId()); type = doc.getReferenceDataType(); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java index 14d4d67edfb..446187eed00 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java @@ -2,7 +2,7 @@ package com.yahoo.searchdefinition; import com.yahoo.document.Field; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.searchdefinition.document.SDDocumentType; import com.yahoo.searchdefinition.document.SDField; @@ -16,7 +16,7 @@ import static java.util.stream.Collectors.toMap; /** * Resolves all document references in the search definitions * - * Iterates through all document fields having a {@link ReferenceDataType} and uses {@link ReferenceDataType#getTargetType()} + * Iterates through all document fields having a {@link NewDocumentReferenceDataType} and uses {@link NewDocumentReferenceDataType#getTargetType()} * to determine the referenced document. This information is aggregated into a {@link DocumentReferences} object. * * @author bjorncs @@ -50,7 +50,7 @@ public class DocumentReferenceResolver { private Map<String, DocumentReference> createFieldToDocumentReferenceMapping(SDDocumentType documentType) { return fieldStream(documentType) - .filter(field -> field.getDataType() instanceof ReferenceDataType) + .filter(field -> field.getDataType() instanceof NewDocumentReferenceDataType) .collect(toMap(Field::getName, this::createDocumentReference)); } @@ -61,7 +61,7 @@ public class DocumentReferenceResolver { "The field '%s' is an invalid document reference. The field must be an attribute.", field.getName())); } - ReferenceDataType reference = (ReferenceDataType) field.getDataType(); + NewDocumentReferenceDataType reference = (NewDocumentReferenceDataType) field.getDataType(); String targetDocumentName = getTargetDocumentName(reference); Schema schema = schemaMapping.get(targetDocumentName); if (schema == null) { @@ -87,7 +87,7 @@ public class DocumentReferenceResolver { return documentType.getDocumentType().getFields().stream(); } - private static String getTargetDocumentName(ReferenceDataType reference) { + private static String getTargetDocumentName(NewDocumentReferenceDataType reference) { return reference.getTargetType().getName(); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java b/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java index 848631f1739..ece1b0bab0a 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/SDDocumentTypeOrderer.java @@ -4,6 +4,7 @@ package com.yahoo.searchdefinition; import com.yahoo.config.application.api.DeployLogger; import com.yahoo.document.*; import com.yahoo.document.annotation.AnnotationReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.documentmodel.NewDocumentType; import com.yahoo.searchdefinition.document.SDDocumentType; import com.yahoo.searchdefinition.document.TemporarySDDocumentType; @@ -133,7 +134,7 @@ public class SDDocumentTypeOrderer { //do nothing } else if (type instanceof TensorDataType) { //do nothing - } else if (type instanceof ReferenceDataType) { + } else if (type instanceof NewDocumentReferenceDataType) { //do nothing } else { deployLogger.logApplicationPackage(Level.WARNING, "Unknown type : " + type); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/SummaryClassField.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/SummaryClassField.java index 83ce2efb801..e9dd2ac321c 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/SummaryClassField.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/SummaryClassField.java @@ -4,7 +4,7 @@ package com.yahoo.searchdefinition.derived; import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; import com.yahoo.document.MapDataType; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.datatypes.BoolFieldValue; import com.yahoo.document.datatypes.ByteFieldValue; import com.yahoo.document.datatypes.DoubleFieldValue; @@ -118,7 +118,7 @@ public class SummaryClassField { } } else if (fieldType instanceof MapDataType) { return Type.JSONSTRING; - } else if (fieldType instanceof ReferenceDataType) { + } else if (fieldType instanceof NewDocumentReferenceDataType) { return Type.LONGSTRING; } else { throw new IllegalArgumentException("Don't know which summary type to convert " + fieldType + " to"); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/VsmFields.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/VsmFields.java index 3edc93fc7c7..c9ad8ad2838 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/VsmFields.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/VsmFields.java @@ -4,7 +4,7 @@ package com.yahoo.searchdefinition.derived; import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; import com.yahoo.document.NumericDataType; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.datatypes.BoolFieldValue; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.PredicateFieldValue; @@ -214,7 +214,7 @@ public class VsmFields extends Derived implements VsmfieldsConfig.Producer { return Type.UNSEARCHABLESTRING; } else if (fieldType instanceof CollectionDataType) { return convertType(((CollectionDataType) fieldType).getNestedType()); - } else if (fieldType instanceof ReferenceDataType) { + } else if (fieldType instanceof NewDocumentReferenceDataType) { return Type.UNSEARCHABLESTRING; } else { throw new IllegalArgumentException("Don't know which streaming field type to convert " + diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java index fce128d80f3..c592e4842a9 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java @@ -6,7 +6,7 @@ import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; import com.yahoo.document.DocumentType; import com.yahoo.document.PrimitiveDataType; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.StructuredDataType; import com.yahoo.document.TemporaryStructuredDataType; import com.yahoo.document.TensorDataType; @@ -255,6 +255,11 @@ public final class Attribute implements Cloneable, Serializable { /** Converts to the right attribute type from a field datatype */ public static Type convertDataType(DataType fieldType) { + if (fieldType instanceof NewDocumentReferenceDataType) { + return Type.REFERENCE; + } else if (fieldType instanceof CollectionDataType) { + return convertDataType(((CollectionDataType) fieldType).getNestedType()); + } FieldValue fval = fieldType.createFieldValue(); if (fval instanceof StringFieldValue) { return Type.STRING; @@ -278,13 +283,9 @@ public final class Attribute implements Cloneable, Serializable { return Type.PREDICATE; } else if (fval instanceof TensorFieldValue) { return Type.TENSOR; - } else if (fieldType instanceof CollectionDataType) { - return convertDataType(((CollectionDataType) fieldType).getNestedType()); - } else if (fieldType instanceof ReferenceDataType) { - return Type.REFERENCE; } else { - throw new IllegalArgumentException("Don't know which attribute type to " + - "convert " + fieldType + " to"); + throw new IllegalArgumentException("Don't know which attribute type to convert " + + fieldType + " [" + fieldType.getClass() + "] to"); } } @@ -298,7 +299,7 @@ public final class Attribute implements Cloneable, Serializable { return CollectionType.SINGLE; } else if (fieldType instanceof PrimitiveDataType) { return CollectionType.SINGLE; - } else if (fieldType instanceof ReferenceDataType) { + } else if (fieldType instanceof NewDocumentReferenceDataType) { return CollectionType.SINGLE; } else { throw new IllegalArgumentException("Field " + fieldType + " not supported in convertCollectionType"); @@ -312,9 +313,9 @@ public final class Attribute implements Cloneable, Serializable { private static Optional<StructuredDataType> convertTargetType(DataType fieldType) { return Optional.of(fieldType) - .filter(ReferenceDataType.class::isInstance) - .map(ReferenceDataType.class::cast) - .map(ReferenceDataType::getTargetType); + .filter(NewDocumentReferenceDataType.class::isInstance) + .map(NewDocumentReferenceDataType.class::cast) + .map(NewDocumentReferenceDataType::getTargetType); } /** Converts to the right field type from an attribute type */ @@ -342,9 +343,9 @@ public final class Attribute implements Cloneable, Serializable { } StructuredDataType type = referenceDocumentType.get(); if (type instanceof DocumentType) { - return ReferenceDataType.createWithInferredId((DocumentType) type); + return new NewDocumentReferenceDataType((DocumentType) type); } else { - return ReferenceDataType.createWithInferredId((TemporaryStructuredDataType) type); + return NewDocumentReferenceDataType.forDocumentName(type.getName()); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java index ed20bc0a94d..f628db85429 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java @@ -4,7 +4,7 @@ package com.yahoo.searchdefinition.parser; import com.yahoo.document.DataType; import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentTypeManager; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.PositionDataType; import com.yahoo.document.WeightedSetDataType; @@ -244,7 +244,7 @@ public class ConvertParsedTypes { private DataType createDocRef(ParsedType pType) { var ref = pType.getReferencedDocumentType(); assert(ref.getVariant() == ParsedType.Variant.DOCUMENT); - return ReferenceDataType.createWithInferredId(findDocFromSchemas(ref.name())); + return new NewDocumentReferenceDataType(findDocFromSchemas(ref.name())); } private DataType resolveFromContext(ParsedType pType, ParsedDocument context) { diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReferenceFieldsProcessor.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReferenceFieldsProcessor.java index 57833fecc7a..edb55dae5bf 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReferenceFieldsProcessor.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ReferenceFieldsProcessor.java @@ -2,7 +2,7 @@ package com.yahoo.searchdefinition.processing; import com.yahoo.config.application.api.DeployLogger; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.searchdefinition.RankProfileRegistry; import com.yahoo.searchdefinition.Schema; import com.yahoo.searchdefinition.document.SDField; @@ -36,14 +36,14 @@ public class ReferenceFieldsProcessor extends Processor { private void clearSummaryAttributeAspectForExplicitSummaryFields() { for (DocumentSummary docSum : schema.getSummaries().values()) { docSum.getSummaryFields().values().stream() - .filter(summaryField -> summaryField.getDataType() instanceof ReferenceDataType) + .filter(summaryField -> summaryField.getDataType() instanceof NewDocumentReferenceDataType) .forEach(summaryField -> summaryField.setTransform(SummaryTransform.NONE)); } } private void clearSummaryAttributeAspectForConcreteFields() { for (SDField field : schema.allConcreteFields()) { - if (field.getDataType() instanceof ReferenceDataType) { + if (field.getDataType() instanceof NewDocumentReferenceDataType) { removeFromAttributePrefetchSummaryClass(field); clearSummaryTransformOnSummaryFields(field); } diff --git a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java index 4dbeaef17ac..6f52a384a36 100644 --- a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java +++ b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java @@ -7,6 +7,7 @@ import com.yahoo.document.*; import com.yahoo.document.annotation.AnnotationReferenceDataType; import com.yahoo.document.annotation.AnnotationType; import com.yahoo.documentmodel.DataTypeCollection; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.documentmodel.NewDocumentType; import com.yahoo.documentmodel.VespaDocumentType; import com.yahoo.searchdefinition.document.FieldSet; @@ -172,8 +173,11 @@ public class DocumentManager { // Nothing to do; the type of the tensor is instead stored in each field as detailed type information // to provide better compatibility. A tensor field can have its tensorType changed (in compatible ways) // without changing the field type and thus requiring data refeed - } else if (type instanceof ReferenceDataType) { - ReferenceDataType refType = (ReferenceDataType) type; + } else if (type instanceof NewDocumentReferenceDataType) { + NewDocumentReferenceDataType refType = (NewDocumentReferenceDataType) type; + if (refType.isTemporary()) { + throw new IllegalArgumentException("Still temporary: " + refType); + } builder.referencetype(new Datatype.Referencetype.Builder().target_type_id(refType.getTargetType().getId())); } else { throw new IllegalArgumentException("Can not create config for data type " + type + " of class " + type.getClass()); @@ -356,8 +360,12 @@ public class DocumentManager { docTypeBuildOneType((AnnotationReferenceDataType) type, documentBuilder, indexMap); } else if (type instanceof TensorDataType) { docTypeBuildOneType((TensorDataType) type, documentBuilder, indexMap); - } else if (type instanceof ReferenceDataType) { - docTypeBuildOneType((ReferenceDataType) type, documentBuilder, indexMap); + } else if (type instanceof NewDocumentReferenceDataType) { + var refType = (NewDocumentReferenceDataType) type; + if (refType.isTemporary()) { + throw new IllegalArgumentException("Still temporary: " + refType); + } + docTypeBuildOneType(refType, documentBuilder, indexMap); } else if (type instanceof PrimitiveDataType) { docTypeBuildOneType((PrimitiveDataType) type, documentBuilder, indexMap); } else if (type instanceof DocumentType) { @@ -465,7 +473,7 @@ public class DocumentManager { .annotationtype(indexMap.idxOf(type.getAnnotationType()))); } - private void docTypeBuildOneType(ReferenceDataType type, + private void docTypeBuildOneType(NewDocumentReferenceDataType type, DocumentmanagerConfig.Doctype.Builder builder, IdxMap indexMap) { diff --git a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java index 1bd80988d58..2f0814bd664 100644 --- a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java +++ b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java @@ -6,6 +6,7 @@ import com.yahoo.document.config.DocumenttypesConfig; import com.yahoo.document.annotation.AnnotationReferenceDataType; import com.yahoo.document.annotation.AnnotationType; import com.yahoo.documentmodel.DataTypeCollection; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.documentmodel.NewDocumentType; import com.yahoo.documentmodel.VespaDocumentType; import com.yahoo.searchdefinition.document.FieldSet; @@ -125,8 +126,12 @@ public class DocumentTypes { // to provide better compatibility. A tensor field can have its tensorType changed (in compatible ways) // without changing the field type and thus requiring data refeed return; - } else if (type instanceof ReferenceDataType) { - buildConfig((ReferenceDataType) type, documentBuilder); + } else if (type instanceof NewDocumentReferenceDataType) { + var refType = (NewDocumentReferenceDataType) type; + if (refType.isTemporary()) { + throw new IllegalArgumentException("Still temporary: " + refType); + } + buildConfig(refType, documentBuilder); return; } else { return; @@ -213,9 +218,9 @@ public class DocumentTypes { id(type.getAnnotationType().getId()))); } - private void buildConfig(ReferenceDataType type, + private void buildConfig(NewDocumentReferenceDataType type, DocumenttypesConfig.Documenttype.Builder documentBuilder) { - ReferenceDataType refType = type; + NewDocumentReferenceDataType refType = type; DocumenttypesConfig.Documenttype.Referencetype.Builder refBuilder = new DocumenttypesConfig.Documenttype.Referencetype.Builder(); refBuilder.id(refType.getId()); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidator.java index 976ed0a0219..1379ba3fae9 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidator.java @@ -7,7 +7,7 @@ import com.yahoo.document.CollectionDataType; import com.yahoo.document.DataType; import com.yahoo.document.Field; import com.yahoo.document.MapDataType; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.TensorDataType; import com.yahoo.document.WeightedSetDataType; @@ -68,7 +68,7 @@ public class SearchDataTypeValidator extends Validator { return true; // Maps will work for summary, see disallowIndexingOfMaps() } else if (dataType instanceof TensorDataType) { return true; - } else if (dataType instanceof ReferenceDataType) { + } else if (dataType instanceof NewDocumentReferenceDataType) { return true; } else { return dataType.equals(DataType.INT) || diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java index dc5ffa7ecc7..4e3d2cbb61b 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java @@ -5,7 +5,7 @@ import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.model.deploy.DeployState; import com.yahoo.document.DataType; import com.yahoo.document.NumericDataType; -import com.yahoo.document.ReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.searchdefinition.document.Attribute; import com.yahoo.searchdefinition.document.ImmutableSDField; import com.yahoo.searchdefinition.document.Matching; @@ -75,7 +75,7 @@ public class StreamingValidator extends Validator { private static void failStreamingDocumentReferences(SearchCluster sc) { for (Attribute attribute : sc.getSdConfig().getAttributeFields().attributes()) { DataType dataType = attribute.getDataType(); - if (dataType instanceof ReferenceDataType) { + if (dataType instanceof NewDocumentReferenceDataType) { String errorMessage = String.format( "For streaming search cluster '%s': Attribute '%s' has type '%s'. " + "Document references and imported fields are not allowed in streaming search.", |