diff options
5 files changed, 161 insertions, 33 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java index 9cbb4479778..1775c69f669 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java @@ -29,6 +29,7 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce public enum FieldSet {ALL, FAST_ACCESS} private Map<String, Attribute> attributes = new java.util.LinkedHashMap<>(); + private Map<String, Attribute> importedAttributes = new java.util.LinkedHashMap<>(); /** * Flag indicating if a position-attribute has been found @@ -51,9 +52,10 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce return; // Ignore struct fields for indexed search (only implemented for streaming search) } if (field.isImportedField()) { - return; // Ignore imported fields + deriveImportedAttributes(field); + } else { + deriveAttributes(field); } - deriveAttributes(field); } /** @@ -67,18 +69,6 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce return getAttribute(attributeName) != null; } - private void deriveAttribute(ImmutableSDField field, Attribute fieldAttribute) { - Attribute attribute = getAttribute(fieldAttribute.getName()); - if (attribute == null) { - attributes.put(fieldAttribute.getName(), fieldAttribute); - attribute = getAttribute(fieldAttribute.getName()); - } - Ranking ranking = field.getRanking(); - if (ranking != null && ranking.isFilter()) { - attribute.setEnableBitVectors(true); - attribute.setEnableOnlyBitVector(true); - } - } /** * Derives one attribute. TODO: Support non-default named attributes */ @@ -96,6 +86,27 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce } } + private void deriveAttribute(ImmutableSDField field, Attribute fieldAttribute) { + Attribute attribute = getAttribute(fieldAttribute.getName()); + if (attribute == null) { + attributes.put(fieldAttribute.getName(), fieldAttribute); + attribute = getAttribute(fieldAttribute.getName()); + } + Ranking ranking = field.getRanking(); + if (ranking != null && ranking.isFilter()) { + attribute.setEnableBitVectors(true); + attribute.setEnableOnlyBitVector(true); + } + } + + private void deriveImportedAttributes(ImmutableSDField field) { + for (Attribute attribute : field.getAttributes().values()) { + if (!importedAttributes.containsKey(field.getName())) { + importedAttributes.put(field.getName(), attribute); + } + } + } + /** * Returns a read only attribute iterator */ @@ -133,7 +144,7 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce return (fs == FieldSet.ALL) || ((fs == FieldSet.FAST_ACCESS) && attribute.isFastAccess()); } - private AttributesConfig.Attribute.Builder getConfig(Attribute attribute) { + private AttributesConfig.Attribute.Builder getConfig(Attribute attribute, boolean imported) { AttributesConfig.Attribute.Builder aaB = new AttributesConfig.Attribute.Builder() .name(attribute.getName()) .datatype(AttributesConfig.Attribute.Datatype.Enum.valueOf(attribute.getType().getExportAttributeTypeName())) @@ -174,13 +185,19 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce if (attribute.tensorType().isPresent()) { aaB.tensortype(attribute.tensorType().get().toString()); } + aaB.imported(imported); return aaB; } public void getConfig(AttributesConfig.Builder builder, FieldSet fs) { for (Attribute attribute : attributes.values()) { if (isAttributeInFieldSet(attribute, fs)) { - builder.attribute(getConfig(attribute)); + builder.attribute(getConfig(attribute, false)); + } + } + if (fs == FieldSet.ALL) { + for (Attribute attribute : importedAttributes.values()) { + builder.attribute(getConfig(attribute, true)); } } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/ImportedFields.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/ImportedFields.java index 5fb73445879..cfe33ef019f 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/ImportedFields.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/ImportedFields.java @@ -46,21 +46,10 @@ public class ImportedFields extends Derived implements ImportedFieldsConfig.Prod private static ImportedFieldsConfig.Attribute.Builder createAttributeBuilder(ImportedField field) { ImportedFieldsConfig.Attribute.Builder result = new ImportedFieldsConfig.Attribute.Builder(); - Attribute targetAttribute = field.targetField().getAttributes().get(field.targetField().getName()); result.name(field.fieldName()); result.referencefield(field.reference().referenceField().getName()); result.targetfield(field.targetField().getName()); - result.datatype(getDataType(targetAttribute)); - result.collectiontype(getCollectionType(targetAttribute)); return result; } - private static ImportedFieldsConfig.Attribute.Datatype.Enum getDataType(Attribute targetAttribute) { - return ImportedFieldsConfig.Attribute.Datatype.Enum.valueOf(targetAttribute.getType().getExportAttributeTypeName()); - } - - private static ImportedFieldsConfig.Attribute.Collectiontype.Enum getCollectionType(Attribute targetAttribute) { - return ImportedFieldsConfig.Attribute.Collectiontype.Enum.valueOf(targetAttribute.getCollectionType().getName()); - } - } diff --git a/config-model/src/test/derived/importedfields/attributes.cfg b/config-model/src/test/derived/importedfields/attributes.cfg new file mode 100644 index 00000000000..df0dd4f8ac4 --- /dev/null +++ b/config-model/src/test/derived/importedfields/attributes.cfg @@ -0,0 +1,120 @@ +attribute[].name "a_ref" +attribute[].datatype REFERENCE +attribute[].collectiontype SINGLE +attribute[].removeifzero false +attribute[].createifnonexistent false +attribute[].fastsearch false +attribute[].huge false +attribute[].sortascending true +attribute[].sortfunction UCA +attribute[].sortstrength PRIMARY +attribute[].sortlocale "" +attribute[].enablebitvectors false +attribute[].enableonlybitvector false +attribute[].fastaccess false +attribute[].arity 8 +attribute[].lowerbound -9223372036854775808 +attribute[].upperbound 9223372036854775807 +attribute[].densepostinglistthreshold 0.4 +attribute[].tensortype "" +attribute[].imported false +attribute[].name "b_ref" +attribute[].datatype REFERENCE +attribute[].collectiontype SINGLE +attribute[].removeifzero false +attribute[].createifnonexistent false +attribute[].fastsearch false +attribute[].huge false +attribute[].sortascending true +attribute[].sortfunction UCA +attribute[].sortstrength PRIMARY +attribute[].sortlocale "" +attribute[].enablebitvectors false +attribute[].enableonlybitvector false +attribute[].fastaccess false +attribute[].arity 8 +attribute[].lowerbound -9223372036854775808 +attribute[].upperbound 9223372036854775807 +attribute[].densepostinglistthreshold 0.4 +attribute[].tensortype "" +attribute[].imported false +attribute[].name "int_field" +attribute[].datatype INT32 +attribute[].collectiontype SINGLE +attribute[].removeifzero false +attribute[].createifnonexistent false +attribute[].fastsearch false +attribute[].huge false +attribute[].sortascending true +attribute[].sortfunction UCA +attribute[].sortstrength PRIMARY +attribute[].sortlocale "" +attribute[].enablebitvectors false +attribute[].enableonlybitvector false +attribute[].fastaccess false +attribute[].arity 8 +attribute[].lowerbound -9223372036854775808 +attribute[].upperbound 9223372036854775807 +attribute[].densepostinglistthreshold 0.4 +attribute[].tensortype "" +attribute[].imported true +attribute[].name "string_field" +attribute[].datatype STRING +attribute[].collectiontype SINGLE +attribute[].removeifzero false +attribute[].createifnonexistent false +attribute[].fastsearch false +attribute[].huge false +attribute[].sortascending true +attribute[].sortfunction UCA +attribute[].sortstrength PRIMARY +attribute[].sortlocale "" +attribute[].enablebitvectors false +attribute[].enableonlybitvector false +attribute[].fastaccess false +attribute[].arity 8 +attribute[].lowerbound -9223372036854775808 +attribute[].upperbound 9223372036854775807 +attribute[].densepostinglistthreshold 0.4 +attribute[].tensortype "" +attribute[].imported true +attribute[].name "int_array_field" +attribute[].datatype INT32 +attribute[].collectiontype ARRAY +attribute[].removeifzero false +attribute[].createifnonexistent false +attribute[].fastsearch false +attribute[].huge false +attribute[].sortascending true +attribute[].sortfunction UCA +attribute[].sortstrength PRIMARY +attribute[].sortlocale "" +attribute[].enablebitvectors false +attribute[].enableonlybitvector false +attribute[].fastaccess false +attribute[].arity 8 +attribute[].lowerbound -9223372036854775808 +attribute[].upperbound 9223372036854775807 +attribute[].densepostinglistthreshold 0.4 +attribute[].tensortype "" +attribute[].imported true +attribute[].name "int_wset_field" +attribute[].datatype INT32 +attribute[].collectiontype WEIGHTEDSET +attribute[].removeifzero false +attribute[].createifnonexistent false +attribute[].fastsearch false +attribute[].huge false +attribute[].sortascending true +attribute[].sortfunction UCA +attribute[].sortstrength PRIMARY +attribute[].sortlocale "" +attribute[].enablebitvectors false +attribute[].enableonlybitvector false +attribute[].fastaccess false +attribute[].arity 8 +attribute[].lowerbound -9223372036854775808 +attribute[].upperbound 9223372036854775807 +attribute[].densepostinglistthreshold 0.4 +attribute[].tensortype "" +attribute[].imported true diff --git a/config-model/src/test/derived/importedfields/imported-fields.cfg b/config-model/src/test/derived/importedfields/imported-fields.cfg index 48eb8a58af3..3f2a083bdc2 100644 --- a/config-model/src/test/derived/importedfields/imported-fields.cfg +++ b/config-model/src/test/derived/importedfields/imported-fields.cfg @@ -1,20 +1,20 @@ attribute[].name "my_int_field" attribute[].referencefield "a_ref" attribute[].targetfield "int_field" -attribute[].datatype INT32 +attribute[].datatype NONE attribute[].collectiontype SINGLE attribute[].name "my_string_field" attribute[].referencefield "b_ref" attribute[].targetfield "string_field" -attribute[].datatype STRING +attribute[].datatype NONE attribute[].collectiontype SINGLE attribute[].name "my_int_array_field" attribute[].referencefield "a_ref" attribute[].targetfield "int_array_field" -attribute[].datatype INT32 -attribute[].collectiontype ARRAY +attribute[].datatype NONE +attribute[].collectiontype SINGLE attribute[].name "my_int_wset_field" attribute[].referencefield "a_ref" attribute[].targetfield "int_wset_field" -attribute[].datatype INT32 -attribute[].collectiontype WEIGHTEDSET +attribute[].datatype NONE +attribute[].collectiontype SINGLE diff --git a/configdefinitions/src/vespa/imported-fields.def b/configdefinitions/src/vespa/imported-fields.def index ad895b3bdbf..051226f1615 100644 --- a/configdefinitions/src/vespa/imported-fields.def +++ b/configdefinitions/src/vespa/imported-fields.def @@ -10,9 +10,11 @@ attribute[].referencefield string # The name of the target attribute field in the parent document type that is imported into this document type. attribute[].targetfield string +# Deprecated. TODO: Remove when going to Vespa 7. # The data type of the target attribute field. This enum should match the one in attributes.def. attribute[].datatype enum { STRING, UINT1, UINT2, UINT4, INT8, INT16, INT32, INT64, FLOAT, DOUBLE, PREDICATE, TENSOR, REFERENCE, NONE } default=NONE +# Deprecated. TODO: Remove when going to Vespa 7. # The collection type of the target attribute field. This enum should match the one in attributes.def. attribute[].collectiontype enum { SINGLE, ARRAY, WEIGHTEDSET } default=SINGLE |