diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-12-07 16:08:56 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-12-07 16:08:56 +0100 |
commit | a32bb8795a32367a95e7883fe61c8c9ccd085892 (patch) | |
tree | 135170cf3e7e39d9229c62e061f48c68e0bce236 | |
parent | 10a580357998b4c750729f27d3ef2e224dd69af7 (diff) |
Detect integer fields in fieldsets.
5 files changed, 23 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java b/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java index 7afa2b46693..96c64ff1a1c 100644 --- a/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java +++ b/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java @@ -351,6 +351,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { boolean anyStemming = false; boolean anyNormalizing = false; boolean anyString = false; + boolean anyInteger = false; String phraseSegmentingCommand = null; String stemmingCommand = null; Matching fieldSetMatching = fieldSet.getMatching(); // null if no explicit matching @@ -382,6 +383,10 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { if (explicitPhraseSegmentingCommand.isPresent()) { phraseSegmentingCommand = explicitPhraseSegmentingCommand.get(); } + if (isTypeOrNested(field, DataType.INT) || isTypeOrNested(field, DataType.LONG) || + isTypeOrNested(field, DataType.BYTE)) { + anyInteger = true; + } } if (anyIndexing && anyAttributing && fieldSet.getMatching() == null) { // We have both attributes and indexes and no explicit match setting -> @@ -445,6 +450,9 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { if (anyString) { addIndexCommand(iiB, fieldSet.getName(), CMD_STRING); } + if (anyInteger) { + addIndexCommand(iiB, fieldSet.getName(), CMD_INTEGER); + } if (fieldSetMatching != null) { // Explicit matching set on fieldset if (fieldSetMatching.getType().equals(MatchType.EXACT)) { diff --git a/config-model/src/test/derived/importedfields/index-info.cfg b/config-model/src/test/derived/importedfields/index-info.cfg index 830249b94db..749e8b71a30 100644 --- a/config-model/src/test/derived/importedfields/index-info.cfg +++ b/config-model/src/test/derived/importedfields/index-info.cfg @@ -76,4 +76,6 @@ indexinfo[].command[].command "index" indexinfo[].command[].indexname "myfieldset" indexinfo[].command[].command "string" indexinfo[].command[].indexname "myfieldset" +indexinfo[].command[].command "integer" +indexinfo[].command[].indexname "myfieldset" indexinfo[].command[].command "word" diff --git a/config-model/src/test/derived/indexschema/index-info.cfg b/config-model/src/test/derived/indexschema/index-info.cfg index 3de7adcb930..8c2349e37ea 100644 --- a/config-model/src/test/derived/indexschema/index-info.cfg +++ b/config-model/src/test/derived/indexschema/index-info.cfg @@ -365,6 +365,8 @@ indexinfo[].command[].indexname "fs3" indexinfo[].command[].command "attribute" indexinfo[].command[].indexname "fs3" indexinfo[].command[].command "index" +indexinfo[].command[].indexname "fs3" +indexinfo[].command[].command "integer" indexinfo[].command[].indexname "fs4" indexinfo[].command[].command "lowercase" indexinfo[].command[].indexname "fs4" diff --git a/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java b/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java index 4ea221446a4..29f2d9aff9a 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java +++ b/container-search/src/main/java/com/yahoo/search/yql/YqlParser.java @@ -420,6 +420,10 @@ public class YqlParser implements Parser { if (!index.isInteger() && !stringField) throw new IllegalArgumentException("The in operator is only supported for integer and string fields. The field " + field + " is not of these types"); + if (index.isInteger() && stringField) { + throw new IllegalArgumentException("The in operator is not supported for fieldsets with a mix of integer and string fields. The fieldset " + + field + " has both"); + } Item item = null; if (stringField) { item = fillStringIn(ast, ast.getArgument(1), new StringInItem(field)); diff --git a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java index 178163cf961..783a0ec61de 100644 --- a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java @@ -90,6 +90,10 @@ public class YqlParserTestCase { sd.addIndex(stringIndex); Index floatIndex = new Index("float"); sd.addIndex(floatIndex); + Index mixedIndex = new Index("mixed"); + mixedIndex.setInteger(true); + mixedIndex.setString(true); + sd.addIndex(mixedIndex); return new IndexFacts(new IndexModel(sd)); } @@ -1201,6 +1205,9 @@ public class YqlParserTestCase { assertParseFail("select * from sources * where float in (25)", new IllegalArgumentException("The in operator is only supported for integer and string fields. " + "The field float is not of these types")); + assertParseFail("select * from sources * where mixed in (25)", + new IllegalArgumentException("The in operator is not supported for fieldsets with a mix of integer " + + "and string fields. The fieldset mixed has both")); } private static void assertNumericInItem(String field, long[] values, QueryTree query) { |