diff options
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema/processing/PagedAttributeValidator.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/schema/processing/PagedAttributeValidator.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/PagedAttributeValidator.java b/config-model/src/main/java/com/yahoo/schema/processing/PagedAttributeValidator.java new file mode 100644 index 00000000000..34bb6e1db2e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/schema/processing/PagedAttributeValidator.java @@ -0,0 +1,66 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.schema.processing; + +import com.yahoo.config.application.api.DeployLogger; +import com.yahoo.document.Field; +import com.yahoo.schema.RankProfileRegistry; +import com.yahoo.schema.Schema; +import com.yahoo.schema.document.Attribute; +import com.yahoo.tensor.TensorType; +import com.yahoo.vespa.model.container.search.QueryProfiles; + +import java.util.Optional; + +/** + * Validates the 'paged' attribute setting and throws if specified on unsupported types. + * + * @author geirst + */ +public class PagedAttributeValidator extends Processor { + + public PagedAttributeValidator(Schema schema, + DeployLogger deployLogger, + RankProfileRegistry rankProfileRegistry, + QueryProfiles queryProfiles) { + super(schema, deployLogger, rankProfileRegistry, queryProfiles); + } + + @Override + public void process(boolean validate, boolean documentsOnly) { + if (!validate) { + return; + } + for (var field : schema.allConcreteFields()) { + for (var attribute : field.getAttributes().values()) { + if (attribute.isPaged()) { + validatePagedSetting(field, attribute); + } + } + } + } + + private void validatePagedSetting(Field field, Attribute attribute) { + if (!isSupportedType(attribute)) { + fail(schema, field, "The 'paged' attribute setting is not supported for non-dense tensor, predicate and reference types"); + } + } + + private boolean isSupportedType(Attribute attribute) { + var type = attribute.getType(); + return (type != Attribute.Type.PREDICATE) && + (type != Attribute.Type.REFERENCE) && + (isSupportedTensorType(attribute.tensorType())); + } + + private boolean isSupportedTensorType(Optional<TensorType> tensorType) { + if (tensorType.isPresent()) { + return isDenseTensorType(tensorType.get()); + } + return true; + } + + private boolean isDenseTensorType(TensorType type) { + return type.dimensions().stream().allMatch(d -> d.isIndexed()); + } + +} |