diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-09-29 16:42:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-29 16:42:03 +0200 |
commit | 13db8a3ad2408aa1b4841b45de01e987b9244f5d (patch) | |
tree | 96ad0b250aa28600c90cd8cca6891fc06fffe252 /config-model | |
parent | 507e6eef0f00fc55888fee1ab0afc3af8f70eb72 (diff) | |
parent | 2e46f0586b30a6a2c8bd309c6caf9555832417c6 (diff) |
Merge pull request #28699 from vespa-engine/bratseth/smarter-input
Bratseth/smarter input
Diffstat (limited to 'config-model')
29 files changed, 491 insertions, 297 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/document/SDField.java b/config-model/src/main/java/com/yahoo/schema/document/SDField.java index 7821c101880..6cbdb38b9bc 100644 --- a/config-model/src/main/java/com/yahoo/schema/document/SDField.java +++ b/config-model/src/main/java/com/yahoo/schema/document/SDField.java @@ -196,6 +196,8 @@ public class SDField extends Field implements TypedKey, ImmutableSDField { return isExtraField; } + public boolean isDocumentField() { return ! isExtraField; } + @Override public boolean isImportedField() { return false; @@ -613,11 +615,8 @@ public class SDField extends Field implements TypedKey, ImmutableSDField { @Override public RankType getRankType() { return this.rankType; } - /** - * Returns the search-time attribute settings of this field or null if none is set. - * - * <p>TODO: Make unmodifiable.</p> - */ + /** Returns the search-time attribute settings of this field or null if none is set. */ + // TODO: Make unmodifiable @Override public Map<String, Attribute> getAttributes() { return attributes; } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java b/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java index 985ec8653c7..0537f1704ab 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/IndexingInputs.java @@ -31,9 +31,8 @@ public class IndexingInputs extends Processor { ScriptExpression script = field.getIndexingScript(); if (script == null) continue; - String fieldName = field.getName(); - script = (ScriptExpression)new DefaultToCurrentField(fieldName).convert(script); - script = (ScriptExpression)new EnsureInputExpression(fieldName).convert(script); + script = (ScriptExpression)new DefaultToCurrentField(field).convert(script); + script = (ScriptExpression)new EnsureInputExpression(field).convert(script); if (validate) new VerifyInputExpression(schema, field).visit(script); @@ -43,10 +42,10 @@ public class IndexingInputs extends Processor { private static class DefaultToCurrentField extends ExpressionConverter { - final String fieldName; + final SDField field; - DefaultToCurrentField(String fieldName) { - this.fieldName = fieldName; + DefaultToCurrentField(SDField field) { + this.field = field; } @Override @@ -56,27 +55,28 @@ public class IndexingInputs extends Processor { @Override protected Expression doConvert(Expression exp) { - return new InputExpression(fieldName); + return new InputExpression(field.getName()); } } private static class EnsureInputExpression extends ExpressionConverter { - final String fieldName; + final SDField field; - EnsureInputExpression(String fieldName) { - this.fieldName = fieldName; + EnsureInputExpression(SDField field) { + this.field = field; } @Override protected boolean shouldConvert(Expression exp) { - return exp instanceof StatementExpression; + return exp instanceof StatementExpression + && ( field.isDocumentField() || ( field.getAttribute() != null && field.getAttribute().isMutable())); } @Override protected Expression doConvert(Expression exp) { if (exp.requiredInputType() != null) { - return new StatementExpression(new InputExpression(fieldName), exp); + return new StatementExpression(new InputExpression(field.getName()), exp); } else { return exp; } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java b/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java index 3c7e9b4066f..e17b1e46a6e 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/IndexingValidation.java @@ -24,6 +24,7 @@ import com.yahoo.vespa.indexinglanguage.expressions.SummaryExpression; import com.yahoo.vespa.indexinglanguage.expressions.VerificationContext; import com.yahoo.vespa.indexinglanguage.expressions.VerificationException; import com.yahoo.vespa.model.container.search.QueryProfiles; +import com.yahoo.yolean.Exceptions; import java.util.HashSet; import java.util.Set; @@ -51,7 +52,7 @@ public class IndexingValidation extends Processor { converter.convert(exp); // TODO: stop doing this explicitly when visiting a script does not branch } } catch (VerificationException e) { - fail(schema, field, "For expression '" + e.getExpression() + "': " + e.getMessage()); + fail(schema, field, "For expression '" + e.getExpression() + "': " + Exceptions.toMessageString(e)); } } } diff --git a/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java b/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java index 0362dc39c4c..1627320dc54 100644 --- a/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java +++ b/config-model/src/main/java/com/yahoo/schema/processing/PredicateProcessor.java @@ -15,11 +15,11 @@ import com.yahoo.vespa.documentmodel.DocumentSummary; import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; import com.yahoo.vespa.indexinglanguage.ExpressionConverter; +import com.yahoo.vespa.indexinglanguage.expressions.ConstantExpression; import com.yahoo.vespa.indexinglanguage.expressions.Expression; import com.yahoo.vespa.indexinglanguage.expressions.OptimizePredicateExpression; import com.yahoo.vespa.indexinglanguage.expressions.OutputExpression; import com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression; -import com.yahoo.vespa.indexinglanguage.expressions.SetValueExpression; import com.yahoo.vespa.indexinglanguage.expressions.SetVarExpression; import com.yahoo.vespa.indexinglanguage.expressions.StatementExpression; import com.yahoo.vespa.model.container.search.QueryProfiles; @@ -112,14 +112,14 @@ public class PredicateProcessor extends Processor { private Expression makeSetPredicateVariablesScript(BooleanIndexDefinition options) { List<Expression> expressions = new ArrayList<>(); - expressions.add(new SetValueExpression(new IntegerFieldValue(options.getArity()))); + expressions.add(new ConstantExpression(new IntegerFieldValue(options.getArity()))); expressions.add(new SetVarExpression("arity")); if (options.hasLowerBound()) { - expressions.add(new SetValueExpression(new LongFieldValue(options.getLowerBound()))); + expressions.add(new ConstantExpression(new LongFieldValue(options.getLowerBound()))); expressions.add(new SetVarExpression("lower_bound")); } if (options.hasUpperBound()) { - expressions.add(new SetValueExpression(new LongFieldValue(options.getUpperBound()))); + expressions.add(new ConstantExpression(new LongFieldValue(options.getUpperBound()))); expressions.add(new SetVarExpression("upper_bound")); } return new StatementExpression(expressions); diff --git a/config-model/src/test/examples/indexing_attribute_changed.sd b/config-model/src/test/examples/indexing_attribute_changed.sd deleted file mode 100644 index bab878d09ab..00000000000 --- a/config-model/src/test/examples/indexing_attribute_changed.sd +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_attribute_changed { - document indexing_attribute_changed { - field foo type string { - indexing: summary | lowercase | attribute - } - } -} diff --git a/config-model/src/test/examples/indexing_attribute_other.sd b/config-model/src/test/examples/indexing_attribute_other.sd deleted file mode 100644 index e3f58f20910..00000000000 --- a/config-model/src/test/examples/indexing_attribute_other.sd +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_attribute_other { - document indexing_attribute_other { - field foo type string { - indexing: attribute bar - } - } -} diff --git a/config-model/src/test/examples/indexing_extra_field_input_extra_field.sd b/config-model/src/test/examples/indexing_extra_field_input_extra_field.sd deleted file mode 100644 index 315d6c2a677..00000000000 --- a/config-model/src/test/examples/indexing_extra_field_input_extra_field.sd +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_extra_field_input_extra_field { - document indexing_extra_field_input_extra_field { - - } - field foo type string { - - } - field bar type string { - indexing: input bar | index - } -} diff --git a/config-model/src/test/examples/indexing_extra_field_input_implicit.sd b/config-model/src/test/examples/indexing_extra_field_input_implicit.sd deleted file mode 100644 index 8aff3284ce3..00000000000 --- a/config-model/src/test/examples/indexing_extra_field_input_implicit.sd +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_extra_field_input_implicit { - document indexing_extra_field_input_implicit { - - } - field foo type string { - indexing: index - } -} diff --git a/config-model/src/test/examples/indexing_extra_field_input_null.sd b/config-model/src/test/examples/indexing_extra_field_input_null.sd deleted file mode 100644 index c4600fa680a..00000000000 --- a/config-model/src/test/examples/indexing_extra_field_input_null.sd +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_extra_field_input_null { - document indexing_extra_field_input_null { - - } - field foo type string { - indexing: input foo | index - } -} diff --git a/config-model/src/test/examples/indexing_extra_field_input_self.sd b/config-model/src/test/examples/indexing_extra_field_input_self.sd deleted file mode 100644 index 36dbae21449..00000000000 --- a/config-model/src/test/examples/indexing_extra_field_input_self.sd +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_extra_field_input_self { - document indexing_extra_field_input_self { - - } - field foo type string { - indexing: input foo | index - } -} diff --git a/config-model/src/test/examples/indexing_index_changed.sd b/config-model/src/test/examples/indexing_index_changed.sd deleted file mode 100644 index 194a9bd3177..00000000000 --- a/config-model/src/test/examples/indexing_index_changed.sd +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_index_changed { - document indexing_index_changed { - field foo type string { - indexing: attribute | lowercase | index - } - } -} diff --git a/config-model/src/test/examples/indexing_index_other.sd b/config-model/src/test/examples/indexing_index_other.sd deleted file mode 100644 index 40b8b150a5b..00000000000 --- a/config-model/src/test/examples/indexing_index_other.sd +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_index_other { - document indexing_index_other { - field foo type string { - indexing: index bar - } - } -} diff --git a/config-model/src/test/examples/indexing_modify_field_no_output.sd b/config-model/src/test/examples/indexing_modify_field_no_output.sd deleted file mode 100644 index ac2bed520e8..00000000000 --- a/config-model/src/test/examples/indexing_modify_field_no_output.sd +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_modify_field_no_output { - document indexing_modify_field_no_output { - field foo type string { - indexing: lowercase | echo - } - } -} diff --git a/config-model/src/test/examples/indexing_output_conflict.sd b/config-model/src/test/examples/indexing_output_conflict.sd deleted file mode 100644 index 9cf1cbc0823..00000000000 --- a/config-model/src/test/examples/indexing_output_conflict.sd +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_output_confict { - document indexing_output_confict { - field foo type string { - - } - } - field bar type string { - indexing: input foo | attribute | lowercase | index - } -} diff --git a/config-model/src/test/examples/indexing_output_other_field.sd b/config-model/src/test/examples/indexing_output_other_field.sd deleted file mode 100644 index 40b08bb15b2..00000000000 --- a/config-model/src/test/examples/indexing_output_other_field.sd +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_output_other_field { - document indexing_output_other_field { - field foo type string { - indexing: index bar - } - } - field bar type string { - - } -} diff --git a/config-model/src/test/examples/indexing_summary_other.sd b/config-model/src/test/examples/indexing_summary_other.sd deleted file mode 100644 index 871ab854c51..00000000000 --- a/config-model/src/test/examples/indexing_summary_other.sd +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search indexing_summary_other { - document indexing_summary_other { - field foo type string { - indexing: summary bar - } - } -} diff --git a/config-model/src/test/examples/matchphase/non_existing_attribute.sd b/config-model/src/test/examples/matchphase/non_existing_attribute.sd deleted file mode 100644 index cd3842fde8a..00000000000 --- a/config-model/src/test/examples/matchphase/non_existing_attribute.sd +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search test { - document test { - field foo type int { - indexing: summary - } - } - rank-profile default { - match-phase { - attribute: foo - max-hits: 100 - } - } -} diff --git a/config-model/src/test/examples/matchphase/non_fast_search_attribute.sd b/config-model/src/test/examples/matchphase/non_fast_search_attribute.sd deleted file mode 100644 index 5fde096cf61..00000000000 --- a/config-model/src/test/examples/matchphase/non_fast_search_attribute.sd +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search test { - document test { - field foo type int { - indexing: attribute - } - } - rank-profile default { - match-phase { - attribute: foo - max-hits: 100 - } - } -} diff --git a/config-model/src/test/examples/matchphase/wrong_collection_type_attribute.sd b/config-model/src/test/examples/matchphase/wrong_collection_type_attribute.sd deleted file mode 100644 index 8a9166c94f7..00000000000 --- a/config-model/src/test/examples/matchphase/wrong_collection_type_attribute.sd +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search test { - document test { - field foo type array<int> { - indexing: attribute - } - } - rank-profile default { - match-phase { - attribute: foo - max-hits: 100 - } - } -} diff --git a/config-model/src/test/examples/matchphase/wrong_data_type_attribute.sd b/config-model/src/test/examples/matchphase/wrong_data_type_attribute.sd deleted file mode 100644 index d4f526569ea..00000000000 --- a/config-model/src/test/examples/matchphase/wrong_data_type_attribute.sd +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -search test { - document test { - field foo type string { - indexing: attribute - } - } - rank-profile default { - match-phase { - attribute: foo - max-hits: 100 - } - } -} diff --git a/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java b/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java index 3ca182e18c2..db862dd388e 100644 --- a/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/AttributeSettingsTestCase.java @@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.*; /** * Attribute settings * - * @author bratseth + * @author bratseth */ public class AttributeSettingsTestCase extends AbstractSchemaTestCase { diff --git a/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java b/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java index e69f26a31c9..89eff4ec464 100644 --- a/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/parser/SchemaParserTestCase.java @@ -269,7 +269,6 @@ public class SchemaParserTestCase { checkFileParses("src/test/examples/implicitsummaryfields.sd"); checkFileParses("src/test/examples/incorrectrankingexpressionfileref.sd"); checkFileParses("src/test/examples/indexing_extra.sd"); - checkFileParses("src/test/examples/indexing_modify_field_no_output.sd"); checkFileParses("src/test/examples/indexing.sd"); checkFileParses("src/test/examples/indexrewrite.sd"); checkFileParses("src/test/examples/indexsettings.sd"); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java b/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java index f9c1e992347..36f20c18588 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java @@ -38,6 +38,6 @@ public abstract class AssertIndexingScript { String str = actualExp.toString(); assertTrue(parsedExpected.remove(str), "Unexpected: " + str); } - assertTrue(parsedExpected.isEmpty(), "Missing: " + parsedExpected.toString()); + assertTrue(parsedExpected.isEmpty(), "Missing: " + parsedExpected); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java b/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java deleted file mode 100644 index 12da3f0797b..00000000000 --- a/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.schema.processing; - -import com.yahoo.schema.ApplicationBuilder; -import com.yahoo.schema.parser.ParseException; - -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * @author Simon Thoresen Hult - */ -public abstract class AssertSearchBuilder { - - public static void assertBuilds(String searchDefinitionFileName) throws IOException, ParseException { - assertNotNull(ApplicationBuilder.buildFromFile(searchDefinitionFileName)); - } - - public static void assertBuildFails(String searchDefinitionFileName, String expectedException) - throws IOException, ParseException { - try { - ApplicationBuilder.buildFromFile(searchDefinitionFileName); - fail(searchDefinitionFileName); - } catch (IllegalArgumentException e) { - assertEquals(expectedException, e.getMessage()); - } - } -} diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java index d420623f233..675168ca6c2 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java @@ -1,45 +1,165 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.schema.processing; +import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; +import com.yahoo.yolean.Exceptions; import org.junit.jupiter.api.Test; -import java.io.IOException; - -import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Simon Thoresen Hult + * @author bratseth */ public class IndexingInputsTestCase { @Test - void requireThatExtraFieldInputExtraFieldThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_extra_field_input_extra_field.sd", - "For schema 'indexing_extra_field_input_extra_field', field 'bar': Indexing script refers " + - "to field 'bar' which is neither a field in document type " + - "'indexing_extra_field_input_extra_field' nor a mutable attribute"); + void requireThatExtraFieldInputExtraFieldThrows() throws ParseException { + try { + var schema = """ + search indexing_extra_field_input_extra_field { + document indexing_extra_field_input_extra_field { + } + field foo type string { + } + field bar type string { + indexing: input bar | index + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_extra_field_input_extra_field', field 'bar': Indexing script refers " + + "to field 'bar' which is neither a field in document type " + + "'indexing_extra_field_input_extra_field' nor a mutable attribute", + Exceptions.toMessageString(e)); + } + } + + @Test + void requireThatExtraFieldInputImplicitThrows() throws ParseException { + try { + var schema = """ + search indexing_extra_field_input_implicit { + document indexing_extra_field_input_implicit { + } + field foo type string { + indexing: index + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_extra_field_input_implicit', field 'foo': " + + "For expression '{ tokenize normalize stem:\"BEST\" | index foo; }': Expected string input, but no input is specified", + Exceptions.toMessageString(e)); + } + } + + @Test + void requireThatExtraFieldInputNullThrows() throws ParseException { + try { + var schema = """ + search indexing_extra_field_input_null { + document indexing_extra_field_input_null { + } + field foo type string { + indexing: input foo | index + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_extra_field_input_null', field 'foo': Indexing script refers to field " + + "'foo' which is neither a field in document type 'indexing_extra_field_input_null' nor a mutable attribute", + Exceptions.toMessageString(e)); + } + } + + @Test + void requireThatExtraFieldInputSelfThrows() throws ParseException { + try { + var schema = """ + search indexing_extra_field_input_self { + document indexing_extra_field_input_self { + } + field foo type string { + indexing: input foo | index + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_extra_field_input_self', field 'foo': Indexing script refers to field " + + "'foo' which is neither a field in document type 'indexing_extra_field_input_self' nor a mutable attribute", + Exceptions.toMessageString(e)); + } } @Test - void requireThatExtraFieldInputImplicitThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_extra_field_input_implicit.sd", - "For schema 'indexing_extra_field_input_implicit', field 'foo': Indexing script refers to " + - "field 'foo' which is neither a field in document type 'indexing_extra_field_input_implicit' nor a mutable attribute"); + void testPlainInputInDerivedField() throws ParseException { + var schema = """ + schema test { + document test { + field field1 type int { + } + } + field derived1 type int { + indexing: input field1 | attribute + } + } + """; + ApplicationBuilder.createFromString(schema); } @Test - void requireThatExtraFieldInputNullThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_extra_field_input_null.sd", - "For schema 'indexing_extra_field_input_null', field 'foo': Indexing script refers to field " + - "'foo' which is neither a field in document type 'indexing_extra_field_input_null' nor a mutable attribute"); + void testWrappedInputInDerivedField() throws ParseException { + var schema = """ + schema test { + document test { + field field1 type int { + } + } + field derived1 type int { + indexing: if (input field1 == 0) { 0 } else { 1 } | attribute + } + } + """; + ApplicationBuilder.createFromString(schema); } @Test - void requireThatExtraFieldInputSelfThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_extra_field_input_self.sd", - "For schema 'indexing_extra_field_input_self', field 'foo': Indexing script refers to field " + - "'foo' which is neither a field in document type 'indexing_extra_field_input_self' nor a mutable attribute"); + void testNoInputInDerivedField() throws ParseException { + try { + var schema = """ + schema test { + document test { + field field1 type int { + } + } + field derived1 type int { + indexing: attribute + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'test', field 'derived1': For expression '{ attribute derived1; }': " + + "Expected any input, but no input is specified", + Exceptions.toMessageString(e)); + } } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java index e707d203381..7557ca5b725 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java @@ -1,13 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.schema.processing; +import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; +import com.yahoo.yolean.Exceptions; import org.junit.jupiter.api.Test; -import java.io.IOException; - -import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Simon Thoresen Hult @@ -15,16 +15,51 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; public class IndexingOutputsTestCase { @Test - void requireThatOutputOtherFieldThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_output_other_field.sd", - "For schema 'indexing_output_other_field', field 'foo': Indexing expression 'index bar' " + - "attempts to write to a field other than 'foo'."); + void requireThatOutputOtherFieldThrows() throws ParseException { + try { + var schema = """ + search indexing_output_other_field { + document indexing_output_other_field { + field foo type string { + indexing: index bar + } + } + field bar type string { + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_output_other_field', field 'foo': Indexing expression 'index bar' " + + "attempts to write to a field other than 'foo'.", + Exceptions.toMessageString(e)); + } } @Test - void requireThatOutputConflictThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_output_conflict.sd", - "For schema 'indexing_output_confict', field 'bar': For expression 'index bar': Attempting " + - "to assign conflicting values to field 'bar'."); + void requireThatOutputConflictThrows() throws ParseException { + try { + var schema = """ + search indexing_output_confict { + document indexing_output_confict { + field foo type string { + } + } + field bar type string { + indexing: input foo | attribute | lowercase | index + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_output_confict', field 'bar': For expression 'index bar': Attempting " + + "to assign conflicting values to field 'bar'.", + Exceptions.toMessageString(e)); + } } + } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java index aa8a2922e8f..4343abbf548 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java @@ -4,13 +4,15 @@ package com.yahoo.schema.processing; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.derived.AbstractExportingTestCase; import com.yahoo.schema.parser.ParseException; +import com.yahoo.yolean.Exceptions; import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; import static com.yahoo.schema.processing.AssertIndexingScript.assertIndexing; -import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Simon Thoresen Hult @@ -18,45 +20,135 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; public class IndexingValidationTestCase extends AbstractExportingTestCase { @Test - void testAttributeChanged() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_attribute_changed.sd", - "For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " + - "Attempting to assign conflicting values to field 'foo'."); + void testAttributeChanged() throws ParseException { + try { + var schema = """ + search indexing_attribute_changed { + document indexing_attribute_changed { + field foo type string { + indexing: summary | lowercase | attribute + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " + + "Attempting to assign conflicting values to field 'foo'.", + Exceptions.toMessageString(e)); + } } @Test - void testAttributeOther() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_attribute_other.sd", - "For schema 'indexing_attribute_other', field 'foo': Indexing expression 'attribute bar' " + - "attempts to write to a field other than 'foo'."); + void testAttributeOther() throws ParseException { + try { + var schema = """ + search indexing_attribute_other { + document indexing_attribute_other { + field foo type string { + indexing: attribute bar + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_attribute_other', field 'foo': Indexing expression 'attribute bar' " + + "attempts to write to a field other than 'foo'.", + Exceptions.toMessageString(e)); + } } @Test - void testIndexChanged() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_index_changed.sd", - "For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " + - "Attempting to assign conflicting values to field 'foo'."); + void testIndexChanged() throws ParseException { + try { + var schema = """ + search indexing_index_changed { + document indexing_index_changed { + field foo type string { + indexing: attribute | lowercase | index + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " + + "Attempting to assign conflicting values to field 'foo'.", + Exceptions.toMessageString(e)); + } } @Test - void testIndexOther() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_index_other.sd", - "For schema 'indexing_index_other', field 'foo': Indexing expression 'index bar' " + - "attempts to write to a field other than 'foo'."); + void testIndexOther() throws ParseException { + try { + var schema = """ + search indexing_index_other { + document indexing_index_other { + field foo type string { + indexing: index bar\s + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_index_other', field 'foo': Indexing expression 'index bar' " + + "attempts to write to a field other than 'foo'.", + Exceptions.toMessageString(e)); + } } @Test - void testSummaryChanged() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_summary_changed.sd", - "For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " + - "to assign conflicting values to field 'foo'."); + void testSummaryChanged() throws ParseException { + try { + var schema = """ + search indexing_summary_fail { + document indexing_summary_fail { + field foo type string { + indexing: index | lowercase | summary\s + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " + + "to assign conflicting values to field 'foo'.", + Exceptions.toMessageString(e)); + } } @Test - void testSummaryOther() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_summary_other.sd", - "For schema 'indexing_summary_other', field 'foo': Indexing expression 'summary bar' " + - "attempts to write to a field other than 'foo'."); + void testSummaryOther() throws ParseException { + try { + var schema = """ + search indexing_summary_other { + document indexing_summary_other { + field foo type string { + indexing: summary bar + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_summary_other', field 'foo': Indexing expression 'summary bar' " + + "attempts to write to a field other than 'foo'.", + Exceptions.toMessageString(e)); + } } @Test @@ -68,9 +160,35 @@ public class IndexingValidationTestCase extends AbstractExportingTestCase { } @Test - void requireThatMultilineOutputConflictThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_multiline_output_conflict.sd", - "For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " + - "Attempting to assign conflicting values to field 'cox'."); + void requireThatMultilineOutputConflictThrows() throws ParseException { + try { + var schema = """ + search indexing_multiline_output_confict { + document indexing_multiline_output_confict { + field foo type string { + } + field bar type string { + } + field baz type string { + } + } + field cox type string { + indexing { + input foo | attribute; + input bar | index; + input baz | summary; + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " + + "Attempting to assign conflicting values to field 'cox'.", + Exceptions.toMessageString(e)); + } } + } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java index 1f723924db6..c46b4fc2c7d 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java @@ -1,13 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.schema.processing; +import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; +import com.yahoo.yolean.Exceptions; import org.junit.jupiter.api.Test; import java.io.IOException; -import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; -import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuilds; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Simon Thoresen Hult @@ -15,16 +17,43 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuilds; public class IndexingValuesTestCase { @Test - void requireThatModifyFieldNoOutputDoesNotThrow() throws IOException, ParseException { - assertBuilds("src/test/examples/indexing_modify_field_no_output.sd"); + void requireThatModifyFieldNoOutputDoesNotThrow() throws ParseException { + var schema = """ + search indexing_modify_field_no_output { + document indexing_modify_field_no_output { + field foo type string { + indexing: lowercase | echo + } + } + } + """; + ApplicationBuilder.createFromString(schema); } @Test void requireThatInputOtherFieldThrows() throws IOException, ParseException { - assertBuildFails("src/test/examples/indexing_input_other_field.sd", - "For schema 'indexing_input_other_field', field 'bar': Indexing expression 'input foo' " + - "attempts to modify the value of the document field 'bar'. " + - "Use a field outside the document block instead."); + try { + var schema = """ + search indexing_input_other_field { + document indexing_input_other_field { + field foo type string { + + } + field bar type string { + indexing: input foo | attribute | index | summary + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For schema 'indexing_input_other_field', field 'bar': Indexing expression 'input foo' " + + "attempts to modify the value of the document field 'bar'. " + + "Use a field outside the document block instead.", + Exceptions.toMessageString(e)); + } } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java index cbddea8ea6a..85ec80d2610 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java @@ -1,9 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.schema.processing; +import com.yahoo.schema.ApplicationBuilder; +import com.yahoo.yolean.Exceptions; import org.junit.jupiter.api.Test; -import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class MatchPhaseSettingsValidatorTestCase { @@ -13,25 +16,109 @@ public class MatchPhaseSettingsValidatorTestCase { @Test void requireThatAttributeMustExists() throws Exception { - assertBuildFails("src/test/examples/matchphase/non_existing_attribute.sd", - getMessagePrefix() + "does not exists"); + try { + var schema = """ + search test { + document test { + field foo type int { + indexing: summary + } + } + rank-profile default { + match-phase { + attribute: foo + max-hits: 100 + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals(getMessagePrefix() + "does not exists", Exceptions.toMessageString(e)); + } } @Test void requireThatAttributeMustBeNumeric() throws Exception { - assertBuildFails("src/test/examples/matchphase/wrong_data_type_attribute.sd", - getMessagePrefix() + "must be single value numeric, but it is 'string'"); + try { + var schema = """ + search test { + document test { + field foo type string { + indexing: attribute + } + } + rank-profile default { + match-phase { + attribute: foo + max-hits: 100 + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals(getMessagePrefix() + "must be single value numeric, but it is 'string'", + Exceptions.toMessageString(e)); + } } @Test void requireThatAttributeMustBeSingleValue() throws Exception { - assertBuildFails("src/test/examples/matchphase/wrong_collection_type_attribute.sd", - getMessagePrefix() + "must be single value numeric, but it is 'Array<int>'"); + try { + var schema = """ + search test { + document test { + field foo type array<int> { + indexing: attribute + } + } + rank-profile default { + match-phase { + attribute: foo + max-hits: 100 + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals(getMessagePrefix() + "must be single value numeric, but it is 'Array<int>'", + Exceptions.toMessageString(e)); + } } @Test void requireThatAttributeMustHaveFastSearch() throws Exception { - assertBuildFails("src/test/examples/matchphase/non_fast_search_attribute.sd", - getMessagePrefix() + "must be fast-search, but it is not"); + try { + var schema = """ + search test { + document test { + field foo type int { + indexing: attribute + } + } + rank-profile default { + match-phase { + attribute: foo + max-hits: 100 + } + } + } + """; + ApplicationBuilder.createFromString(schema); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals(getMessagePrefix() + "must be fast-search, but it is not", + Exceptions.toMessageString(e)); + } } + } |