diff options
author | Arne Juul <arnej@vespa.ai> | 2023-11-01 08:09:00 +0000 |
---|---|---|
committer | Arne Juul <arnej@vespa.ai> | 2023-11-01 08:20:59 +0000 |
commit | 9b3f08769c295f0e8d4d506393ebece8e7651f43 (patch) | |
tree | 36d1171bcc614876b46d15de673c272f5f2134f5 /config-model/src/main/java/com | |
parent | ef89054d86570de1934d34e880b4827a310b9269 (diff) |
validate for array/wset attributes
Diffstat (limited to 'config-model/src/main/java/com')
-rw-r--r-- | config-model/src/main/java/com/yahoo/schema/RankProfile.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/RankProfile.java b/config-model/src/main/java/com/yahoo/schema/RankProfile.java index 1ff85c9c89f..188918e99e5 100644 --- a/config-model/src/main/java/com/yahoo/schema/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/schema/RankProfile.java @@ -1265,14 +1265,34 @@ public class RankProfile implements Cloneable { return Optional.empty(); // if this context does not contain this input } + private static class AttributeErrorType extends TensorType { + private final String attr; + private final Attribute.CollectionType collType; + AttributeErrorType(String attr, Attribute.CollectionType collType) { + super(TensorType.Value.INT8, List.of()); + this.attr = attr; + this.collType = collType; + } + private void doThrow() { + throw new IllegalArgumentException("Cannot use attribute(" + attr +") " + collType + " as ranking expression input"); + } + @Override public TensorType.Value valueType() { doThrow(); return null; } + @Override public int rank() { doThrow(); return 0; } + @Override public List<TensorType.Dimension> dimensions() { doThrow(); return null; } + } + private void addAttributeFeatureTypes(ImmutableSDField field, Map<Reference, TensorType> featureTypes) { Attribute attribute = field.getAttribute(); field.getAttributes().forEach((k, a) -> { String name = k; if (attribute == a) // this attribute should take the fields name name = field.getName(); // switch to that - it is separate for imported fields - featureTypes.put(FeatureNames.asAttributeFeature(name), - a.tensorType().orElse(TensorType.empty)); + if (a.getCollectionType().equals(Attribute.CollectionType.SINGLE)) { + featureTypes.put(FeatureNames.asAttributeFeature(name), + a.tensorType().orElse(TensorType.empty)); + } else { + featureTypes.put(FeatureNames.asAttributeFeature(name), new AttributeErrorType(name, a.getCollectionType())); + } }); } |