aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/schema
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-10-26 15:34:49 +0200
committerTor Egge <Tor.Egge@online.no>2023-10-26 15:34:49 +0200
commitcb5adbfd3d9ce54bbc693bd0df3f9af0c09b4afd (patch)
tree3bf500294044724b8b418a5cb73320a0c01c8c4b /config-model/src/main/java/com/yahoo/schema
parentf79e502a32056a710d12b1d8388cdefea89db5a3 (diff)
Adjust multiple summary transforms in shared class.
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/processing/AdjustSummaryTransforms.java82
-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/SummaryConsistency.java38
-rw-r--r--config-model/src/main/java/com/yahoo/schema/processing/SummaryTransformForDocumentId.java32
4 files changed, 83 insertions, 71 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/AdjustSummaryTransforms.java b/config-model/src/main/java/com/yahoo/schema/processing/AdjustSummaryTransforms.java
new file mode 100644
index 00000000000..dd6f118d113
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/processing/AdjustSummaryTransforms.java
@@ -0,0 +1,82 @@
+// Copyright Vespa.ai. 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.schema.RankProfileRegistry;
+import com.yahoo.schema.Schema;
+import com.yahoo.schema.derived.SummaryClass;
+import com.yahoo.schema.document.Attribute;
+import com.yahoo.schema.document.ImmutableSDField;
+import com.yahoo.vespa.documentmodel.SummaryField;
+import com.yahoo.vespa.documentmodel.SummaryTransform;
+import com.yahoo.vespa.model.container.search.QueryProfiles;
+
+import static com.yahoo.schema.document.ComplexAttributeFieldUtils.isComplexFieldWithOnlyStructFieldAttributes;
+
+/**
+ * Adds the corresponding summary transform for all "documentid" summary fields.
+ * For summary fields without an existing transform:
+ * - Adds the attribute transforms where the source field has an attribute vector.
+ * - Adds the attribute combiner transform where the source field is a struct field where all subfields have attribute
+ * vector.
+ * - Add the copy transform where the source field is a struct or map field with a different name.
+ *
+ * @author geirst
+ */
+public class AdjustSummaryTransforms extends Processor {
+
+ public AdjustSummaryTransforms(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
+ super(schema, deployLogger, rankProfileRegistry, queryProfiles);
+ }
+
+ @Override
+ public void process(boolean validate, boolean documentsOnly) {
+ for (var summary : schema.getSummaries().values()) {
+ for (var summaryField : summary.getSummaryFields().values()) {
+ makeDocumentIdTransformIfAppropriate(summaryField);
+ makeAttributeTransformIfAppropriate(summaryField, schema);
+ makeAttributeCombinerTransformIfAppropriate(summaryField, schema);
+ makeCopyTransformIfAppropriate(summaryField, schema);
+ }
+ }
+ }
+
+ private void makeDocumentIdTransformIfAppropriate(SummaryField summaryField)
+ {
+ if (summaryField.getName().equals(SummaryClass.DOCUMENT_ID_FIELD)) {
+ summaryField.setTransform(SummaryTransform.DOCUMENT_ID);
+ }
+ }
+
+ /** If the source is an attribute, make this use the attribute transform */
+ private void makeAttributeTransformIfAppropriate(SummaryField summaryField, Schema schema) {
+ if (summaryField.getTransform() != SummaryTransform.NONE) return;
+ Attribute attribute = schema.getAttribute(summaryField.getSingleSource());
+ if (attribute == null) return;
+ summaryField.setTransform(SummaryTransform.ATTRIBUTE);
+ }
+
+ /** If the source is a complex field with only struct field attributes then make this use the attribute combiner transform */
+ private void makeAttributeCombinerTransformIfAppropriate(SummaryField summaryField, Schema schema) {
+ if (summaryField.getTransform() == SummaryTransform.NONE) {
+ String sourceFieldName = summaryField.getSingleSource();
+ ImmutableSDField source = schema.getField(sourceFieldName);
+ if (source != null && isComplexFieldWithOnlyStructFieldAttributes(source)) {
+ summaryField.setTransform(SummaryTransform.ATTRIBUTECOMBINER);
+ }
+ }
+ }
+
+ /*
+ * This function must be called after makeAttributeCombinerTransformIfAppropriate().
+ */
+ private void makeCopyTransformIfAppropriate(SummaryField summaryField, Schema schema) {
+ if (summaryField.getTransform() == SummaryTransform.NONE) {
+ String sourceFieldName = summaryField.getSingleSource();
+ ImmutableSDField source = schema.getField(sourceFieldName);
+ if (source != null && source.usesStructOrMap() && summaryField.hasExplicitSingleSource()) {
+ summaryField.setTransform(SummaryTransform.COPY);
+ }
+ }
+ }
+}
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 d9b90ad661d..2d4b4824310 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
@@ -53,8 +53,8 @@ public class Processing {
ImplicitSummaries::new,
ImplicitSummaryFields::new,
AdjustPositionSummaryFields::new,
- SummaryTransformForDocumentId::new,
SummaryConsistency::new,
+ AdjustSummaryTransforms::new,
SummaryNamesFieldCollisions::new,
SummaryFieldsMustHaveValidSource::new,
MatchedElementsOnlyResolver::new,
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/SummaryConsistency.java b/config-model/src/main/java/com/yahoo/schema/processing/SummaryConsistency.java
index a7ff50ffcca..4b214e00d65 100644
--- a/config-model/src/main/java/com/yahoo/schema/processing/SummaryConsistency.java
+++ b/config-model/src/main/java/com/yahoo/schema/processing/SummaryConsistency.java
@@ -8,14 +8,11 @@ import com.yahoo.schema.RankProfileRegistry;
import com.yahoo.schema.Schema;
import com.yahoo.schema.document.Attribute;
import com.yahoo.document.WeightedSetDataType;
-import com.yahoo.schema.document.ImmutableSDField;
import com.yahoo.vespa.documentmodel.DocumentSummary;
import com.yahoo.vespa.documentmodel.SummaryField;
import com.yahoo.vespa.documentmodel.SummaryTransform;
import com.yahoo.vespa.model.container.search.QueryProfiles;
-import static com.yahoo.schema.document.ComplexAttributeFieldUtils.isComplexFieldWithOnlyStructFieldAttributes;
-
/**
* Ensure that summary field transforms for fields having the same name
* are consistent across summary classes
@@ -35,9 +32,6 @@ public class SummaryConsistency extends Processor {
for (SummaryField summaryField : summary.getSummaryFields().values()) {
assertConsistency(summaryField, schema, validate);
- makeAttributeTransformIfAppropriate(summaryField, schema);
- makeAttributeCombinerTransformIfAppropriate(summaryField, schema);
- makeCopyTransformIfAppropriate(summaryField, schema);
}
}
}
@@ -60,38 +54,6 @@ public class SummaryConsistency extends Processor {
}
}
- /** If the source is an attribute, make this use the attribute transform */
- private void makeAttributeTransformIfAppropriate(SummaryField summaryField, Schema schema) {
- if (summaryField.getTransform() != SummaryTransform.NONE) return;
- Attribute attribute = schema.getAttribute(summaryField.getSingleSource());
- if (attribute == null) return;
- summaryField.setTransform(SummaryTransform.ATTRIBUTE);
- }
-
- /** If the source is a complex field with only struct field attributes then make this use the attribute combiner transform */
- private void makeAttributeCombinerTransformIfAppropriate(SummaryField summaryField, Schema schema) {
- if (summaryField.getTransform() == SummaryTransform.NONE) {
- String sourceFieldName = summaryField.getSingleSource();
- ImmutableSDField source = schema.getField(sourceFieldName);
- if (source != null && isComplexFieldWithOnlyStructFieldAttributes(source)) {
- summaryField.setTransform(SummaryTransform.ATTRIBUTECOMBINER);
- }
- }
- }
-
- /*
- * This function must be called after makeAttributeCombinerTransformIfAppropriate().
- */
- private void makeCopyTransformIfAppropriate(SummaryField summaryField, Schema schema) {
- if (summaryField.getTransform() == SummaryTransform.NONE) {
- String sourceFieldName = summaryField.getSingleSource();
- ImmutableSDField source = schema.getField(sourceFieldName);
- if (source != null && source.usesStructOrMap() && summaryField.hasExplicitSingleSource()) {
- summaryField.setTransform(SummaryTransform.COPY);
- }
- }
- }
-
private void assertConsistentTypes(SummaryField existing, SummaryField seen) {
if (existing.getDataType() instanceof WeightedSetDataType && seen.getDataType() instanceof WeightedSetDataType &&
((WeightedSetDataType)existing.getDataType()).getNestedType().equals(((WeightedSetDataType)seen.getDataType()).getNestedType()))
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/SummaryTransformForDocumentId.java b/config-model/src/main/java/com/yahoo/schema/processing/SummaryTransformForDocumentId.java
deleted file mode 100644
index 388aa93e81c..00000000000
--- a/config-model/src/main/java/com/yahoo/schema/processing/SummaryTransformForDocumentId.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright Vespa.ai. 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.schema.RankProfileRegistry;
-import com.yahoo.schema.Schema;
-import com.yahoo.schema.derived.SummaryClass;
-import com.yahoo.vespa.documentmodel.SummaryTransform;
-import com.yahoo.vespa.model.container.search.QueryProfiles;
-
-/**
- * Adds the corresponding summary transform for all "documentid" summary fields.
- *
- * @author geirst
- */
-public class SummaryTransformForDocumentId extends Processor {
-
- public SummaryTransformForDocumentId(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
- super(schema, deployLogger, rankProfileRegistry, queryProfiles);
- }
-
- @Override
- public void process(boolean validate, boolean documentsOnly) {
- for (var summary : schema.getSummaries().values()) {
- for (var summaryField : summary.getSummaryFields().values()) {
- if (summaryField.getName().equals(SummaryClass.DOCUMENT_ID_FIELD)) {
- summaryField.setTransform(SummaryTransform.DOCUMENT_ID);
- }
- }
- }
- }
-}