diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-03-15 13:21:06 +0100 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-03-15 13:38:48 +0100 |
commit | 8618500f10427d6414e1dabb02e34695cbd92e79 (patch) | |
tree | fc4e7d1589d00949b8619e2e2a31ab8c1a8019e4 /document/src/test/java/com/yahoo | |
parent | 6d803878dd20afc1500286f0382e7077f834abaf (diff) |
Add comparison support for BoolFieldValues in Java document selection impl
Field _value_ itself is already extracted via field path iteration, but
since bool fields do not inherit from an existing numeric field value type
we need to explicitly handle the bool type when evaluating AST comparison nodes.
Diffstat (limited to 'document/src/test/java/com/yahoo')
-rw-r--r-- | document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java index 0a23c14cf16..bf8cf07a097 100644 --- a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java @@ -17,6 +17,7 @@ import com.yahoo.document.MapDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.WeightedSetDataType; import com.yahoo.document.datatypes.Array; +import com.yahoo.document.datatypes.BoolFieldValue; import com.yahoo.document.datatypes.FloatFieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.MapFieldValue; @@ -373,6 +374,8 @@ public class DocumentSelectorTestCase { documents.add(createDocument("id:myspace:test:g=mygroup:qux", 15, 1.0f, "quux", "corge")); documents.add(createDocument("id:myspace:test::missingint", null, 2.0f, null, "bar")); documents.add(createDocument("id:myspace:test::ampersand", null, 2.0f, null, "&")); + documents.add(createDocument("id:foo:test::withtruefield", null, 0.0f, null, "")); + documents.add(createDocument("id:foo:test::withfalsefield", null, 0.0f, null, "")); // Add some array/struct info to doc 1 Struct sval = new Struct(documents.get(1).getDocument().getField("mystruct").getDataType()); @@ -446,6 +449,9 @@ public class DocumentSelectorTestCase { intvals2.add(new IntegerFieldValue(9)); documents.get(1).getDocument().setFieldValue("intarray", intvals2); + documents.get(8).getDocument().setFieldValue("truth", new BoolFieldValue(true)); + documents.get(9).getDocument().setFieldValue("truth", new BoolFieldValue(false)); + return documents; } @@ -740,6 +746,17 @@ public class DocumentSelectorTestCase { } @Test + public void boolean_fields_can_be_used_for_equality_comparisons() throws ParseException { + var documents = createDocs(); + assertEquals(Result.TRUE, evaluate("test.truth == 1", documents.get(8))); // has explicit field set to true + assertEquals(Result.FALSE, evaluate("test.truth == 1", documents.get(9))); // has explicit field set to false + assertEquals(Result.TRUE, evaluate("test.truth == 0", documents.get(9))); + // FIXME very un-intuitive behavior when nulls are implicitly returned: + assertEquals(Result.FALSE, evaluate("test.truth == 1", documents.get(0))); // Does not have field set in document + assertEquals(Result.FALSE, evaluate("test.truth == 0", documents.get(0))); // Does not have field set in document + } + + @Test public void testInheritance() throws ParseException { var s=new DocumentSelector("parent.parentField = \"parentValue\""); List<DocumentPut> documents = createDocs(); |