diff options
3 files changed, 130 insertions, 49 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java new file mode 100644 index 00000000000..29dd36c1d25 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java @@ -0,0 +1,26 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import java.util.ArrayList; +import java.util.List; + +public class ParsedDocument { + private final String name; + private final List<String> inherited = new ArrayList<>(); + + public ParsedDocument(String name) { + this.name = name; + } + + String getName() { return name; } + void inherit(String other) { inherited.add(other); } + + /* + private final List<ParsedField> fields = new ArrayList<>(); + List<ParsedField> getFields() { return fields; } + void addField(ParsedField field) { fields.add(field); } + void addStruct(ParsedStruct type) {} + void addAnnotation(ParsedAnnotation type) {} + */ +} + diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java new file mode 100644 index 00000000000..6026cf55beb --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java @@ -0,0 +1,41 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import com.yahoo.searchdefinition.OnnxModel; +import com.yahoo.searchdefinition.RankingConstant; +import com.yahoo.searchdefinition.document.Stemming; + +import java.util.ArrayList; +import java.util.List; + +public class ParsedSchema { + private final String name; + private final List<String> inherited = new ArrayList<>(); + + public ParsedSchema(String name) { + this.name = name; + } + + String getName() { return name; } + + void addDocument(ParsedDocument document) {} + void addImportedField(String asFieldName, String refFieldName, String foregnFieldName) {} + void addOnnxModel(OnnxModel model) {} + void addRankingConstant(RankingConstant constant) {} + void enableRawAsBase64(boolean value) {} + void inherit(String other) { inherited.add(other); } + void setStemming(Stemming value) {} + + /* + private final List<ParsedField> fields = new ArrayList<>(); + List<ParsedField> getFields() { return fields; } + void addField(ParsedField field) { fields.add(field); } + void addAnnotation(ParsedAnnotation annotation) {} + void addIndex(ParsedIndex index) {} + void addStruct(ParsedStruct struct) {} + void addFieldSet(ParsedFieldSet fieldSet) {} + void addDocumentSummary(ParsedDocumentSummary docsum) {} + void addRankProfile(ParsedRankProfile profile) {} + */ +} + diff --git a/config-model/src/main/javacc/IntermediateParser.jj b/config-model/src/main/javacc/IntermediateParser.jj index f4608361571..6e69cc4624a 100644 --- a/config-model/src/main/javacc/IntermediateParser.jj +++ b/config-model/src/main/javacc/IntermediateParser.jj @@ -397,10 +397,9 @@ SPECIAL_TOKEN : * * @return the schema object */ -Schema schema(DocumentTypeManager docMan) : +ParsedSchema schema() : { - this.docMan = docMan; - Schema schema; + ParsedSchema schema; } { (<NL>)* (schema = rootSchema() | schema = rootDocument()) @@ -413,17 +412,17 @@ Schema schema(DocumentTypeManager docMan) : * * @return the schema definition object. */ -Schema rootSchema() : +ParsedSchema rootSchema() : { String name; String inherited = null; - Schema schema; + ParsedSchema schema; } { ( ( <SCHEMA> | <SEARCH> ) name = identifier() (<INHERITS> inherited = identifier() )? { - schema = new Schema(name, applicationPackage, Optional.ofNullable(inherited), fileRegistry, deployLogger, properties); - rankProfileRegistry.add(new DefaultRankProfile(schema, rankProfileRegistry, schema.rankingConstants())); - rankProfileRegistry.add(new UnrankedRankProfile(schema, rankProfileRegistry, schema.rankingConstants()));} + schema = new ParsedSchema(name); + if (inherited != null) schema.inherit(inherited); + } lbrace() (rootSchemaItem(schema) (<NL>)*)* <RBRACE> (<NL>)* <EOF>) { return schema; } } @@ -434,22 +433,25 @@ Schema rootSchema() : * * @param schema the schema object to modify. */ -void rootSchemaItem(Schema schema) : { } +void rootSchemaItem(ParsedSchema schema) : { } { ( document(schema) | rawAsBase64(schema) + | searchStemming(schema) + | importField(schema) + | rankingConstant(schema) + | useDocument(schema) +/* | documentSummary(schema) | field(null, schema) | index(schema, null) - | rankingConstant(schema) | rankProfile(schema) - | searchStemming(schema) - | useDocument(schema) | structOutside(schema) | annotationOutside(schema) | fieldSet(schema) - | importField(schema) - | onnxModel(schema) ) +*/ + | onnxModel(schema) + ) } /** @@ -457,9 +459,9 @@ void rootSchemaItem(Schema schema) : { } * * @return the schema definition object. */ -Schema rootDocument() : +ParsedSchema rootDocument() : { - Schema schema = new DocumentOnlySchema(applicationPackage, fileRegistry, deployLogger, properties); + ParsedSchema schema = new ParsedSchema("<unnamed>"); } { ( (rootDocumentItem(schema) (<NL>)*)*<EOF> ) @@ -471,7 +473,7 @@ Schema rootDocument() : * * @param schema the schema object to modify. */ -void rootDocumentItem(Schema schema) : { } +void rootDocumentItem(ParsedSchema schema) : { } { ( namedDocument(schema) ) } @@ -481,7 +483,7 @@ void rootDocumentItem(Schema schema) : { } * * @param schema the schema object to modify. */ -void useDocument(Schema schema) : { } +void useDocument(ParsedSchema schema) : { } { <USEDOCUMENT> <COLON> identifier() { deployLogger.logApplicationPackage(Level.WARNING, "Specifying 'use-document' is deprecated and has no effect."); } @@ -492,15 +494,15 @@ void useDocument(Schema schema) : { } * * @param schema the schema object to add content to. */ -void document(Schema schema) : +void document(ParsedSchema schema) : { String name = schema.getName(); - SDDocumentType document; + ParsedDocument document; } { - ( <DOCUMENT> (name = identifier())? (<NL>)* { document = new SDDocumentType(name, schema); } + ( <DOCUMENT> (name = identifier())? (<NL>)* { document = new ParsedDocument(name); } [ inheritsDocument(document) (<NL>)* ] - <LBRACE> (<NL>)* (documentBody(document, schema) (<NL>)*)* <RBRACE> ) + <LBRACE> (<NL>)* (documentBody(document) (<NL>)*)* <RBRACE> ) { schema.addDocument(document); } @@ -511,15 +513,15 @@ void document(Schema schema) : * * @param schema the schema object to add content to */ -void namedDocument(Schema schema) : +void namedDocument(ParsedSchema schema) : { String name; - SDDocumentType document; + ParsedDocument document; } { - ( <DOCUMENT> name = identifier() (<NL>)* { document = new SDDocumentType(name, schema); } + ( <DOCUMENT> name = identifier() (<NL>)* { document = new ParsedDocument(name); } [ inheritsDocument(document) (<NL>)* ] - <LBRACE> (<NL>)* (documentBody(document, schema) (<NL>)*)* <RBRACE> ) + <LBRACE> (<NL>)* (documentBody(document) (<NL>)*)* <RBRACE> ) { schema.addDocument(document); } @@ -529,21 +531,21 @@ void namedDocument(Schema schema) : * Consumes a document body block * * @param document the document type to modify. - * @param schema the schema object to add content to */ -void documentBody(SDDocumentType document, Schema schema) : +void documentBody(ParsedDocument document) : { } { - ( annotation(schema, document) - | compression(document) - | headercfg(document) - | bodycfg(document) + ( compression(null) + | headercfg(null) + | bodycfg(null) + /* | annotation(schema, document) | structInside(document, schema) - | field(document, schema) ) + | field(document, schema) */ + ) } -void rawAsBase64(Schema schema) : +void rawAsBase64(ParsedSchema schema) : { boolean enabled = false; } @@ -605,11 +607,11 @@ void compressionItem() : } /** - * Consumes a document inheritance statement. + * Consumes a struct inheritance statement. * - * @param document The document type to modify. + * @param document The struct type to modify. */ -void inheritsDocument(SDDocumentType document) : +void inheritsStruct(SDDocumentType document) : { String name; } @@ -618,6 +620,22 @@ void inheritsDocument(SDDocumentType document) : ( <COMMA> name = identifier() { document.inherit(new DataTypeName(name)); } )* } + +/** + * Consumes a document inheritance statement. + * + * @param document The document type to modify. + */ +void inheritsDocument(ParsedDocument document) : +{ + String name; +} +{ + <INHERITS> name = identifier() { document.inherit(name); } + ( <COMMA> name = identifier() { document.inherit(name); } )* +} + + /** * Consumes a field block from within a document element. * @@ -807,7 +825,7 @@ SDDocumentType structDefinition(Schema schema, SDDocumentType repo) : } { ( <STRUCT> name = identifier() (<NL>)* { struct = new SDDocumentType(name, schema); } - [ inheritsDocument(struct) (<NL>)* ] + [ inheritsStruct(struct) (<NL>)* ] lbrace() (structFieldDefinition(struct) (<NL>)*)* <RBRACE> ) { try { @@ -1436,7 +1454,7 @@ void fieldStemming(FieldOperationContainer field) : * * @param schema the schema to modify */ -void searchStemming(Schema schema) : +void searchStemming(ParsedSchema schema) : { String setting; } @@ -1833,7 +1851,7 @@ void hnswIndexBody(HnswIndexParams.Builder params) : * * @param schema the schema object to add content to. */ -void onnxModel(Schema schema) : +void onnxModel(ParsedSchema schema) : { String name; OnnxModel onnxModel; @@ -1846,7 +1864,7 @@ void onnxModel(Schema schema) : lbrace() (onnxModelItem(onnxModel) (<NL>)*)+ <RBRACE> ) { if (documentsOnly) return; - schema.onnxModels().add(onnxModel); + schema.addOnnxModel(onnxModel); } } @@ -1883,7 +1901,7 @@ void onnxModelItem(OnnxModel onnxModel) : * * @param schema the schema object to add content to */ -void rankingConstant(Schema schema) : +void rankingConstant(ParsedSchema schema) : { String name; String path = null; @@ -1900,7 +1918,7 @@ void rankingConstant(Schema schema) : ) { if (documentsOnly) return; - schema.rankingConstants().add(new RankingConstant(name, type, path, pathType)); + schema.addRankingConstant(new RankingConstant(name, type, path, pathType)); } } @@ -2550,7 +2568,7 @@ TensorType tensorType(String errorMessage) : } } -void importField(Schema schema) : +void importField(ParsedSchema schema) : { String fieldRefSpec; String aliasFieldName; @@ -2566,11 +2584,7 @@ void importField(Schema schema) : int indexOfDot = fieldRefSpec.indexOf('.'); String documentReferenceFieldName = fieldRefSpec.substring(0, indexOfDot); String foreignFieldName = fieldRefSpec.substring(indexOfDot + 1); - TemporaryImportedFields importedFields = schema.temporaryImportedFields().get(); - if (importedFields.hasField(aliasFieldName)) { - throw new IllegalArgumentException("For schema '" + schema.getName() + "', import field as '" + aliasFieldName + "': Field already imported"); - } - importedFields.add(new TemporaryImportedField(aliasFieldName, documentReferenceFieldName, foreignFieldName)); + schema.addImportedField(aliasFieldName, documentReferenceFieldName, foreignFieldName); } } |