aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-12-14 22:45:49 +0100
committerJon Bratseth <bratseth@gmail.com>2021-12-14 22:45:49 +0100
commit182104d8f355ff2bef5b2abba0ccae88a958fa21 (patch)
treede1ff964695b1b6087aa2bf30831fd9c49b66675 /document
parent8a085f018f881670bb6f0907c431e37f12d77492 (diff)
Restore current behavior and add Vesopa 8 TODOs
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/select/rule/DocumentTypeNode.java25
-rw-r--r--document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java5
-rw-r--r--document/src/vespa/document/select/doctype.cpp1
3 files changed, 28 insertions, 3 deletions
diff --git a/document/src/main/java/com/yahoo/document/select/rule/DocumentTypeNode.java b/document/src/main/java/com/yahoo/document/select/rule/DocumentTypeNode.java
index 7e04ec6fa1b..5bf62009797 100644
--- a/document/src/main/java/com/yahoo/document/select/rule/DocumentTypeNode.java
+++ b/document/src/main/java/com/yahoo/document/select/rule/DocumentTypeNode.java
@@ -2,8 +2,11 @@
package com.yahoo.document.select.rule;
import com.yahoo.document.BucketIdFactory;
+import com.yahoo.document.DocumentGet;
import com.yahoo.document.DocumentOperation;
import com.yahoo.document.DocumentPut;
+import com.yahoo.document.DocumentRemove;
+import com.yahoo.document.DocumentType;
import com.yahoo.document.DocumentUpdate;
import com.yahoo.document.select.BucketSet;
import com.yahoo.document.select.Context;
@@ -43,7 +46,27 @@ public class DocumentTypeNode implements ExpressionNode {
}
private Object evaluate(DocumentOperation op) {
- return op.getId().getDocType().equals(type) ? op : false;
+ // TODO Vespa 8: Uncomment the following line and remove the legacy one
+ // return op.getId().getDocType().equals(type) ? op : false;
+ return legacyEvaluate(op);
+ }
+
+ private Object legacyEvaluate(DocumentOperation op) {
+ DocumentType doct;
+ if (op instanceof DocumentPut) {
+ doct = ((DocumentPut) op).getDocument().getDataType();
+ } else if (op instanceof DocumentUpdate) {
+ doct = ((DocumentUpdate) op).getDocumentType();
+ } else if (op instanceof DocumentRemove) {
+ DocumentRemove removeOp = (DocumentRemove) op;
+ return (removeOp.getId().getDocType().equals(type) ? op : Boolean.FALSE);
+ } else if (op instanceof DocumentGet) {
+ DocumentGet getOp = (DocumentGet) op;
+ return (getOp.getId().getDocType().equals(type) ? op : Boolean.FALSE);
+ } else {
+ throw new IllegalStateException("Document class '" + op.getClass().getName() + "' is not supported.");
+ }
+ return doct.isA(this.type) ? op : Boolean.FALSE;
}
public void accept(Visitor visitor) {
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 690b216e5e2..5a75110ca74 100644
--- a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java
+++ b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java
@@ -749,8 +749,9 @@ public class DocumentSelectorTestCase {
var s=new DocumentSelector("parent.parentField = \"parentValue\"");
List<DocumentPut> documents = createDocs();
assertEquals(Result.TRUE, evaluate("test", documents.get(0)));
- assertEquals("Matching on type is exact",
- Result.FALSE, evaluate("parent", documents.get(0)));
+ // TODO Vespa 8: Change the following assert (only) to expect Result.FALSE
+ assertEquals("Matching on type is [on Vespa 7, not] exact",
+ Result.TRUE, evaluate("parent", documents.get(0)));
assertEquals(Result.TRUE, evaluate("test.parentField = \"parentValue\"", documents.get(0)));
assertEquals("Fields may be accessed by parent type",
Result.TRUE, evaluate("parent.parentField = \"parentValue\"", documents.get(0)));
diff --git a/document/src/vespa/document/select/doctype.cpp b/document/src/vespa/document/select/doctype.cpp
index 5381fc48777..05b8b9593dd 100644
--- a/document/src/vespa/document/select/doctype.cpp
+++ b/document/src/vespa/document/select/doctype.cpp
@@ -15,6 +15,7 @@ namespace {
vespalib::stringref name)
{
if (type.getName() == name) return true;
+ // TODO Vespa 8: Remove this for look on Vespa 8
for (std::vector<const DocumentType *>::const_iterator it
= type.getInheritedTypes().begin();
it != type.getInheritedTypes().end(); ++it)