aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahooinc.com>2021-12-10 11:05:54 +0000
committerArne H Juul <arnej@yahooinc.com>2021-12-13 13:12:21 +0000
commit7187dafb2b9fadc11f49844b637723df36aa3e3e (patch)
tree0e282cc87ed8a9cb624faf6e2d54c3fee195aedf /config-model/src/main/java/com/yahoo/searchdefinition
parent82397b67bcbe865283cece305037577294a86fa2 (diff)
try to make simple struct inherit work
* inheritance was just lost in conversion * with unit test
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java7
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java1
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/ValidateStructTypeInheritance.java66
3 files changed, 74 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java
index 70f3403520b..55f24123940 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java
@@ -390,6 +390,13 @@ public class DocumentModelBuilder {
throw new IllegalArgumentException("Data type '" + sdoc.getName() + "' is not a struct => tostring='" + sdoc.toString() + "'.");
}
}
+ for (SDDocumentType type : sdoc.getTypes()) {
+ for (SDDocumentType proxy : type.getInheritedTypes()) {
+ var inherited = dt.getDataTypeRecursive(proxy.getName());
+ var converted = (StructDataType) dt.getDataType(type.getName());
+ converted.inherit((StructDataType) inherited);
+ }
+ }
for (AnnotationType annotation : sdoc.getAnnotations().values()) {
dt.add(annotation);
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
index a484476e978..34472616a78 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
@@ -79,6 +79,7 @@ public class Processing {
OnnxModelConfigGenerator::new,
OnnxModelTypeResolver::new,
RankingExpressionTypeResolver::new,
+ ValidateStructTypeInheritance::new,
BoolAttributeValidator::new,
PagedAttributeValidator::new,
// These should be last:
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ValidateStructTypeInheritance.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ValidateStructTypeInheritance.java
new file mode 100644
index 00000000000..6b4ffa33136
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ValidateStructTypeInheritance.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.searchdefinition.processing;
+
+import com.yahoo.searchdefinition.Schema;
+import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.searchdefinition.RankProfileRegistry;
+import com.yahoo.vespa.model.container.search.QueryProfiles;
+
+import com.yahoo.document.DataType;
+import com.yahoo.document.Field;
+import com.yahoo.document.StructDataType;
+import com.yahoo.searchdefinition.document.SDDocumentType;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author arnej
+ */
+public class ValidateStructTypeInheritance extends Processor {
+
+ public ValidateStructTypeInheritance(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
+ super(schema, deployLogger, rankProfileRegistry, queryProfiles);
+ }
+
+ @Override
+ public void process(boolean validate, boolean documentsOnly) {
+ if (!validate) return;
+ verifyNoRedeclarations(schema.getDocument());
+ }
+
+ void fail(Field field, String message) {
+ throw newProcessException(schema, field, message);
+ }
+
+ void verifyNoRedeclarations(SDDocumentType docType) {
+ for (SDDocumentType type : docType.allTypes().values()) {
+ if (type.isStruct()) {
+ var seenFieldNames = new HashSet<>();
+ for (var field : type.getDocumentType().contentStruct().getFieldsThisTypeOnly()) {
+ if (seenFieldNames.contains(field.getName())) {
+ // cannot happen?
+ fail(field, "struct "+type.getName()+" has multiple fields with same name: "+field.getName());
+ }
+ seenFieldNames.add(field.getName());
+ }
+ for (SDDocumentType inherit : type.getInheritedTypes()) {
+ if (inherit.isStruct()) {
+ for (var field : inherit.getDocumentType().contentStruct().getFieldsThisTypeOnly()) {
+ if (seenFieldNames.contains(field.getName())) {
+ fail(field, "struct "+type.getName()+" cannot inherit from "+inherit.getName()+" and redeclare field "+field.getName());
+ }
+ seenFieldNames.add(field.getName());
+
+ }
+ } else {
+ fail(new Field("no field"), "struct cannot inherit from non-struct "+inherit.getName()+" class "+inherit.getClass());
+ }
+ }
+ }
+ }
+ }
+
+}