From 9958447debaf3a924017b03dbc38e682d44f417d Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Fri, 17 Jan 2025 14:37:46 +0100 Subject: [PATCH 1/2] Add all operators to error message for select queries Also reorder switch statements. No funcational changes. --- .../main/java/com/yahoo/search/query/SelectParser.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/container-search/src/main/java/com/yahoo/search/query/SelectParser.java b/container-search/src/main/java/com/yahoo/search/query/SelectParser.java index df9d95892eda..c482923e93b9 100644 --- a/container-search/src/main/java/com/yahoo/search/query/SelectParser.java +++ b/container-search/src/main/java/com/yahoo/search/query/SelectParser.java @@ -187,13 +187,13 @@ private Item walkJson(Inspector inspector) { switch (type) { case AND -> item[0] = buildAnd(key, value); case AND_NOT -> item[0] = buildNotAnd(key, value); - case OR -> item[0] = buildOr(key, value); - case EQ -> item[0] = buildEquals(key, value); - case RANGE -> item[0] = buildRange(key, value); + case CALL -> item[0] = buildFunctionCall(key, value); case CONTAINS -> item[0] = buildTermSearch(key, value); + case EQ -> item[0] = buildEquals(key, value); case MATCHES -> item[0] = buildRegExpSearch(key, value); - case CALL -> item[0] = buildFunctionCall(key, value); - default -> throw newUnexpectedArgumentException(key, AND, CALL, CONTAINS, EQ, OR, RANGE, AND_NOT); + case OR -> item[0] = buildOr(key, value); + case RANGE -> item[0] = buildRange(key, value); + default -> throw newUnexpectedArgumentException(key, AND, AND_NOT, CALL, CONTAINS, EQ, MATCHES, OR, RANGE); } }); return item[0]; From 4a84b9fe8c044da60c0f749dc188e460f14e72bb Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Sat, 18 Jan 2025 11:08:08 +0100 Subject: [PATCH 2/2] Support json query with "where: " --- .../src/main/java/com/yahoo/search/query/SelectParser.java | 6 ++++++ .../src/test/java/com/yahoo/select/SelectTestCase.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/container-search/src/main/java/com/yahoo/search/query/SelectParser.java b/container-search/src/main/java/com/yahoo/search/query/SelectParser.java index c482923e93b9..e57568d205dc 100644 --- a/container-search/src/main/java/com/yahoo/search/query/SelectParser.java +++ b/container-search/src/main/java/com/yahoo/search/query/SelectParser.java @@ -2,6 +2,8 @@ package com.yahoo.search.query; import com.google.common.base.Preconditions; +import com.yahoo.prelude.query.FalseItem; +import com.yahoo.prelude.query.TrueItem; import com.yahoo.processing.IllegalInputException; import com.yahoo.collections.LazyMap; import com.yahoo.geo.DistanceParser; @@ -63,6 +65,7 @@ import static com.yahoo.search.yql.YqlParser.MAX_EDIT_DISTANCE; import static com.yahoo.search.yql.YqlParser.PREFIX_LENGTH; import static com.yahoo.slime.Type.ARRAY; +import static com.yahoo.slime.Type.BOOL; import static com.yahoo.slime.Type.DOUBLE; import static com.yahoo.slime.Type.LONG; import static com.yahoo.slime.Type.OBJECT; @@ -181,6 +184,9 @@ private QueryTree buildTree() { } private Item walkJson(Inspector inspector) { + if (inspector.type() == BOOL) + return inspector.asBool() ? new TrueItem() : new FalseItem(); + Item[] item = {null}; inspector.traverse((ObjectTraverser) (key, value) -> { String type = (FUNCTION_CALLS.contains(key)) ? CALL : key; diff --git a/container-search/src/test/java/com/yahoo/select/SelectTestCase.java b/container-search/src/test/java/com/yahoo/select/SelectTestCase.java index b15663e0ce67..f7c101f81d1b 100644 --- a/container-search/src/test/java/com/yahoo/select/SelectTestCase.java +++ b/container-search/src/test/java/com/yahoo/select/SelectTestCase.java @@ -69,6 +69,12 @@ void test_contains() { assertParse(json.toString(), "default:foo"); } + @Test + void testWhereWithBoolean() { + assertParse("true", "TRUE"); + assertParse("false", "FALSE"); + } + @Test void testDottedFieldNames() { assertParse("{ 'contains' : ['my.nested.title', 'madonna']}",