diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-06-08 14:38:54 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-06-08 14:38:54 +0200 |
commit | 0b1348868b7b4ec23925b20bd7bea4fa5f0d53e2 (patch) | |
tree | 5c7fe757a5cb8db218fa1eac16872d70bf6f9019 /config-model | |
parent | e060beabc75b7db1424d168ee3513f5a5692a101 (diff) |
Disallow unbound tensor dimensions in query profile fields
Diffstat (limited to 'config-model')
2 files changed, 9 insertions, 1 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/QueryProfiles.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/QueryProfiles.java index 0a9618e7b08..079baf6fe7d 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/QueryProfiles.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/QueryProfiles.java @@ -9,6 +9,7 @@ import com.yahoo.search.query.profile.SubstituteString; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.query.profile.config.QueryProfilesConfig; +import com.yahoo.tensor.TensorType; import java.io.Serializable; import java.util.ArrayList; @@ -56,6 +57,7 @@ public class QueryProfiles implements Serializable, QueryProfilesConfig.Producer Set<String> tensorFields = new HashSet<>(); for (QueryProfileType type : registry.getTypeRegistry().allComponents()) { for (var fieldEntry : type.fields().entrySet()) { + validateTensorField(fieldEntry.getKey(), fieldEntry.getValue().getType().asTensorType()); if (fieldEntry.getValue().getType().asTensorType().rank() > 0) tensorFields.add(fieldEntry.getKey()); } @@ -73,6 +75,12 @@ public class QueryProfiles implements Serializable, QueryProfilesConfig.Producer } + private void validateTensorField(String fieldName, TensorType type) { + if (type.dimensions().stream().anyMatch(d -> d.isIndexed() && d.size().isEmpty())) + throw new IllegalArgumentException("Illegal type in field " + fieldName + " type " + type + + ": Dense tensor dimensions must have a size"); + } + @Override public void getConfig(QueryProfilesConfig.Builder builder) { for (QueryProfile profile : registry.allComponents()) { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java index e4ca83640e9..35679ffa762 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionShadowingTestCase.java @@ -159,7 +159,7 @@ public class RankingExpressionShadowingTestCase extends SchemaTestCase { public void testNeuralNetworkSetup() throws ParseException { // Note: the type assigned to query profile and constant tensors here is not the correct type RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); - QueryProfileRegistry queryProfiles = queryProfileWith("query(q)", "tensor(x[])"); + QueryProfileRegistry queryProfiles = queryProfileWith("query(q)", "tensor(x[1])"); SearchBuilder builder = new SearchBuilder(rankProfileRegistry, queryProfiles); builder.importString( "search test {\n" + |