summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2023-04-21 13:11:46 +0000
committerArne Juul <arnej@yahooinc.com>2023-04-21 13:11:46 +0000
commit64d0414f237cd31484ec234d3582dab1021f03b4 (patch)
treee0d7424f0d38d0f1963430033d37f1ea292070f9
parenteaedf1a1417e5592ebb736aa34a7b72bd03fe169 (diff)
for document-summary blocks:
* for existing fields, allow skipping the type declaration * if type is same except for weighted-set flags, adjust type to match * for this to work with inheritance, wire in inherited schema early
-rw-r--r--config-model/src/main/java/com/yahoo/schema/Schema.java11
-rw-r--r--config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedSchemas.java25
-rw-r--r--config-model/src/main/javacc/SchemaParser.jj7
-rw-r--r--config-model/src/test/derived/multiplesummaries/index-info.cfg2
-rw-r--r--config-model/src/test/derived/multiplesummaries/multiplesummaries.sd5
5 files changed, 41 insertions, 9 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/Schema.java b/config-model/src/main/java/com/yahoo/schema/Schema.java
index 180c8e6012f..93bec4975a6 100644
--- a/config-model/src/main/java/com/yahoo/schema/Schema.java
+++ b/config-model/src/main/java/com/yahoo/schema/Schema.java
@@ -709,8 +709,17 @@ public class Schema implements ImmutableSchema {
public FieldSets fieldSets() { return fieldSets; }
+ private Schema inheritedSchema = null;
+
+ public void setInheritedSchema(Schema value) {
+ inheritedSchema = value;
+ }
+
/** Returns the schema inherited by this, or throws if none */
- private Schema requireInherited() { return owner.schemas().get(inherited.get()); }
+ private Schema requireInherited() {
+ if (inheritedSchema != null) return inheritedSchema;
+ return owner.schemas().get(inherited.get());
+ }
/**
* For adding structs defined in document scope
diff --git a/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedSchemas.java b/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedSchemas.java
index 0abcc9e890a..40ec84ec8bc 100644
--- a/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedSchemas.java
+++ b/config-model/src/main/java/com/yahoo/schema/parser/ConvertParsedSchemas.java
@@ -98,6 +98,13 @@ public class ConvertParsedSchemas {
Schema schema = parsed.getDocumentWithoutSchema()
? new DocumentOnlySchema(applicationPackage, fileRegistry, deployLogger, properties)
: new Schema(parsed.name(), applicationPackage, inherited, fileRegistry, deployLogger, properties);
+ inherited.ifPresent(parentName -> {
+ for (var possibleParent : resultList) {
+ if (possibleParent.getName().equals(parentName)) {
+ schema.setInheritedSchema(possibleParent);
+ }
+ }
+ });
convertSchema(schema, parsed);
resultList.add(schema);
}
@@ -145,7 +152,23 @@ public class ConvertParsedSchemas {
docsum.setOmitSummaryFeatures(true);
}
for (var parsedField : parsed.getSummaryFields()) {
- DataType dataType = typeContext.resolveType(parsedField.getType());
+ var parsedType = parsedField.getType();
+ DataType dataType = (parsedType != null) ? typeContext.resolveType(parsedType) : null;
+ var existingField = schema.getField(parsedField.name());
+ if (existingField != null) {
+ var existingType = existingField.getDataType();
+ if (dataType == null) {
+ dataType = existingType;
+ } else if (!dataType.equals(existingType)) {
+ if (dataType.getValueClass().equals(com.yahoo.document.datatypes.WeightedSet.class)) {
+ // "adjusting type for field " + parsedField.name() + " in document-summary " + parsed.name() + " field already has: " + existingType + " but declared type was: " + dataType
+ dataType = existingType;
+ }
+ }
+ }
+ if (dataType == null) {
+ throw new IllegalArgumentException("Missing data-type for summary field " + parsedField.name() + " in document-summary " + parsed.name());
+ }
var summaryField = new SummaryField(parsedField.name(), dataType);
// XXX does not belong here:
summaryField.setVsmCommand(SummaryField.VsmCommand.FLATTENSPACE);
diff --git a/config-model/src/main/javacc/SchemaParser.jj b/config-model/src/main/javacc/SchemaParser.jj
index 9d6e16b3f67..9a38fdc673e 100644
--- a/config-model/src/main/javacc/SchemaParser.jj
+++ b/config-model/src/main/javacc/SchemaParser.jj
@@ -1075,15 +1075,16 @@ void attributeSetting(ParsedAttribute attribute) :
void summaryInDocument(ParsedDocumentSummary docsum) :
{
String name;
- ParsedType type;
+ ParsedType type = null;
ParsedSummaryField psf;
}
{
<SUMMARY> name = identifierWithDash() { }
- <TYPE> type = dataType() {
+ (<TYPE> type = dataType())?
+ lbrace() {
psf = new ParsedSummaryField(name, type);
}
- lbrace() (summaryItem(psf) (<NL>)*)* <RBRACE>
+ (summaryItem(psf) (<NL>)*)* <RBRACE>
{
var old = docsum.addField(psf);
if (old != null) {
diff --git a/config-model/src/test/derived/multiplesummaries/index-info.cfg b/config-model/src/test/derived/multiplesummaries/index-info.cfg
index 085a9eb232f..50f2419fc58 100644
--- a/config-model/src/test/derived/multiplesummaries/index-info.cfg
+++ b/config-model/src/test/derived/multiplesummaries/index-info.cfg
@@ -82,8 +82,6 @@ indexinfo[].command[].command "index"
indexinfo[].command[].indexname "h"
indexinfo[].command[].command "multivalue"
indexinfo[].command[].indexname "h"
-indexinfo[].command[].command "string"
-indexinfo[].command[].indexname "h"
indexinfo[].command[].command "type WeightedSet<string>"
indexinfo[].command[].indexname "loc"
indexinfo[].command[].command "index"
diff --git a/config-model/src/test/derived/multiplesummaries/multiplesummaries.sd b/config-model/src/test/derived/multiplesummaries/multiplesummaries.sd
index 51259802a3a..5f93a6e512b 100644
--- a/config-model/src/test/derived/multiplesummaries/multiplesummaries.sd
+++ b/config-model/src/test/derived/multiplesummaries/multiplesummaries.sd
@@ -62,6 +62,7 @@ schema multiplesummaries {
field h type weightedset<string> {
indexing: summary
+ weightedset: create-if-nonexistent
}
field loc type string {
@@ -91,7 +92,7 @@ schema multiplesummaries {
summary e type string {
}
- summary f type array<string> {
+ summary f {
}
summary g type array<int> {
@@ -209,7 +210,7 @@ schema multiplesummaries {
bolding: on
}
- summary c type string {
+ summary c {
}
}