summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahooinc.com>2023-03-17 15:01:11 +0100
committerGitHub <noreply@github.com>2023-03-17 15:01:11 +0100
commitedcdc5e2869033f8219ad21204adb2a1bc12c388 (patch)
tree52e2c69778d95021bc976824074503881a18eb7a
parent0ee0a814b61bb356a8ee526189bcdb57cda003f2 (diff)
parentca0eb55932187dcd4ae8fb17669acfd60b6ee13b (diff)
Merge pull request #26478 from vespa-engine/toregge/config-model-raw-attribute
Add raw attributes to config model.
-rw-r--r--config-model/src/main/java/com/yahoo/schema/document/Attribute.java6
-rw-r--r--config-model/src/main/java/com/yahoo/schema/processing/Processing.java2
-rw-r--r--config-model/src/main/java/com/yahoo/schema/processing/SingleValueOnlyAttributeValidator.java (renamed from config-model/src/main/java/com/yahoo/schema/processing/BoolAttributeValidator.java)9
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java50
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/SingleValueOnlyAttributeValidatorTestCase.java73
5 files changed, 83 insertions, 57 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/document/Attribute.java b/config-model/src/main/java/com/yahoo/schema/document/Attribute.java
index 34e86cbf4a8..70fcf64dff3 100644
--- a/config-model/src/main/java/com/yahoo/schema/document/Attribute.java
+++ b/config-model/src/main/java/com/yahoo/schema/document/Attribute.java
@@ -100,7 +100,8 @@ public final class Attribute implements Cloneable, Serializable {
BOOL("bool", "BOOL"),
PREDICATE("predicate", "PREDICATE"),
TENSOR("tensor", "TENSOR"),
- REFERENCE("reference", "REFERENCE");
+ REFERENCE("reference", "REFERENCE"),
+ RAW("raw", "RAW");
private final String myName; // different from what name() returns.
private final String exportAttributeTypeName;
@@ -290,7 +291,7 @@ public final class Attribute implements Cloneable, Serializable {
} else if (fval instanceof ByteFieldValue) {
return Type.BYTE;
} else if (fval instanceof Raw) {
- return Type.BYTE;
+ return Type.RAW;
} else if (fval instanceof PredicateFieldValue) {
return Type.PREDICATE;
} else if (fval instanceof TensorFieldValue) {
@@ -344,6 +345,7 @@ public final class Attribute implements Cloneable, Serializable {
case PREDICATE -> DataType.PREDICATE;
case TENSOR -> DataType.getTensor(tensorType.orElseThrow(IllegalStateException::new));
case REFERENCE-> createReferenceDataType();
+ case RAW -> DataType.RAW;
default -> throw new IllegalArgumentException("Unknown attribute type " + attributeType);
};
}
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/Processing.java b/config-model/src/main/java/com/yahoo/schema/processing/Processing.java
index 8f7e8daeed0..df4b0d0d941 100644
--- a/config-model/src/main/java/com/yahoo/schema/processing/Processing.java
+++ b/config-model/src/main/java/com/yahoo/schema/processing/Processing.java
@@ -89,7 +89,7 @@ public class Processing {
OnnxModelConfigGenerator::new,
OnnxModelTypeResolver::new,
RankingExpressionTypeResolver::new,
- BoolAttributeValidator::new,
+ SingleValueOnlyAttributeValidator::new,
PagedAttributeValidator::new,
// These should be last:
IndexingValidation::new,
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/BoolAttributeValidator.java b/config-model/src/main/java/com/yahoo/schema/processing/SingleValueOnlyAttributeValidator.java
index bdb1eed4b10..b2786e6c785 100644
--- a/config-model/src/main/java/com/yahoo/schema/processing/BoolAttributeValidator.java
+++ b/config-model/src/main/java/com/yahoo/schema/processing/SingleValueOnlyAttributeValidator.java
@@ -14,9 +14,9 @@ import com.yahoo.vespa.model.container.search.QueryProfiles;
*
* @author geirst
*/
-public class BoolAttributeValidator extends Processor {
+public class SingleValueOnlyAttributeValidator extends Processor {
- public BoolAttributeValidator(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
+ public SingleValueOnlyAttributeValidator(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(schema, deployLogger, rankProfileRegistry, queryProfiles);
}
@@ -27,9 +27,10 @@ public class BoolAttributeValidator extends Processor {
if (attribute == null) {
continue;
}
- if (attribute.getType().equals(Attribute.Type.BOOL) &&
+ if ((attribute.getType().equals(Attribute.Type.BOOL) ||
+ attribute.getType().equals(Attribute.Type.RAW)) &&
!attribute.getCollectionType().equals(Attribute.CollectionType.SINGLE)) {
- fail(schema, field, "Only single value bool attribute fields are supported");
+ fail(schema, field, "Only single value " + attribute.getType().getName() + " attribute fields are supported");
}
}
}
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java
deleted file mode 100644
index f19b1f43115..00000000000
--- a/config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// 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.schema.parser.ParseException;
-import org.junit.jupiter.api.Test;
-
-import static com.yahoo.schema.ApplicationBuilder.createFromString;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static com.yahoo.config.model.test.TestUtil.joinLines;
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * @author geirst
- */
-public class BoolAttributeValidatorTestCase {
-
- @Test
- void array_of_bool_attribute_is_not_supported() throws ParseException {
- try {
- createFromString(getSd("field b type array<bool> { indexing: attribute }"));
- fail("Expected exception");
- }
- catch (IllegalArgumentException e) {
- assertEquals("For schema 'test', field 'b': Only single value bool attribute fields are supported",
- e.getMessage());
- }
- }
-
- @Test
- void weigtedset_of_bool_attribute_is_not_supported() throws ParseException {
- try {
- createFromString(getSd("field b type weightedset<bool> { indexing: attribute }"));
- fail("Expected exception");
- }
- catch (IllegalArgumentException e) {
- assertEquals("For schema 'test', field 'b': Only single value bool attribute fields are supported",
- e.getMessage());
- }
- }
-
- private String getSd(String field) {
- return joinLines(
- "schema test {",
- " document test {",
- " " + field,
- " }",
- "}");
- }
-
-}
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/SingleValueOnlyAttributeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/SingleValueOnlyAttributeValidatorTestCase.java
new file mode 100644
index 00000000000..a7f4125a537
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/schema/processing/SingleValueOnlyAttributeValidatorTestCase.java
@@ -0,0 +1,73 @@
+// 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.schema.parser.ParseException;
+import org.junit.jupiter.api.Test;
+
+import static com.yahoo.schema.ApplicationBuilder.createFromString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static com.yahoo.config.model.test.TestUtil.joinLines;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * @author geirst
+ */
+public class SingleValueOnlyAttributeValidatorTestCase {
+
+ private static void array_attribute_is_not_supported(String type) throws ParseException {
+ try {
+ createFromString(getSd("field b type array<" + type + "> { indexing: attribute }"));
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'test', field 'b': Only single value " + type + " attribute fields are supported",
+ e.getMessage());
+ }
+ }
+
+ private static void weightedset_attribute_is_not_supported(String type) throws ParseException {
+ try {
+ createFromString(getSd("field b type weightedset<" + type + "> { indexing: attribute }"));
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ if (type.equals("raw")) {
+ assertEquals("weightedset of complex type '[type BUILTIN] {raw}' is not supported",
+ e.getMessage());
+ } else {
+ assertEquals("For schema 'test', field 'b': Only single value " + type + " attribute fields are supported",
+ e.getMessage());
+ }
+ }
+ }
+
+ @Test
+ void array_of_bool_attribute_is_not_supported() throws ParseException {
+ array_attribute_is_not_supported("bool");
+ }
+
+ @Test
+ void weightedset_of_bool_attribute_is_not_supported() throws ParseException {
+ weightedset_attribute_is_not_supported("bool");
+ }
+
+ @Test
+ void array_of_raw_attribute_is_not_supported() throws ParseException {
+ array_attribute_is_not_supported("raw");
+ }
+
+ @Test
+ void weightedset_of_raw_attribute_is_not_supported() throws ParseException {
+ weightedset_attribute_is_not_supported("raw");
+ }
+
+ private static String getSd(String field) {
+ return joinLines(
+ "schema test {",
+ " document test {",
+ " " + field,
+ " }",
+ "}");
+ }
+
+}