diff options
Diffstat (limited to 'config-model/src')
14 files changed, 139 insertions, 72 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java index 7034a69bae4..415fcd1d34e 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/Search.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/Search.java @@ -622,7 +622,7 @@ public class Search implements ImmutableSearch { @Override public String toString() { - return "search definition '" + getName() + "'"; + return "schema '" + getName() + "'"; } public boolean isAccessingDiskSummary(SummaryField field) { @@ -670,4 +670,9 @@ public class Search implements ImmutableSearch { return this; } + public void validate(DeployLogger logger) { + for (var summary : summaries.values()) + summary.validate(logger); + } + } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java index 78cc0d496b0..0f7ead43868 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/SearchBuilder.java @@ -128,10 +128,10 @@ public class SearchBuilder { /** * Import search definition. * - * @param fileName The name of the file to import. - * @return The name of the imported object. - * @throws IOException Thrown if the file can not be read for some reason. - * @throws ParseException Thrown if the file does not contain a valid search definition. ``` + * @param fileName the name of the file to import + * @return the name of the imported object + * @throws IOException thrown if the file can not be read for some reason + * @throws ParseException thrown if the file does not contain a valid search definition */ public String importFile(String fileName) throws IOException, ParseException { File file = new File(fileName); @@ -146,10 +146,10 @@ public class SearchBuilder { * Reads and parses the search definition string provided by the given reader. Once all search definitions have been * imported, call {@link #build()}. * - * @param reader The reader whose content to import. - * @param searchDefDir The path to use when resolving file references. - * @return The name of the imported object. - * @throws ParseException Thrown if the file does not contain a valid search definition. + * @param reader the reader whose content to import + * @param searchDefDir the path to use when resolving file references + * @return the name of the imported object + * @throws ParseException thrown if the file does not contain a valid search definition */ public String importReader(NamedReader reader, String searchDefDir) throws IOException, ParseException { return importString(IOUtils.readAll(reader), searchDefDir); @@ -222,6 +222,9 @@ public class SearchBuilder { public void build(boolean validate) { if (isBuilt) throw new IllegalStateException("Model already built"); + if (validate) + searchList.forEach(search -> search.validate(deployLogger)); + List<Search> built = new ArrayList<>(); List<SDDocumentType> sdocs = new ArrayList<>(); sdocs.add(SDDocumentType.VESPA_DOCUMENT); @@ -230,6 +233,7 @@ public class SearchBuilder { sdocs.add(search.getDocument()); } } + var orderer = new SDDocumentTypeOrderer(sdocs, deployLogger); orderer.process(); for (SDDocumentType sdoc : orderer.getOrdered()) { @@ -255,7 +259,8 @@ public class SearchBuilder { builder.addToModel(searchList); if ( validate && ! builder.valid() ) - throw new IllegalArgumentException("Impossible to build a correct model."); + throw new IllegalArgumentException("Impossible to build a correct model"); + searchList = built; isBuilt = true; } @@ -332,6 +337,14 @@ public class SearchBuilder { return builder; } + public static SearchBuilder createFromStrings(DeployLogger logger, String ... schemas) throws ParseException { + SearchBuilder builder = new SearchBuilder(logger); + for (var schema : schemas) + builder.importString(schema); + builder.build(true); + return builder; + } + /** * Convenience factory method to import and build a {@link Search} object from a file. Only for testing. * diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDDocumentType.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDDocumentType.java index 007a29c95b7..5d50abec8bb 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDDocumentType.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDDocumentType.java @@ -38,9 +38,9 @@ import java.util.Set; public class SDDocumentType implements Cloneable, Serializable { public static final SDDocumentType VESPA_DOCUMENT; - private Map<DataTypeName, SDDocumentType> inheritedTypes = new HashMap<>(); - private Map<NewDocumentType.Name, SDDocumentType> ownedTypes = new HashMap<>(); - private AnnotationTypeRegistry annotationTypes = new AnnotationTypeRegistry(); + private final Map<DataTypeName, SDDocumentType> inheritedTypes = new HashMap<>(); + private final Map<NewDocumentType.Name, SDDocumentType> ownedTypes = new HashMap<>(); + private final AnnotationTypeRegistry annotationTypes = new AnnotationTypeRegistry(); private DocumentType docType; private DataType structType; // The field sets here are set from the processing step in SD, to ensure that the full Search and this SDDocumentType is built first. @@ -181,16 +181,16 @@ public class SDDocumentType implements Cloneable, Serializable { public DocumentType getDocumentType() { return docType; } public void inherit(DataTypeName name) { - if ( ! inheritedTypes.containsKey(name)) { - inheritedTypes.put(name, new TemporarySDDocumentType(name)); - } + inherit(new TemporarySDDocumentType(name)); } public void inherit(SDDocumentType type) { - if (type != null) { - if (!inheritedTypes.containsKey(type.getDocumentName()) || (inheritedTypes.get(type.getDocumentName()) instanceof TemporarySDDocumentType)) { - inheritedTypes.put(type.getDocumentName(), type); - } + if (type == null) return; + if (type.getName().equals(this.getName())) + throw new IllegalArgumentException("Document type '" + getName() + "' cannot inherit itself"); + if ( ! inheritedTypes.containsKey(type.getDocumentName()) || + (inheritedTypes.get(type.getDocumentName()) instanceof TemporarySDDocumentType)) { + inheritedTypes.put(type.getDocumentName(), type); } } @@ -208,10 +208,7 @@ public class SDDocumentType implements Cloneable, Serializable { field.setId(id, docType); } - /** Override getField, as it may need to ask inherited types that isn't registered in document type. - * @param name Name of field to get. - * @return The field found. - */ + /** Override getField, as it may need to ask inherited types that isn't registered in document type. */ public Field getField(String name) { if (name.contains(".")) { String superFieldName = name.substring(0,name.indexOf(".")); @@ -222,7 +219,7 @@ public class SDDocumentType implements Cloneable, Serializable { SDField superField = (SDField)f; return superField.getStructField(subFieldName); } else { - throw new IllegalArgumentException("Field "+f.getName()+" is not SDField"); + throw new IllegalArgumentException("Field " + f.getName() + " is not an SDField"); } } } @@ -246,18 +243,15 @@ public class SDDocumentType implements Cloneable, Serializable { docType.addField(field); } - /** - * This is SD parse-time inheritance check. - * - * @param field The field being verified. - */ + /** Parse-time inheritance check. */ private void verifyInheritance(Field field) { for (SDDocumentType parent : inheritedTypes.values()) { for (Field pField : parent.fieldSet()) { if (pField.getName().equals(field.getName())) { if (!pField.getDataType().equals(field.getDataType())) { - throw new IllegalArgumentException("For search '"+getName()+"', field '"+field.getName()+"': " + - "datatype can't be different from that of same field in supertype '"+parent.getName()+"'."); + throw new IllegalArgumentException("For search '" + getName() + "', field '" + field.getName() + + "': Datatype can not be different from that of same field " + + "in the supertype '" + parent.getName() + "'"); } } } @@ -304,6 +298,7 @@ public class SDDocumentType implements Cloneable, Serializable { return docType.getFieldCount(); } + @Override public String toString() { return "SD document type '" + docType.getName() + "'"; } @@ -342,4 +337,5 @@ public class SDDocumentType implements Cloneable, Serializable { public void setTemporaryImportedFields(TemporaryImportedFields temporaryImportedFields) { this.temporaryImportedFields = temporaryImportedFields; } + } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaries.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaries.java index e05ca24cc77..edf9f744150 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaries.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImplicitSummaries.java @@ -31,7 +31,7 @@ public class ImplicitSummaries extends Processor { public void process(boolean validate, boolean documentsOnly) { DocumentSummary defaultSummary = search.getSummary("default"); if (defaultSummary == null) { - defaultSummary = new DocumentSummary("default"); + defaultSummary = new DocumentSummary("default", search); defaultSummary.setFromDisk(true); search.addSummary(defaultSummary); } @@ -116,7 +116,7 @@ public class ImplicitSummaries extends Processor { private DocumentSummary getOrCreateAttributePrefetchSummary(Search search) { DocumentSummary summary = search.getSummary("attributeprefetch"); if (summary == null) { - summary = new DocumentSummary("attributeprefetch"); + summary = new DocumentSummary("attributeprefetch", search); search.addSummary(summary); } return summary; @@ -209,10 +209,10 @@ public class ImplicitSummaries extends Processor { } } - private void addToDestination(String destinationName, SummaryField summaryField,Search search) { + private void addToDestination(String destinationName, SummaryField summaryField, Search search) { DocumentSummary destination = search.getSummary(destinationName); if (destination == null) { - destination = new DocumentSummary(destinationName); + destination = new DocumentSummary(destinationName, search); search.addSummary(destination); destination.add(summaryField); } diff --git a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java index f648e18dfda..23c1a48b6fe 100644 --- a/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java +++ b/config-model/src/main/java/com/yahoo/vespa/documentmodel/DocumentSummary.java @@ -1,10 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.documentmodel; +import com.yahoo.config.application.api.DeployLogger; +import com.yahoo.searchdefinition.Search; + import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.logging.Level; /** * A document summary definition - a list of summary fields. @@ -15,15 +19,14 @@ public class DocumentSummary extends FieldView { private boolean fromDisk = false; private boolean omitSummaryFeatures = false; - private DocumentSummary inherited; + private String inherited; - /** - * Creates a DocumentSummary with the given name. - * - * @param name The name to use for this summary. - */ - public DocumentSummary(String name) { + private final Search owner; + + /** Creates a DocumentSummary with the given name. */ + public DocumentSummary(String name, Search owner) { super(name); + this.owner = owner; } public void setFromDisk(boolean fromDisk) { this.fromDisk = fromDisk; } @@ -44,7 +47,7 @@ public class DocumentSummary extends FieldView { * in different classes have the same summary transform, because this is * what is supported by the backend currently. * - * @param summaryField The summaryfield to add + * @param summaryField the summaryfield to add */ public void add(SummaryField summaryField) { summaryField.addDestination(getName()); @@ -97,18 +100,39 @@ public class DocumentSummary extends FieldView { } /** Sets the parent of this. Both summaries must be present in the same search definition */ - public void setInherited(DocumentSummary inherited) { + public void setInherited(String inherited) { this.inherited = inherited; } /** Returns the parent of this, or null if none is inherited */ public DocumentSummary getInherited() { + return owner.getSummary(inherited); + } + + /** Returns the name of the summary this was declared to inherit, or null if not sett to inherit anything */ + public String getInheritedName() { return inherited; } + @Override public String toString() { - return "document summary '" + getName() + "'" + - (inherited == null ? "" : " inheriting from '" + inherited.getName() + "'"); + return "document summary '" + getName() + "'"; + } + + public void validate(DeployLogger logger) { + if (inherited != null) { + if ( ! owner.getSummaries().containsKey(inherited)) { + logger.log(Level.WARNING, + this + " inherits " + inherited + " but this" + " is not present in " + owner); + logger.logApplicationPackage(Level.WARNING, + this + " inherits " + inherited + " but this" + " is not present in " + owner); + // TODO: When safe, replace the above by + // throw new IllegalArgumentException(this + " inherits " + inherited + " but this" + + // " is not present in " + owner); + // ... and update SummaryTestCase.testValidationOfInheritedSummary + } + } + } } diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj index 11ebd7c8b3e..19bea494347 100644 --- a/config-model/src/main/javacc/SDParser.jj +++ b/config-model/src/main/javacc/SDParser.jj @@ -1776,7 +1776,7 @@ Object documentSummary(Search search) : } { ( <DOCUMENTSUMMARY> - name = identifierWithDash() { search.addSummary(summary = new DocumentSummary(name)); } + name = identifierWithDash() { search.addSummary(summary = new DocumentSummary(name, search)); } [inheritsDocumentSummary(summary, search)] lbrace() ( @@ -1803,7 +1803,7 @@ void inheritsDocumentSummary(DocumentSummary documentSummary, Search search) : { <INHERITS> name = identifierWithDash() { - documentSummary.setInherited(search.getSummaries().get(name)); + documentSummary.setInherited(name); } } 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 e0a4d0f24ca..4fae4d92cb0 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java @@ -17,6 +17,8 @@ import java.util.List; import java.util.Map; import static java.util.stream.Collectors.toList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author bjorncs @@ -118,16 +120,21 @@ public class DocumentGraphValidatorTest { validator.validateDocumentGraph(documentListOf(adSearch)); } + /** + * Self inheritance is checked early because it is possible, and because it otherwise + * produces a stack overflow before getting to graph validation. + */ @Test public void self_inheritance_forbidden() { - Search adSearch = createSearchWithName("ad"); - SDDocumentType document = adSearch.getDocument(); - document.inherit(document); - - DocumentGraphValidator validator = new DocumentGraphValidator(); - exceptionRule.expect(DocumentGraphValidator.DocumentGraphException.class); - exceptionRule.expectMessage("Document dependency cycle detected: ad->ad."); - validator.validateDocumentGraph(documentListOf(adSearch)); + try { + Search adSearch = createSearchWithName("ad"); + SDDocumentType document = adSearch.getDocument(); + document.inherit(document); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("Document type 'ad' cannot inherit itself", e.getMessage()); + } } private static List<SDDocumentType> documentListOf(Search... searches) { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java index 6b39d046600..fff5c2023b9 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java @@ -40,7 +40,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: foo is invalid: Invocation loop: foo -> foo", + assertEquals("In schema 'test', rank profile 'test': The function 'foo' is invalid: foo is invalid: Invocation loop: foo -> foo", Exceptions.toMessageString(e)); } } @@ -75,7 +75,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: arg(5) is invalid: foo is invalid: arg(5) is invalid: Invocation loop: arg(5) -> foo -> arg(5)", + assertEquals("In schema 'test', rank profile 'test': The function 'foo' is invalid: arg(5) is invalid: foo is invalid: arg(5) is invalid: Invocation loop: arg(5) -> foo -> arg(5)", Exceptions.toMessageString(e)); } } @@ -110,7 +110,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: arg(foo) is invalid: a1 is invalid: foo is invalid: arg(foo) is invalid: Invocation loop: arg(foo) -> foo -> arg(foo)", + assertEquals("In schema 'test', rank profile 'test': The function 'foo' is invalid: arg(foo) is invalid: a1 is invalid: foo is invalid: arg(foo) is invalid: Invocation loop: arg(foo) -> foo -> arg(foo)", Exceptions.toMessageString(e)); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java index f8d03d3574b..35a775d7ad5 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java @@ -216,6 +216,28 @@ public class SummaryTestCase { } } + @Test + public void testValidationOfInheritedSummary() throws ParseException { + try { + String schema = joinLines( + "schema test {" + + " document test {" + + " }" + + " document-summary test_summary inherits nonesuch {" + + " }" + + "}"); + DeployLoggerStub logger = new DeployLoggerStub(); + SearchBuilder.createFromStrings(logger, schema); + assertEquals("document summary 'test_summary' inherits nonesuch but this is not present in schema 'test'", + logger.entries.get(0).message); + // fail("Expected failure"); + } + catch (IllegalArgumentException e) { + // assertEquals("document summary 'test_summary' inherits nonesuch but this is not present in schema 'test'", + // e.getMessage()); + } + } + private static class TestValue { private final DocumentSummary summary; diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java index be2b048f211..8873fc36303 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java @@ -26,7 +26,7 @@ public class UrlFieldValidationTestCase { fail("Should have caused an exception"); // success } catch (IllegalArgumentException e) { - assertEquals("Error in field 'a' in search definition 'test': uri type fields cannot be attributes", + assertEquals("Error in field 'a' in schema 'test': uri type fields cannot be attributes", Exceptions.toMessageString(e)); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java index c82d39e084f..f0fab8e4810 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java @@ -36,7 +36,7 @@ public class AddAttributeTransformToSummaryOfImportedFieldsTest { public void attribute_summary_transform_applied_to_summary_field_of_imported_field() { Search search = createSearchWithDocument(DOCUMENT_NAME); search.setImportedFields(createSingleImportedField(IMPORTED_FIELD_NAME)); - search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME)); + search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, search)); AddAttributeTransformToSummaryOfImportedFields processor = new AddAttributeTransformToSummaryOfImportedFields( search,null,null,null); @@ -65,8 +65,8 @@ public class AddAttributeTransformToSummaryOfImportedFieldsTest { return new ImportedFields(Collections.singletonMap(fieldName, importedField)); } - private static DocumentSummary createDocumentSummary(String fieldName) { - DocumentSummary summary = new DocumentSummary("mysummary"); + private static DocumentSummary createDocumentSummary(String fieldName, Search search) { + DocumentSummary summary = new DocumentSummary("mysummary", search); summary.add(new SummaryField(fieldName, DataType.INT)); return summary; } 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 47e74185902..f9796432de8 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 @@ -200,7 +200,7 @@ public class AdjustPositionSummaryFieldsTestCase { public void addSummaryField(String summaryName, String fieldName, DataType dataType, SummaryTransform transform, String source) { DocumentSummary summary = childSearch.getSummary(summaryName); if (summary == null) { - summary = new DocumentSummary(summaryName); + summary = new DocumentSummary(summaryName, childSearch); childSearch.addSummary(summary); } SummaryField summaryField = new SummaryField(fieldName, dataType); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java index 8fa4c9952ff..3bdcca52236 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java @@ -52,7 +52,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[10],y[3])", + assertEquals("In schema 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[10],y[3])", Exceptions.toMessageString(expected)); } } @@ -100,7 +100,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x{},y{},z{})", + assertEquals("In schema 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x{},y{},z{})", Exceptions.toMessageString(expected)); } } @@ -132,7 +132,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The second-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[10],y[3])", + assertEquals("In schema 'test', rank profile 'my_rank_profile': The second-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[10],y[3])", Exceptions.toMessageString(expected)); } } @@ -162,7 +162,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[10],y[5]) while the 'false' type is tensor(z[10])" + + assertEquals("In schema 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[10],y[5]) while the 'false' type is tensor(z[10])" + "\n'true' branch: attribute(a)" + "\n'false' branch: attribute(b)", Exceptions.toMessageString(expected)); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java index adc146a2047..c7b9ce16338 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java @@ -37,7 +37,7 @@ public class ValidateFieldTypesTest { public void throws_exception_if_type_of_document_field_does_not_match_summary_field() { Search search = createSearchWithDocument(DOCUMENT_NAME); search.setImportedFields(createSingleImportedField(IMPORTED_FIELD_NAME, DataType.INT)); - search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, DataType.STRING)); + search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, DataType.STRING, search)); ValidateFieldTypes validator = new ValidateFieldTypes(search, null, null, null); exceptionRule.expect(IllegalArgumentException.class); @@ -66,8 +66,8 @@ public class ValidateFieldTypesTest { return new ImportedFields(Collections.singletonMap(fieldName, importedField)); } - private static DocumentSummary createDocumentSummary(String fieldName, DataType dataType) { - DocumentSummary summary = new DocumentSummary("mysummary"); + private static DocumentSummary createDocumentSummary(String fieldName, DataType dataType, Search search) { + DocumentSummary summary = new DocumentSummary("mysummary", search); summary.add(new SummaryField(fieldName, dataType)); return summary; } |