From 62a65a21ae3defcfe1352d9536a3571dcedad320 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 10 Oct 2022 15:44:55 +0200 Subject: Allow paged setting for tensor attributes without fast-rank setting. --- .../schema/processing/PagedAttributeValidator.java | 8 ++--- .../PagedAttributeValidatorTestCase.java | 34 +++++++++++++++------- 2 files changed, 28 insertions(+), 14 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 index 793505acd01..6f470cfdc56 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/PagedAttributeValidator.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/PagedAttributeValidator.java @@ -41,19 +41,19 @@ public class PagedAttributeValidator extends Processor { 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"); + fail(schema, field, "The 'paged' attribute setting is not supported for fast-rank tensor and predicate types"); } } private boolean isSupportedType(Attribute attribute) { var type = attribute.getType(); return (type != Attribute.Type.PREDICATE) && - (isSupportedTensorType(attribute.tensorType())); + (isSupportedTensorType(attribute.tensorType(), attribute.isFastRank())); } - private boolean isSupportedTensorType(Optional tensorType) { + private boolean isSupportedTensorType(Optional tensorType, boolean fastRank) { if (tensorType.isPresent()) { - return isDenseTensorType(tensorType.get()); + return !fastRank; } return true; } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java index 719db2ffdcc..9de44d28c09 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java @@ -71,8 +71,13 @@ public class PagedAttributeValidatorTestCase { } @Test - void non_dense_tensor_attribute_does_not_support_paged_setting() throws ParseException { - assertPagedSettingNotSupported("tensor(x{},y[2])"); + void non_dense_none_fast_rank_tensor_attribute_supports_paged_setting() throws ParseException { + assertPagedSupported("tensor(x{},y[2])"); + } + + @Test + void non_dense_fast_rank_tensor_attribute_does_not_support_paged_setting() throws ParseException { + assertPagedSettingNotSupported("tensor(x{},y[2])", true); } @Test @@ -82,36 +87,45 @@ public class PagedAttributeValidatorTestCase { @Test void reference_attribute_support_paged_setting() throws ParseException { - assertPagedSupported("reference", Optional.of(getSd("parent", "int"))); + assertPagedSupported("reference", Optional.of(getSd("parent", "int", false))); } private void assertPagedSettingNotSupported(String fieldType) throws ParseException { - assertPagedSettingNotSupported(fieldType, Optional.empty()); + assertPagedSettingNotSupported(fieldType, false); + } + + private void assertPagedSettingNotSupported(String fieldType, boolean fastRank) throws ParseException { + assertPagedSettingNotSupported(fieldType, fastRank, Optional.empty()); } - private void assertPagedSettingNotSupported(String fieldType, Optional parentSd) throws ParseException { + private void assertPagedSettingNotSupported(String fieldType, boolean fastRank, Optional parentSd) throws ParseException { try { if (parentSd.isPresent()) { - createFromStrings(new BaseDeployLogger(), parentSd.get(), getSd(fieldType)); + createFromStrings(new BaseDeployLogger(), parentSd.get(), getSd(fieldType, fastRank)); } else { - createFromString(getSd(fieldType)); + createFromString(getSd(fieldType, fastRank)); } fail("Expected exception"); } catch (IllegalArgumentException e) { - assertEquals("For schema 'test', field 'foo': The 'paged' attribute setting is not supported for non-dense tensor, predicate and reference types", + assertEquals("For schema 'test', field 'foo': The 'paged' attribute setting is not supported for fast-rank tensor and predicate types", e.getMessage()); } } private String getSd(String fieldType) { - return getSd("test", fieldType); + return getSd(fieldType, false); + } + + private String getSd(String fieldType, boolean fastRank) { + return getSd("test", fieldType, fastRank); } - private String getSd(String docType, String fieldType) { + private String getSd(String docType, String fieldType, boolean fastRank) { return joinLines( "schema " + docType + " {", " document " + docType + " {", " field foo type " + fieldType + "{", + (fastRank ? "attribute: fast-rank" : ""), " indexing: attribute", " attribute: paged", " }", -- cgit v1.2.3