summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2023-11-01 20:02:04 +0000
committerArne Juul <arnej@yahooinc.com>2023-11-01 20:52:35 +0000
commit464d372e8f95b4a56d54957d32f2c5c5641a4c39 (patch)
tree0dbdcbdb5cb95c6f0b6ca8a08030a17630cbfe67 /config-model/src/main/java/com
parent3f1a122dc2cdeecf0a1356a18dfe6a46a7f9c2f3 (diff)
validate for array/wset attributes, take 2:
* ensure attribute(arrayfield).count does not trigger validation * log warning via deploylogger instead of throwing exception
Diffstat (limited to 'config-model/src/main/java/com')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/FeatureNames.java1
-rw-r--r--config-model/src/main/java/com/yahoo/schema/RankProfile.java35
2 files changed, 34 insertions, 2 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/FeatureNames.java b/config-model/src/main/java/com/yahoo/schema/FeatureNames.java
index ab2e63aa469..c0f40cedea2 100644
--- a/config-model/src/main/java/com/yahoo/schema/FeatureNames.java
+++ b/config-model/src/main/java/com/yahoo/schema/FeatureNames.java
@@ -27,6 +27,7 @@ public class FeatureNames {
/** Returns true if the given reference is an attribute, constant or query feature */
public static boolean isSimpleFeature(Reference reference) {
if ( ! reference.isSimple()) return false;
+ if (reference.output() != null) return false;
String name = reference.name();
return name.equals("attribute") || name.equals("constant") || name.equals("query");
}
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..3d64252f56a 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,45 @@ public class RankProfile implements Cloneable {
return Optional.empty(); // if this context does not contain this input
}
+ private static class AttributeErrorType extends TensorType {
+ private final DeployLogger deployLogger;
+ private final String attr;
+ private final Attribute.CollectionType collType;
+ private boolean shouldWarn = true;
+ AttributeErrorType(DeployLogger deployLogger, String attr, Attribute.CollectionType collType) {
+ super(TensorType.Value.DOUBLE, List.of());
+ this.deployLogger = deployLogger;
+ this.attr = attr;
+ this.collType = collType;
+ }
+ private void warnOnce() {
+ if (shouldWarn) {
+ deployLogger.log(Level.WARNING, "Using attribute(" + attr +") " + collType + " as ranking expression input");
+ shouldWarn = false;
+ }
+ }
+ @Override public TensorType.Value valueType() { warnOnce(); return super.valueType(); }
+ @Override public int rank() { warnOnce(); return super.rank(); }
+ @Override public List<TensorType.Dimension> dimensions() { warnOnce(); return super.dimensions(); }
+ @Override public boolean equals(Object o) {
+ if (o instanceof TensorType other) {
+ return (other.rank() == 0);
+ }
+ return false;
+ }
+ }
+
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(deployLogger, name, a.getCollectionType()));
+ }
});
}