summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahooinc.com>2022-03-08 11:27:42 +0000
committerArne H Juul <arnej@yahooinc.com>2022-03-11 13:36:53 +0000
commitee4fb1f44497518575d0cd38afee55b4a20706cf (patch)
tree8af4f9454558b53452fd62a801e04c08581e7ecb
parentba2758ab815ebe7ab2fa9b702b3ace7d5c0fd0d7 (diff)
even TemporarySDField should be connected to a "repo"
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/TemporarySDField.java8
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java2
-rw-r--r--config-model/src/main/javacc/SDParser.jj20
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java2
-rwxr-xr-xconfig-model/src/test/java/com/yahoo/searchdefinition/SDDocumentTypeOrdererTestCase.java12
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/SchemaOrdererTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/VsmFieldsTestCase.java5
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java5
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java15
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java10
-rw-r--r--document/src/main/java/com/yahoo/document/DataType.java1
11 files changed, 44 insertions, 38 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/TemporarySDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/TemporarySDField.java
index 4ced104fa55..6a47d08e3ac 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/TemporarySDField.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/TemporarySDField.java
@@ -8,12 +8,12 @@ import com.yahoo.document.DataType;
*/
public class TemporarySDField extends SDField {
- public TemporarySDField(String name, DataType dataType, SDDocumentType owner) {
- super(owner, name, dataType, owner, false);
+ public TemporarySDField(SDDocumentType repo, String name, DataType dataType, SDDocumentType owner) {
+ super(repo, name, dataType, owner, false);
}
- public TemporarySDField(String name, DataType dataType) {
- super(null, name, dataType, false);
+ public TemporarySDField(SDDocumentType repo, String name, DataType dataType) {
+ super(repo, name, dataType, false);
}
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java
index 99614227714..2d9a788cfef 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertSchemaCollection.java
@@ -221,7 +221,7 @@ public class ConvertSchemaCollection {
}
if (parsed.getMatchSettings().isPresent()) {
// same ugliness as SDParser.jj used to have:
- var tmp = new SDField(null, setName, DataType.STRING);
+ var tmp = new SDField(setName, DataType.STRING);
ConvertParsedFields.convertMatchSettings(tmp, parsed.matchSettings());
schema.fieldSets().userFieldSets().get(setName).setMatching(tmp.getMatching());
}
diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj
index 1a0b518bbb2..1fec33c4f12 100644
--- a/config-model/src/main/javacc/SDParser.jj
+++ b/config-model/src/main/javacc/SDParser.jj
@@ -639,7 +639,7 @@ void field(SDDocumentType document, Schema schema) :
if (name != null && Schema.isReservedName(name.toLowerCase())) {
throw new IllegalArgumentException("Reserved name '" + name + "' can not be used as a field name.");
}
- field = new TemporarySDField(name, type, document);
+ field = new TemporarySDField(document, name, type, document);
}
lbrace() (fieldBody(field, schema, document) (<NL>)*)* <RBRACE>
{
@@ -698,11 +698,13 @@ void annotationOutside(Schema schema) :
<ANNOTATION> name = identifier()
{
type = new SDAnnotationType(name.trim());
+ if (schema.getDocument() == null) {
+ throw new IllegalArgumentException("Can't add annotation '"+name+"' to a document type, define a document type first or declare the annotation inside of one.");
+ }
}
[ inheritsAnnotation(type) (<NL>)* ]
- lbrace() (type = annotationBody(schema, type)) <RBRACE>
+ lbrace() (type = annotationBody(schema, schema.getDocument(), type)) <RBRACE>
{
- if (schema.getDocument()==null) throw new IllegalArgumentException("Can't add annotation '"+name+"' to a document type, define a document type first or declare the annotation inside of one.");
schema.addAnnotation(type);
}
}
@@ -723,7 +725,7 @@ void annotation(Schema schema, SDDocumentType document) :
type = new SDAnnotationType(name.trim());
}
[ inheritsAnnotation(type) (<NL>)* ]
- lbrace() (type = annotationBody(schema, type)) <RBRACE>
+ lbrace() (type = annotationBody(schema, document, type)) <RBRACE>
{
document.addAnnotation(type);
}
@@ -737,12 +739,12 @@ void annotation(Schema schema, SDDocumentType document) :
* @param type the type being built
* @return a modified or new AnnotationType instance
*/
-SDAnnotationType annotationBody(Schema schema, SDAnnotationType type) :
+SDAnnotationType annotationBody(Schema schema, SDDocumentType repo, SDAnnotationType type) :
{
SDDocumentType struct = new SDDocumentType("annotation." + type.getName(), schema);
}
{
- (structFieldDefinition(struct) (<NL>)*)*
+ (structFieldDefinition(repo, struct) (<NL>)*)*
{
if (struct.getFieldCount() > 0) { // Must account for the temporary TemporarySDField.
type = new SDAnnotationType(type.getName(), struct, type.getInherits());
@@ -811,7 +813,7 @@ SDDocumentType structDefinition(Schema schema, SDDocumentType repo) :
{
( <STRUCT> name = identifier() (<NL>)* { struct = new SDDocumentType(name, schema); }
[ inheritsDocument(struct) (<NL>)* ]
- lbrace() (structFieldDefinition(struct) (<NL>)*)* <RBRACE> )
+ lbrace() (structFieldDefinition(repo, struct) (<NL>)*)* <RBRACE> )
{
try {
docMan.getDataType(name);
@@ -921,7 +923,7 @@ DataType wildCardType() :
*
* @param struct The struct to modify.
*/
-void structFieldDefinition(SDDocumentType struct) :
+void structFieldDefinition(SDDocumentType document, SDDocumentType struct) :
{
String name;
SDField field;
@@ -932,7 +934,7 @@ void structFieldDefinition(SDDocumentType struct) :
if (name != null && Schema.isReservedName(name.toLowerCase())) {
throw new IllegalArgumentException("Reserved name '" + name + "' can not be used as a field name.");
}
- field = new TemporarySDField(name, type, struct);
+ field = new TemporarySDField(document, name, type, struct);
struct.addField(field);
}
lbrace() (id(field,struct) (<NL>)*)? (match(field) (<NL>)*)* <RBRACE> {
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java
index 81a44261daf..8edbd789a27 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java
@@ -156,8 +156,8 @@ public class DocumentGraphValidatorTest {
@SuppressWarnings("deprecation")
private static void createDocumentReference(Schema from, Schema to, String refFieldName) {
- SDField refField = new TemporarySDField(refFieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(to.getName())));
SDDocumentType fromDocument = from.getDocument();
+ SDField refField = new TemporarySDField(fromDocument, refFieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(to.getName())));
fromDocument.addField(refField);
Map<String, DocumentReference> originalMap = fromDocument.getDocumentReferences().get().referenceMap();
HashMap<String, DocumentReference> modifiedMap = new HashMap<>(originalMap);
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SDDocumentTypeOrdererTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SDDocumentTypeOrdererTestCase.java
index c7ec2d9e9d1..652a06a6025 100755
--- a/config-model/src/test/java/com/yahoo/searchdefinition/SDDocumentTypeOrdererTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/SDDocumentTypeOrdererTestCase.java
@@ -37,22 +37,22 @@ public class SDDocumentTypeOrdererTestCase {
g.inherit(new TemporarySDDocumentType(new DataTypeName("e")));
g.inherit(new TemporarySDDocumentType(new DataTypeName("c")));
- SDField aFieldTypeB = new TemporarySDField("atypeb", DataType.STRING);
+ SDField aFieldTypeB = new TemporarySDField(a, "atypeb", DataType.STRING);
a.addField(aFieldTypeB);
- SDField bFieldTypeC = new TemporarySDField("btypec", DataType.STRING);
+ SDField bFieldTypeC = new TemporarySDField(b, "btypec", DataType.STRING);
b.addField(bFieldTypeC);
- SDField cFieldTypeG = new TemporarySDField("ctypeg", DataType.STRING);
+ SDField cFieldTypeG = new TemporarySDField(c, "ctypeg", DataType.STRING);
c.addField(cFieldTypeG);
- SDField gFieldTypeF = new TemporarySDField("gtypef", DataType.STRING);
+ SDField gFieldTypeF = new TemporarySDField(g, "gtypef", DataType.STRING);
g.addField(gFieldTypeF);
- SDField fFieldTypeC = new TemporarySDField("ftypec", DataType.STRING);
+ SDField fFieldTypeC = new TemporarySDField(f, "ftypec", DataType.STRING);
f.addField(fFieldTypeC);
- SDField dFieldTypeE = new TemporarySDField("dtypee", DataType.STRING);
+ SDField dFieldTypeE = new TemporarySDField(d, "dtypee", DataType.STRING);
d.addField(dFieldTypeE);
types.add(a);
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/SchemaOrdererTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/SchemaOrdererTestCase.java
index 34d33a00d9e..2522f8f56e2 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/SchemaOrdererTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/SchemaOrdererTestCase.java
@@ -91,8 +91,8 @@ public class SchemaOrdererTestCase extends AbstractSchemaTestCase {
@SuppressWarnings("deprecation")
private static void createDocumentReference(Schema from, Schema to, String refFieldName) {
- SDField refField = new TemporarySDField(refFieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(to.getName())));
SDDocumentType fromDocument = from.getDocument();
+ SDField refField = new TemporarySDField(fromDocument, refFieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(to.getName())));
fromDocument.addField(refField);
Map<String, DocumentReference> originalMap = fromDocument.getDocumentReferences().get().referenceMap();
HashMap<String, DocumentReference> modifiedMap = new HashMap<>(originalMap);
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/VsmFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/VsmFieldsTestCase.java
index 5ab5a8057e8..9c974225605 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/VsmFieldsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/VsmFieldsTestCase.java
@@ -25,8 +25,9 @@ public class VsmFieldsTestCase {
@Test
public void reference_type_field_is_unsearchable() {
Schema schema = new Schema("test", MockApplicationPackage.createEmpty(), new MockFileRegistry(), new TestableDeployLogger(), new TestProperties());
- schema.addDocument(new SDDocumentType("test"));
- SDField refField = new TemporarySDField("ref_field", ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create("parent_type")));
+ var sdoc = new SDDocumentType("test");
+ schema.addDocument(sdoc);
+ SDField refField = new TemporarySDField(sdoc, "ref_field", ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create("parent_type")));
refField.parseIndexingScript("{ summary }");
schema.getDocument().addField(refField);
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java
index 5d2590a420d..926e26451d7 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java
@@ -186,9 +186,10 @@ public class AdjustPositionSummaryFieldsTestCase {
private void createPositionField(Schema schema, boolean setupPosAttr, boolean setupBadAttr) {
String ilScript = setupPosAttr ? "{ summary | attribute }" : "{ summary }";
- schema.getDocument().addField(createField("pos", PositionDataType.INSTANCE, ilScript));
+ var doc = schema.getDocument();
+ doc.addField(createField(doc, "pos", PositionDataType.INSTANCE, ilScript));
if (setupBadAttr) {
- schema.getDocument().addField(createField("pos_zcurve", DataType.LONG, "{ attribute }"));
+ doc.addField(createField(doc, "pos_zcurve", DataType.LONG, "{ attribute }"));
}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
index 324010f9e83..d1d3f4489ce 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
@@ -110,13 +110,14 @@ public class ImportedFieldsResolverTestCase {
public SearchModel() {
super();
grandParentSchema = createSearch("grandparent");
- grandParentSchema.getDocument().addField(createField("ancient_field", DataType.INT, "{ attribute }"));
-
- parentSchema.getDocument().addField(createField("attribute_field", DataType.INT, "{ attribute }"));
- parentSchema.getDocument().addField(createField("attribute_and_index", DataType.INT, "{ attribute | index }"));
- parentSchema.getDocument().addField(new TemporarySDField("not_attribute", DataType.INT));
- parentSchema.getDocument().addField(createField("tensor_field", new TensorDataType(TensorType.fromSpec("tensor(x[5])")), "{ attribute }"));
- parentSchema.getDocument().addField(createField("predicate_field", DataType.PREDICATE, "{ attribute }"));
+ var grandParentDoc = grandParentSchema.getDocument();
+ grandParentDoc.addField(createField(grandParentDoc, "ancient_field", DataType.INT, "{ attribute }"));
+ var parentDoc = parentSchema.getDocument();
+ parentDoc.addField(createField(parentDoc, "attribute_field", DataType.INT, "{ attribute }"));
+ parentDoc.addField(createField(parentDoc, "attribute_and_index", DataType.INT, "{ attribute | index }"));
+ parentDoc.addField(new TemporarySDField(parentDoc, "not_attribute", DataType.INT));
+ parentDoc.addField(createField(parentDoc, "tensor_field", new TensorDataType(TensorType.fromSpec("tensor(x[5])")), "{ attribute }"));
+ parentDoc.addField(createField(parentDoc, "predicate_field", DataType.PREDICATE, "{ attribute }"));
addRefField(parentSchema, grandParentSchema, "ref");
addImportedField(parentSchema, "ancient_field", "ref", "ancient_field");
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java
index b14c7287537..3b4612ee87a 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ParentChildSearchModel.java
@@ -37,19 +37,19 @@ public class ParentChildSearchModel {
return result;
}
- protected static TemporarySDField createField(String name, DataType dataType, String indexingScript) {
- TemporarySDField result = new TemporarySDField(name, dataType);
+ protected static TemporarySDField createField(SDDocumentType repo, String name, DataType dataType, String indexingScript) {
+ TemporarySDField result = new TemporarySDField(repo, name, dataType);
result.parseIndexingScript(indexingScript);
return result;
}
@SuppressWarnings("deprecation")
- protected static SDField createRefField(String parentType, String fieldName) {
- return new TemporarySDField(fieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(parentType)));
+ protected static SDField createRefField(SDDocumentType repo, String parentType, String fieldName) {
+ return new TemporarySDField(repo, fieldName, ReferenceDataType.createWithInferredId(TemporaryStructuredDataType.create(parentType)));
}
protected static void addRefField(Schema child, Schema parent, String fieldName) {
- SDField refField = createRefField(parent.getName(), fieldName);
+ SDField refField = createRefField(child.getDocument(), parent.getName(), fieldName);
child.getDocument().addField(refField);
child.getDocument().setDocumentReferences(new DocumentReferences(ImmutableMap.of(refField.getName(),
new DocumentReference(refField, parent))));
diff --git a/document/src/main/java/com/yahoo/document/DataType.java b/document/src/main/java/com/yahoo/document/DataType.java
index e47c60863ff..2fcbe7333b4 100644
--- a/document/src/main/java/com/yahoo/document/DataType.java
+++ b/document/src/main/java/com/yahoo/document/DataType.java
@@ -62,6 +62,7 @@ public abstract class DataType extends Identifiable implements Serializable, Com
static {
TAG.setTag(true);
}
+
public static int lastPredefinedDataTypeId() {
return 21;
}