summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2019-02-04 13:56:02 +0100
committerGitHub <noreply@github.com>2019-02-04 13:56:02 +0100
commit7285aa2d3f2e8cd6cee90c063c4c29076adb094e (patch)
tree1bbc34148d1b455088513f78d4725270f25d264a /config-model
parent14172aa5cd890445980202909d1277429e4c5a3a (diff)
Revert "Bratseth/disallow dash rebased"
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/javacc/SDParser.jj54
-rw-r--r--config-model/src/test/examples/invalid-name.sd12
-rw-r--r--config-model/src/test/examples/simple-with-weird-name.sd13
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java35
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java13
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java2
6 files changed, 70 insertions, 59 deletions
diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj
index f2eb45205df..883dfc7ac72 100644
--- a/config-model/src/main/javacc/SDParser.jj
+++ b/config-model/src/main/javacc/SDParser.jj
@@ -357,8 +357,7 @@ TOKEN :
| < CONSTANTS: "constants" >
| < FILE: "file" >
| < URI: "uri" >
-| < IDENTIFIER: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_"])* >
-| < IDENTIFIER_WITH_DASH: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_","-"])* >
+| < IDENTIFIER: ["a"-"z","A"-"Z", "_"] (["a"-"z","A"-"Z","0"-"9","_","-"])* >
| < QUOTEDSTRING: "\"" ( ~["\""] )* "\"" >
| < CONTEXT: ["a"-"z","A"-"Z"] (["a"-"z", "A"-"Z", "0"-"9"])* >
| < DOUBLE: ("-")? (["0"-"9"])+ "." (["0"-"9"])+ >
@@ -416,7 +415,10 @@ Search rootSearch(String dir) :
Search search;
}
{
- ( <SEARCH> name = identifier() { search = new Search(name, app);
+ ( <SEARCH> name = identifier() { if (!name.matches("[a-zA-Z_][a-zA-Z_:0-9]*")) {
+ deployLogger.log(Level.WARNING, name + " can not be used in YQL+ expressions.");
+ }
+ search = new Search(name, app);
rankProfileRegistry.add(new DefaultRankProfile(search, rankProfileRegistry));
rankProfileRegistry.add(new UnrankedRankProfile(search, rankProfileRegistry));}
lbrace() (rootSearchItem(search) (<NL>)*)* <RBRACE> (<NL>)* <EOF>)
@@ -667,15 +669,14 @@ void fieldSetItem(String setName, Search search) :
( <FIELDS><COLON> field=identifier() { search.fieldSets().addUserFieldSetItem(setName, field); }
( <COMMA> field=identifier() { search.fieldSets().addUserFieldSetItem(setName, field); } )* )
|
- ( <QUERYCOMMAND> <COLON> (queryCommand = identifierWithDash() | queryCommand = quotedString())) { search.fieldSets().userFieldSets().get(setName).queryCommands().add(queryCommand);}
+ ( <QUERYCOMMAND> <COLON> (queryCommand = identifier() | queryCommand = quotedString())) { search.fieldSets().userFieldSets().get(setName).queryCommands().add(queryCommand);}
|
( match(matchSettings) ) { matchSettings.applyOperations(); search.fieldSets().userFieldSets().get(setName).setMatching(matchSettings.getMatching());}
}
/**
* This rule consumes a annotation block from within either a document element or a search element.
-
- * @param search the search object to add content to.
+ * @param search The search object to add content to.
*/
void annotationOutside(Search search) :
{
@@ -697,7 +698,6 @@ void annotationOutside(Search search) :
/**
* This rule consumes a annotation block from within either a document element.
- *
* @param document The document object to add content to.
*/
void annotation(Search search, SDDocumentType document) :
@@ -1183,7 +1183,7 @@ Object sortingSetting(SortingOperation sorting, String attributeName) :
| <QUATERNARY> { sorting.setStrength(Sorting.Strength.QUATERNARY); }
| <IDENTICAL> { sorting.setStrength(Sorting.Strength.IDENTICAL); }
)
- | <LOCALE> <COLON> locale = identifierWithDash() { sorting.setLocale(locale); }
+ | <LOCALE> <COLON> locale = identifier() { sorting.setLocale(locale); }
)
{ return null; }
}
@@ -1426,7 +1426,7 @@ void summaryProperty(SummaryInFieldLongOperation field) :
String name, value;
}
{
- name = identifierWithDash() <COLON> (value = identifierWithDash() | value = quotedString())
+ name = identifier() <COLON> (value = identifier() | value = quotedString())
{ field.addProperty(new SummaryField.Property(name, value)); }
}
@@ -1441,7 +1441,7 @@ void fieldStemming(FieldOperationContainer field) :
StemmingOperation op = new StemmingOperation();
}
{
- <STEMMING> <COLON> setting = identifierWithDash()
+ <STEMMING> <COLON> setting = identifier()
{
op.setSetting(setting);
field.addOperation(op);
@@ -1458,7 +1458,7 @@ void searchStemming(Search search) :
String setting;
}
{
- <STEMMING> <COLON> setting = identifierWithDash()
+ <STEMMING> <COLON> setting = identifier()
{ search.setStemming(Stemming.get(setting)); }
}
@@ -1473,7 +1473,7 @@ void normalizing(FieldOperationContainer field) :
String setting;
}
{
- <NORMALIZING> <COLON> setting = identifierWithDash()
+ <NORMALIZING> <COLON> setting = identifier()
{
field.addOperation(new NormalizingOperation(setting));
}
@@ -1527,7 +1527,7 @@ void queryCommand(FieldOperationContainer container) :
QueryCommandOperation field = new QueryCommandOperation();
}
{
- <QUERYCOMMAND> <COLON> command = identifierWithDash()
+ <QUERYCOMMAND> <COLON> command = identifier()
{
field.addQueryCommand(command);
container.addOperation(field);
@@ -1540,7 +1540,7 @@ void alias(FieldOperationContainer container) :
String alias;
}
{
- <ALIAS> [aliasedName = identifier()] <COLON> alias = identifierWithDash()
+ <ALIAS> [aliasedName = identifier()] <COLON> alias = identifier()
{
AliasOperation op = new AliasOperation(aliasedName, alias);
container.addOperation(op);
@@ -1773,9 +1773,9 @@ Object indexBody(IndexOperation index) :
double threshold;
}
{
- ( <PREFIX> { index.setPrefix(true); }
- | <ALIAS> <COLON> str = identifierWithDash() { index.addAlias(str); }
- | <STEMMING> <COLON> str = identifierWithDash() { index.setStemming(str); }
+ ( <PREFIX> { index.setPrefix(true); }
+ | <ALIAS> <COLON> str = identifier() { index.addAlias(str); }
+ | <STEMMING> <COLON> str = identifier() { index.setStemming(str); }
| <ARITY> <COLON> arity = integer() { index.setArity(arity); }
| <LOWERBOUND> <COLON> num = consumeLong() { index.setLowerBound(num); }
| <UPPERBOUND> <COLON> num = consumeLong() { index.setUpperBound(num); }
@@ -1855,7 +1855,7 @@ void rankProfile(Search search) :
RankProfile profile;
}
{
- ( <RANKPROFILE> name = identifierWithDash()
+ ( <RANKPROFILE> name = identifier()
{
if (documentsOnly) {
profile = new DocumentsOnlyRankProfile(name, search, rankProfileRegistry);
@@ -1912,7 +1912,7 @@ void inheritsRankProfile(RankProfile profile) :
String str;
}
{
- <INHERITS> str = identifierWithDash()
+ <INHERITS> str = identifier()
{ profile.setInherited(str); }
}
@@ -2211,9 +2211,9 @@ String rankPropertyItem() :
String image, ret = "";
}
{
- ( ( image = identifierWithDash() { ret += image; }
- | image = quotedString() { ret += image; }
- | ( "(" | ")" | <DOT> | <COMMA> ) { ret += token.image; } )+ )
+ ( ( image = identifier() { ret += image; }
+ | image = quotedString() { ret += image; }
+ | ( "(" | ")" | <DOT> | <COMMA> ) { ret += token.image; } )+ )
{ return ret; }
}
@@ -2454,16 +2454,6 @@ String expression() :
{ return exp; }
}
-String identifierWithDash() :
-{
- String identifier;
-}
-{
- ( identifier = identifier() { return identifier; } )
- |
- ( <IDENTIFIER_WITH_DASH> { return token.image; } )
-}
-
/**
* This rule consumes an identifier. This must be kept in sync with all word tokens that should be parseable as
* identifiers.
diff --git a/config-model/src/test/examples/invalid-name.sd b/config-model/src/test/examples/invalid-name.sd
deleted file mode 100644
index f26fcc723f4..00000000000
--- a/config-model/src/test/examples/invalid-name.sd
+++ /dev/null
@@ -1,12 +0,0 @@
-# Dashes in names are not allowed
-search invalid-name {
-
- document invalid-name {
-
- field title type string {
-
- }
-
- }
-
-} \ No newline at end of file
diff --git a/config-model/src/test/examples/simple-with-weird-name.sd b/config-model/src/test/examples/simple-with-weird-name.sd
new file mode 100644
index 00000000000..109f4f7bba7
--- /dev/null
+++ b/config-model/src/test/examples/simple-with-weird-name.sd
@@ -0,0 +1,13 @@
+# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# A minimal doc with name which is incompatible with YQL+
+search simple-with-weird-name {
+
+ document simple-with-weird-name {
+
+ field title type string {
+ indexing: summary | index
+ }
+
+ }
+
+}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java
index a26154fc8da..278471cb37a 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/SearchDefinitionsParsingTestCase.java
@@ -73,16 +73,35 @@ public class SearchDefinitionsParsingTestCase extends SearchDefinitionTestCase {
}
}
- @Test
- public void illegalSearchDefinitionName() throws IOException, ParseException {
- try {
- SearchBuilder.buildFromFile("src/test/examples/invalid-name.sd");
- fail("Name with dash passed");
- } catch (ParseException e) {
- if ( ! e.getMessage().contains("invalid-name")) {
- throw e;
+ private static class WarningCatcher extends Handler {
+ volatile boolean gotYqlWarning = false;
+
+ @Override
+ public void publish(LogRecord record) {
+ if (record.getLevel() == Level.WARNING && record.getMessage().indexOf("YQL") >= 0) {
+ gotYqlWarning = true;
}
}
+
+ @Override
+ public void flush() {
+ // intentionally left blank
+ }
+
+ @Override
+ public void close() throws SecurityException {
+ // intentionally left blank
+ }
}
+
+ @Test
+ public void requireYqlCompatibilityIsTested() throws Exception {
+ Logger log = Logger.getLogger("DeployLogger");
+ WarningCatcher w = new WarningCatcher();
+ log.addHandler(w);
+ assertNotNull(SearchBuilder.buildFromFile("src/test/examples/simple-with-weird-name.sd"));
+ log.removeHandler(w);
+ assertTrue(w.gotYqlWarning);
+ }
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java
index 4180f9f6de4..30f1df6a394 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.*;
/**
* @author gjoranv
+ * @since 5.1.10
*/
public class SearchBuilderTest extends ContainerModelBuilderTestBase {
@@ -34,7 +35,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase {
}
@Test
- public void gui_search_handler_is_always_included_when_search_is_specified() {
+ public void gui_search_handler_is_always_included_when_search_is_specified() throws Exception{
Element clusterElem = DomBuilderTest.parse(
"<jdisc id='default' version='1.0'>",
" <search />",
@@ -60,7 +61,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase {
@Test
- public void search_handler_bindings_can_be_overridden() {
+ public void search_handler_bindings_can_be_overridden() throws Exception {
Element clusterElem = DomBuilderTest.parse(
"<jdisc id='default' version='1.0'>",
" <search>",
@@ -79,7 +80,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase {
}
@Test
- public void search_handler_bindings_can_be_disabled() {
+ public void search_handler_bindings_can_be_disabled() throws Exception {
Element clusterElem = DomBuilderTest.parse(
"<jdisc id='default' version='1.0'>",
" <search>",
@@ -110,7 +111,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase {
assertThat(chainsConfig().chains(), hasItemWithMethod("vespa", "id"));
}
- private void createClusterWithOnlyDefaultChains() {
+ private void createClusterWithOnlyDefaultChains() throws SAXException, IOException {
Element containerElem = DomBuilderTest.parse(
"<jdisc id='default' version='1.0'>",
" <search/>",
@@ -123,7 +124,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase {
}
@Test
- public void manually_setting_up_search_handler_is_forbidden() {
+ public void manually_setting_up_search_handler_is_forbidden() throws IOException, SAXException {
try {
Element clusterElem = DomBuilderTest.parse(
"<jdisc id='default' version='1.0'>",
@@ -192,7 +193,7 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase {
}
- private VespaModel getVespaModelWithMusic(String hosts, String services) {
+ private VespaModel getVespaModelWithMusic(String hosts, String services) throws ParseException {
return new VespaModelCreatorWithMockPkg(hosts, services, ApplicationPackageUtils.generateSearchDefinitions("music")).create();
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java
index 66f59717407..0ad5fb3b0bd 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/content/ReservedDocumentTypeNameValidatorTest.java
@@ -47,7 +47,7 @@ public class ReservedDocumentTypeNameValidatorTest {
public void validation_is_case_insensitive() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The following document types conflict with reserved keyword names: " +
- "'NULL', 'True', 'anD'.");
+ "'NULL', 'True', 'anD'.");
ReservedDocumentTypeNameValidator validator = new ReservedDocumentTypeNameValidator();
Map<String, NewDocumentType> orderedDocTypes = new TreeMap<>(asDocTypeMapping(Arrays.asList("NULL", "True", "anD")));