diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-08-09 13:34:18 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-08-09 14:38:18 +0000 |
commit | 840aacbbae61a4d0162d2decb534a6fe5fae030a (patch) | |
tree | 5077bdbf21edac80543673cca052b46ec108db18 /document/src | |
parent | 247c57f87631a684fa72f410a8c896900c01e303 (diff) |
Remove visitor ordering and order selection.
Diffstat (limited to 'document/src')
43 files changed, 175 insertions, 1031 deletions
diff --git a/document/src/main/java/com/yahoo/document/idstring/IdIdString.java b/document/src/main/java/com/yahoo/document/idstring/IdIdString.java index 44ff08c73f0..4c7f71dd712 100644 --- a/document/src/main/java/com/yahoo/document/idstring/IdIdString.java +++ b/document/src/main/java/com/yahoo/document/idstring/IdIdString.java @@ -24,7 +24,7 @@ public class IdIdString extends IdString { } - private static long makeLocation(String s) { + public static long makeLocation(String s) { long result = 0; byte[] md5sum = MD5.md5.get().digest(Utf8.toBytes(s)); for (int i=0; i<8; ++i) { diff --git a/document/src/main/java/com/yahoo/document/select/DocumentSelector.java b/document/src/main/java/com/yahoo/document/select/DocumentSelector.java index 1ee6ff45c99..8b5178d21a8 100644 --- a/document/src/main/java/com/yahoo/document/select/DocumentSelector.java +++ b/document/src/main/java/com/yahoo/document/select/DocumentSelector.java @@ -98,16 +98,6 @@ public class DocumentSelector { } /** - * Returns the ordering specification, if any, implied by this document - * selection expression. - * - * @param order The order of the - */ - public OrderingSpecification getOrdering(int order) { - return expression.getOrdering(order); - } - - /** * Visits the expression tree. * * @param visitor The visitor to use. diff --git a/document/src/main/java/com/yahoo/document/select/OrderingSpecification.java b/document/src/main/java/com/yahoo/document/select/OrderingSpecification.java deleted file mode 100644 index 97908d3190f..00000000000 --- a/document/src/main/java/com/yahoo/document/select/OrderingSpecification.java +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.select; - -public class OrderingSpecification { - public static int ASCENDING = 0; - public static int DESCENDING = 1; - - public final int order; - public final long orderingStart; - public final short widthBits; - public final short divisionBits; - - public OrderingSpecification() { - this(ASCENDING, (long)0, (short)0, (short)0); - } - - public OrderingSpecification(int order) { - this(order, (long)0, (short)0, (short)0); - } - - public OrderingSpecification(int order, long orderingStart, short widthBits, short divisionBits) { - this.order = order; - this.orderingStart = orderingStart; - this.widthBits = widthBits; - this.divisionBits = divisionBits; - } - - public int getOrder() { return order; } - public long getOrderingStart() { return orderingStart; } - public short getWidthBits() { return widthBits; } - public short getDivisionBits() { return divisionBits; } - - @Override - public boolean equals(Object other) { - OrderingSpecification o = (OrderingSpecification)other; - if (o == null) return false; - - return (order == o.order && orderingStart == o.orderingStart && widthBits == o.widthBits && divisionBits == o.divisionBits); - } - - @Override - public int hashCode() { - return java.util.Objects.hash(order, orderingStart, widthBits, divisionBits); - } - - public String toString() { - return "O: " + order + " S:" + orderingStart + " W:" + widthBits + " D:" + divisionBits; - } -} diff --git a/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java b/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java index c39bd7e668d..921f412096e 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java @@ -5,7 +5,6 @@ import com.yahoo.document.BucketIdFactory; import com.yahoo.document.datatypes.NumericFieldValue; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; import java.util.List; @@ -175,16 +174,11 @@ public class ArithmeticNode implements ExpressionNode { } @Override - public OrderingSpecification getOrdering(int order) { - return null; - } - - @Override public void accept(Visitor visitor) { visitor.visit(this); } - private class ValueItem { + private static class ValueItem { public int operator; public Number value; diff --git a/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java b/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java index 3e03709d0f1..0cedda7c4f0 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/AttributeNode.java @@ -13,7 +13,6 @@ import com.yahoo.document.datatypes.FieldPathIteratorHandler; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Result; import com.yahoo.document.select.ResultList; import com.yahoo.document.select.Visitor; @@ -183,11 +182,6 @@ public class AttributeNode implements ExpressionNode { return ret.toString(); } - @Override - public OrderingSpecification getOrdering(int order) { - return null; - } - public static class Item { public static final int ATTRIBUTE = 0; public static final int FUNCTION = 1; diff --git a/document/src/main/java/com/yahoo/document/select/rule/ComparisonNode.java b/document/src/main/java/com/yahoo/document/select/rule/ComparisonNode.java index c8fd8da0b98..47599e53ece 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/ComparisonNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/ComparisonNode.java @@ -6,10 +6,9 @@ import com.yahoo.document.BucketIdFactory; import com.yahoo.document.DocumentId; import com.yahoo.document.datatypes.FieldPathIteratorHandler; import com.yahoo.document.datatypes.NumericFieldValue; -import com.yahoo.document.idstring.GroupDocIdString; +import com.yahoo.document.idstring.IdIdString; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Result; import com.yahoo.document.select.ResultList; import com.yahoo.document.select.Visitor; @@ -78,47 +77,6 @@ public class ComparisonNode implements ExpressionNode { return rhs; } - public OrderingSpecification getOrdering(IdNode lhs, LiteralNode rhs, String operator, int order) { - if (lhs.getWidthBits() == -1 || lhs.getDivisionBits() == -1 || !(rhs.getValue() instanceof Long)) { - return null; - } - - if (operator.equals("==") || operator.equals("=")) { - return new OrderingSpecification(order, (Long)rhs.getValue(), lhs.getWidthBits(), lhs.getDivisionBits()); - } - - if (order == OrderingSpecification.ASCENDING) { - if ((operator.equals("<") || operator.equals("<="))) { - return new OrderingSpecification(order, 0, lhs.getWidthBits(), lhs.getDivisionBits()); - } - if (operator.equals(">")) { - return new OrderingSpecification(order, (Long)rhs.getValue() + 1, lhs.getWidthBits(), lhs.getDivisionBits()); - } - if (operator.equals(">=")) { - return new OrderingSpecification(order, (Long)rhs.getValue(), lhs.getWidthBits(), lhs.getDivisionBits()); - } - } else { - if (operator.equals("<")) { - return new OrderingSpecification(order, (Long)rhs.getValue() - 1, lhs.getWidthBits(), lhs.getDivisionBits()); - } - if (operator.equals("<=")) { - return new OrderingSpecification(order, (Long)rhs.getValue(), lhs.getWidthBits(), lhs.getDivisionBits()); - } - } - return null; - } - - @Override - public OrderingSpecification getOrdering(int order) { - if (lhs instanceof IdNode && rhs instanceof LiteralNode) { - return getOrdering((IdNode)lhs, (LiteralNode)rhs, operator, order); - } else if (rhs instanceof IdNode && lhs instanceof LiteralNode) { - return getOrdering((IdNode)rhs, (LiteralNode)lhs, operator, order); - } - - return null; - } - @Override public BucketSet getBucketSet(BucketIdFactory factory) { if (operator.equals("==") || operator.equals("=")) { @@ -131,6 +89,7 @@ public class ComparisonNode implements ExpressionNode { return null; } + @SuppressWarnings("deprecation") private BucketSet compare(BucketIdFactory factory, IdNode id, LiteralNode literal, String operator) { String field = id.getField(); Object value = literal.getValue(); @@ -156,7 +115,7 @@ public class ComparisonNode implements ExpressionNode { { return null; // no idea } - return new BucketSet(new BucketId(factory.getLocationBitCount(), new GroupDocIdString("", name, "").getLocation())); + return new BucketSet(new BucketId(factory.getLocationBitCount(), IdIdString.makeLocation(name))); } } else if (field.equalsIgnoreCase("bucket")) { if (value instanceof Long) { diff --git a/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java b/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java index 9b766a56eb3..6e43969b623 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/DocumentNode.java @@ -10,7 +10,6 @@ import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentUpdate; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; /** @@ -70,8 +69,4 @@ public class DocumentNode implements ExpressionNode { return type; } - @Override - public OrderingSpecification getOrdering(int order) { - return null; - } } diff --git a/document/src/main/java/com/yahoo/document/select/rule/EmbracedNode.java b/document/src/main/java/com/yahoo/document/select/rule/EmbracedNode.java index 7bf3413bafb..7e7b748dce1 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/EmbracedNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/EmbracedNode.java @@ -4,7 +4,6 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; /** @@ -47,8 +46,4 @@ public class EmbracedNode implements ExpressionNode { visitor.visit(this); } - @Override - public OrderingSpecification getOrdering(int order) { - return null; - } } diff --git a/document/src/main/java/com/yahoo/document/select/rule/ExpressionNode.java b/document/src/main/java/com/yahoo/document/select/rule/ExpressionNode.java index 9350b8ac1c5..232262eb466 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/ExpressionNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/ExpressionNode.java @@ -4,7 +4,6 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; /** @@ -31,14 +30,6 @@ public interface ExpressionNode { BucketSet getBucketSet(BucketIdFactory factory); /** - * If this document selection implies a specific ordering (using the orderdoc scheme), - * return that specification. - * - * @param order The order in which we are looking to traverse the ordering (ASCENDING or DESCENDING) - */ - OrderingSpecification getOrdering(int order); - - /** * Perform visitation of this node. * * @param visitor The visitor that wishes to visit the node. diff --git a/document/src/main/java/com/yahoo/document/select/rule/IdNode.java b/document/src/main/java/com/yahoo/document/select/rule/IdNode.java index 3ca53c1d07d..f0f8815d467 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/IdNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/IdNode.java @@ -3,10 +3,8 @@ package com.yahoo.document.select.rule; import com.yahoo.document.DocumentId; import com.yahoo.document.BucketIdFactory; -import com.yahoo.document.idstring.OrderDocIdString; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; /** @@ -54,10 +52,6 @@ public class IdNode implements ExpressionNode { return null; } - public OrderingSpecification getOrdering(int ordering) { - return null; - } - @Override public Object evaluate(Context context) { DocumentId id = context.getDocumentOperation().getId(); @@ -88,13 +82,8 @@ public class IdNode implements ExpressionNode { } throw new IllegalStateException("Document id doesn't have doc type."); } else if (field.equalsIgnoreCase("order")) { - if (id.getScheme() instanceof OrderDocIdString) { - OrderDocIdString ods = (OrderDocIdString)id.getScheme(); - if (ods.getWidthBits() == widthBits && ods.getDivisionBits() == divisionBits) { - return ods.getOrdering(); - } - } - } else{ + // TODO Remove from grammar on VESPA 8 + } else { throw new IllegalStateException("Identifier field '" + field + "' is not supported."); } return null; diff --git a/document/src/main/java/com/yahoo/document/select/rule/LiteralNode.java b/document/src/main/java/com/yahoo/document/select/rule/LiteralNode.java index 2104a9c0608..9bf75289a26 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/LiteralNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/LiteralNode.java @@ -4,7 +4,6 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; import com.yahoo.document.select.parser.SelectParserUtils; @@ -54,8 +53,4 @@ public class LiteralNode implements ExpressionNode { } } - @Override - public OrderingSpecification getOrdering(int order) { - return null; - } } diff --git a/document/src/main/java/com/yahoo/document/select/rule/LogicNode.java b/document/src/main/java/com/yahoo/document/select/rule/LogicNode.java index 1ae397398b3..bc34e5040c5 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/LogicNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/LogicNode.java @@ -4,7 +4,6 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.ResultList; import com.yahoo.document.select.Visitor; @@ -72,61 +71,6 @@ public class LogicNode implements ExpressionNode { return buf.pop().buckets; } - @Override - public OrderingSpecification getOrdering(int order) { - Stack<OrderingItem> buf = new Stack<>(); - for (NodeItem item : items) { - if (!buf.isEmpty()) { - while (buf.peek().operator > item.operator) { - pickOrdering(buf); - } - } - buf.push(new OrderingItem(item.operator, item.node.getOrdering(order))); - } - while (buf.size() > 1) { - pickOrdering(buf); - } - return buf.pop().ordering; - } - - private OrderingSpecification pickOrdering(OrderingSpecification a, OrderingSpecification b, boolean isAnd) { - if (a.getWidthBits() == b.getWidthBits() && a.getDivisionBits() == b.getDivisionBits() && a.getOrder() == b.getOrder()) { - if ((a.getOrder() == OrderingSpecification.ASCENDING && isAnd) || - (a.getOrder() == OrderingSpecification.DESCENDING && !isAnd)) { - return new OrderingSpecification(a.getOrder(), Math.max(a.getOrderingStart(), b.getOrderingStart()), b.getWidthBits(), a.getDivisionBits()); - } else { - return new OrderingSpecification(a.getOrder(), Math.min(a.getOrderingStart(), b.getOrderingStart()), b.getWidthBits(), a.getDivisionBits()); - } - } - return null; - } - - private void pickOrdering(Stack<OrderingItem> buf) { - OrderingItem rhs = buf.pop(); - OrderingItem lhs = buf.pop(); - switch (rhs.operator) { - case AND: - if (lhs.ordering == null) { - lhs.ordering = rhs.ordering; - } else if (rhs.ordering == null) { - // empty - } else { - lhs.ordering = pickOrdering(lhs.ordering, rhs.ordering, true); - } - break; - case OR: - if (lhs.ordering != null && rhs.ordering != null) { - lhs.ordering = pickOrdering(lhs.ordering, rhs.ordering, false); - } else { - lhs.ordering = null; - } - break; - default: - lhs.ordering = null; - } - buf.push(lhs); - } - /** * Combines the top two items of the given stack using the operator of the second. * @@ -246,7 +190,7 @@ public class LogicNode implements ExpressionNode { /** * Private class to store results in a stack. */ - private abstract class ValueItem implements ResultList.LazyResultList { + private static abstract class ValueItem implements ResultList.LazyResultList { private final int operator; ValueItem(int operator) { this.operator = operator; @@ -254,7 +198,7 @@ public class LogicNode implements ExpressionNode { int getOperator() { return operator; } } - private final class LazyValueItem extends ValueItem { + private static final class LazyValueItem extends ValueItem { private final NodeItem item; private final Context context; private ResultList lazyResult = null; @@ -273,7 +217,7 @@ public class LogicNode implements ExpressionNode { } } - private final class LazyCombinedItem extends ValueItem { + private static final class LazyCombinedItem extends ValueItem { private final ValueItem lhs; private final ValueItem rhs; private ResultList lazyResult = null; @@ -304,7 +248,7 @@ public class LogicNode implements ExpressionNode { /** * Private class to store bucket sets in a stack. */ - private final class BucketItem { + private static final class BucketItem { private int operator; private BucketSet buckets; @@ -315,22 +259,9 @@ public class LogicNode implements ExpressionNode { } /** - * Private class to store ordering expressions in a stack. - */ - private final class OrderingItem { - private int operator; - private OrderingSpecification ordering; - - OrderingItem(int operator, OrderingSpecification orderSpec) { - this.operator = operator; - this.ordering = orderSpec; - } - } - - /** * Private class to store expression nodes in a stack. */ - public final class NodeItem { + public static final class NodeItem { private int operator; private ExpressionNode node; diff --git a/document/src/main/java/com/yahoo/document/select/rule/NegationNode.java b/document/src/main/java/com/yahoo/document/select/rule/NegationNode.java index ba75b13747d..b2f13f6d822 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/NegationNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/NegationNode.java @@ -4,7 +4,6 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Result; import com.yahoo.document.select.Visitor; @@ -48,8 +47,4 @@ public class NegationNode implements ExpressionNode { return "not " + node; } - @Override - public OrderingSpecification getOrdering(int order) { - return null; - } } diff --git a/document/src/main/java/com/yahoo/document/select/rule/NowNode.java b/document/src/main/java/com/yahoo/document/select/rule/NowNode.java index 567d9ddcb1f..5bb88d2f84a 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/NowNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/NowNode.java @@ -4,7 +4,6 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; /** @@ -28,10 +27,6 @@ public class NowNode implements ExpressionNode { } @Override - public OrderingSpecification getOrdering(int order) { - return null; - } - @Override public void accept(Visitor visitor) { visitor.visit(this); } diff --git a/document/src/main/java/com/yahoo/document/select/rule/VariableNode.java b/document/src/main/java/com/yahoo/document/select/rule/VariableNode.java index 77abb52938f..aae659de129 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/VariableNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/VariableNode.java @@ -4,7 +4,6 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; -import com.yahoo.document.select.OrderingSpecification; import com.yahoo.document.select.Visitor; /** @@ -51,8 +50,4 @@ public class VariableNode implements ExpressionNode { return "$" + value; } - @Override - public OrderingSpecification getOrdering(int order) { - return null; - } } diff --git a/document/src/main/javacc/SelectParser.jj b/document/src/main/javacc/SelectParser.jj index 0e79306ee36..6e1b01b27fb 100755 --- a/document/src/main/javacc/SelectParser.jj +++ b/document/src/main/javacc/SelectParser.jj @@ -74,7 +74,6 @@ TOKEN : <ID_SPECIFIC: "specific"> | <ID_USER: "user"> | <ID_GROUP: "group"> | - <ID_ORDER: "order"> | <ID_BUCKET: "bucket"> | <NULL: "null"> | <NOW: "now"> | @@ -205,7 +204,6 @@ void identifier() : { } <ID_SPECIFIC> | <ID_USER> | <ID_GROUP> | - <ID_ORDER> | <ID_BUCKET> | <NULL> | <NOW> | @@ -229,10 +227,7 @@ IdNode id() : <ID_SPECIFIC> { ret.setField(token.image); } | <ID_USER> { ret.setField(token.image); } | <ID_GROUP> { ret.setField(token.image); } | - <ID_BUCKET> { ret.setField(token.image); } | - ( <ID_ORDER> { ret.setField(token.image); } <LBRACE> - <INTEGER> { ret.setWidthBits(Short.parseShort(token.image)); } <COMMA> - <INTEGER> { ret.setDivisionBits(Short.parseShort(token.image)); } <RBRACE> ) ) + <ID_BUCKET> { ret.setField(token.image); } ) ] ) { return ret; } } diff --git a/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java b/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java index d10d4242f6f..c2e1dbd611c 100644 --- a/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java +++ b/document/src/test/java/com/yahoo/document/BucketIdFactoryTestCase.java @@ -1,10 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; -import com.yahoo.document.BucketIdFactory; -import com.yahoo.document.BucketId; -import com.yahoo.document.DocumentId; -import com.yahoo.document.idstring.*; +import com.yahoo.document.idstring.DocIdString; +import com.yahoo.document.idstring.IdIdString; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -44,23 +42,20 @@ public class BucketIdFactoryTestCase { } @Test + @SuppressWarnings("deprecation") public void testBucketGeneration() { + // TODO Rewrite in time for VESPA 8 to use IdIdString BucketIdFactory factory = new BucketIdFactory(32, 26, 6); DocumentId doc1 = new DocumentId(new DocIdString("ns", "spec")); DocumentId doc2 = new DocumentId(new DocIdString("ns2", "spec")); DocumentId doc3 = new DocumentId(new DocIdString("ns", "spec2")); - DocumentId userDoc1 = new DocumentId(new UserDocIdString("ns", 0x12, "spec")); - DocumentId userDoc2 = new DocumentId(new UserDocIdString("ns2", 0x12, "spec2")); - DocumentId userDoc3 = new DocumentId(new UserDocIdString("ns", 0x13, "spec")); - DocumentId groupDoc1 = new DocumentId(new GroupDocIdString("ns", "yahoo.com", "spec")); - DocumentId groupDoc2 = new DocumentId(new GroupDocIdString("ns2", "yahoo.com", "spec2")); - DocumentId groupDoc3 = new DocumentId(new GroupDocIdString("ns", "yahoo", "spec")); - DocumentId orderDoc1 = new DocumentId(new OrderDocIdString("ns", "13", 31, 19, 1268182861, "foo")); - DocumentId orderDoc2 = new DocumentId(new OrderDocIdString("ns", "13", 31, 19, 1205110861, "foo")); - DocumentId orderDoc3 = new DocumentId(new OrderDocIdString("ns", "13", 31, 19, 1205715661, "foo")); - DocumentId orderDoc4 = new DocumentId(new OrderDocIdString("ns", "13", 4, 0, 2, "foo")); - DocumentId orderDoc5 = new DocumentId(new OrderDocIdString("ns", "13", 4, 0, 4, "foo")); - DocumentId orderDoc6 = new DocumentId(new OrderDocIdString("ns", "13", 4, 0, 11, "foo")); + DocumentId userDoc1 = new DocumentId(new IdIdString("ns", "mytype","n=18", "spec")); + DocumentId userDoc2 = new DocumentId(new IdIdString("ns", "mytype","n=18", "spec2")); + DocumentId userDoc3 = new DocumentId(new IdIdString("ns", "mytype","n=19", "spec")); + DocumentId groupDoc1 = new DocumentId(new IdIdString("ns", "mytype", "g=yahoo.com", "spec")); + DocumentId groupDoc2 = new DocumentId(new IdIdString("ns2", "mytype", "g=yahoo.com", "spec2")); + DocumentId groupDoc3 = new DocumentId(new IdIdString("ns", "mytype", "g=yahoo", "spec")); + BucketId docBucket1 = factory.getBucketId(doc1); BucketId docBucket2 = factory.getBucketId(doc2); @@ -71,32 +66,18 @@ public class BucketIdFactoryTestCase { BucketId groupDocBucket1 = factory.getBucketId(groupDoc1); BucketId groupDocBucket2 = factory.getBucketId(groupDoc2); BucketId groupDocBucket3 = factory.getBucketId(groupDoc3); - BucketId orderDocBucket1 = factory.getBucketId(orderDoc1); - BucketId orderDocBucket2 = factory.getBucketId(orderDoc2); - BucketId orderDocBucket3 = factory.getBucketId(orderDoc3); - BucketId orderDocBucket4 = factory.getBucketId(orderDoc4); - BucketId orderDocBucket5 = factory.getBucketId(orderDoc5); - BucketId orderDocBucket6 = factory.getBucketId(orderDoc6); - - assertEquals(new Hex(0xe99703f200000012l), new Hex(userDocBucket1.getRawId())); - assertEquals(new Hex(0xebfa518a00000012l), new Hex(userDocBucket2.getRawId())); - assertEquals(new Hex(0xeac1850800000013l), new Hex(userDocBucket3.getRawId())); - - assertEquals(new Hex(0xe90ce4b09a1acd50l), new Hex(groupDocBucket1.getRawId())); - assertEquals(new Hex(0xe9cedaa49a1acd50l), new Hex(groupDocBucket2.getRawId())); - assertEquals(new Hex(0xe8cdb18bafe81f24l), new Hex(groupDocBucket3.getRawId())); - - assertEquals(new Hex(0xe980c9abd5fd8d11l), new Hex(docBucket1.getRawId())); - assertEquals(new Hex(0xeafe870c5f9c37b9l), new Hex(docBucket2.getRawId())); - assertEquals(new Hex(0xeaebe9473ecbcd69l), new Hex(docBucket3.getRawId())); - - assertEquals(new Hex(0xeae764e90000000dl), new Hex(orderDocBucket1.getRawId())); - assertEquals(new Hex(0xeacb85f10000000dl), new Hex(orderDocBucket2.getRawId())); - assertEquals(new Hex(0xea68ddf10000000dl), new Hex(orderDocBucket3.getRawId())); - - assertEquals(new Hex(0xe87526540000000dl), new Hex(orderDocBucket4.getRawId())); - assertEquals(new Hex(0xea59f8f20000000dl), new Hex(orderDocBucket5.getRawId())); - assertEquals(new Hex(0xe9eb703d0000000dl), new Hex(orderDocBucket6.getRawId())); + + assertEquals(new Hex(0xeb3089a300000012L), new Hex(userDocBucket1.getRawId())); + assertEquals(new Hex(0xea780a8700000012L), new Hex(userDocBucket2.getRawId())); + assertEquals(new Hex(0xe80d16fc00000013L), new Hex(userDocBucket3.getRawId())); + + assertEquals(new Hex(0xeb82f2be9a1acd50L), new Hex(groupDocBucket1.getRawId())); + assertEquals(new Hex(0xebff6e379a1acd50L), new Hex(groupDocBucket2.getRawId())); + assertEquals(new Hex(0xe91b9600afe81f24L), new Hex(groupDocBucket3.getRawId())); + + assertEquals(new Hex(0xe980c9abd5fd8d11L), new Hex(docBucket1.getRawId())); + assertEquals(new Hex(0xeafe870c5f9c37b9L), new Hex(docBucket2.getRawId())); + assertEquals(new Hex(0xeaebe9473ecbcd69L), new Hex(docBucket3.getRawId())); } //Actually a BucketId testcase ... @@ -113,7 +94,7 @@ public class BucketIdFactoryTestCase { @Test public void testBidContainsDocId() { - DocumentId docId = new DocumentId("userdoc:recovery:18:99999"); + DocumentId docId = new DocumentId("id:ns:recovery:n=18:99999"); BucketIdFactory factory = new BucketIdFactory(32, 26, 6); BucketId bid = new BucketId(16, 0x12L); assert(bid.contains(docId, factory)); diff --git a/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java b/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java index bd769889363..b8f60b5d9bc 100644 --- a/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java @@ -1,16 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; -import com.yahoo.document.idstring.*; +import com.yahoo.document.idstring.IdIdString; import com.yahoo.vespa.objects.BufferSerializer; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import java.math.BigInteger; -import java.io.*; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.regex.Pattern; import java.util.Arrays; @@ -70,10 +72,6 @@ public class DocumentIdTestCase { //valid URIs new DocumentId("doc:blabla:something"); new DocumentId("doc:doc:doc"); - new DocumentId("userdoc:bla:2387:"); - new DocumentId("userdoc:bar:0:"); - new DocumentId("userdoc:bar:18446744073709551615:"); - new DocumentId("userdoc:foo:15:bar"); new DocumentId("id:namespace:type:n=42:whatever"); new DocumentId("id:namespace:type::whatever"); } catch (IllegalArgumentException iae) { @@ -87,13 +85,6 @@ public class DocumentIdTestCase { checkInvalidUri("doc:::"); checkInvalidUri("doc::/"); checkInvalidUri("doc"); - checkInvalidUri("userdoc:"); - checkInvalidUri("userdoc::"); - checkInvalidUri("userdoc:::"); - checkInvalidUri("userdoc:::/"); - checkInvalidUri("userdoc"); - checkInvalidUri("userdoc:-87987//"); - checkInvalidUri("userdoc:18446744073709551620/bar/"); checkInvalidUri("id:namespace:type"); checkInvalidUri("id:namespace:type:key-values"); checkInvalidUri("id:namespace:type:n=0,n=1:foo"); @@ -118,7 +109,7 @@ public class DocumentIdTestCase { //Compares globalId with C++ implementation located in // ~document-HEAD/document/src/tests/cpp-globalidbucketids.txt @Test - public void testCalculateGlobalId() throws IOException{ + public void testCalculateGlobalId() throws IOException { String file = "src/tests/cpp-globalidbucketids.txt"; BufferedReader fr = new BufferedReader(new FileReader(file)); @@ -178,91 +169,8 @@ public class DocumentIdTestCase { } @Test - public void testGroupdoc() { - try { - //valid - new DocumentId("groupdoc:blabla:something:jkl"); - new DocumentId("groupdoc:doc:doc:asd"); - new DocumentId("groupdoc:bar:0:a"); - new DocumentId("groupdoc:bar:18446744073709551615:"); - new DocumentId("groupdoc:foo:15:bar"); - } catch (IllegalArgumentException iae) { - fail(iae.getMessage()); - } - } - - @Test - public void testInvalidGroupdoc() { - checkInvalidUri("grouppdoc:blabla:something"); - checkInvalidUri("groupdoc:blablasomething"); - } - - @Test - public void testUriNamespace() { - DocumentId docId = new DocumentId("doc:bar:foo"); - assertEquals("doc:bar:foo", docId.toString()); - assertEquals("doc", docId.getScheme().getType().toString()); - assertEquals("bar", docId.getScheme().getNamespace()); - assertEquals("foo", docId.getScheme().getNamespaceSpecific()); - - docId = new DocumentId("userdoc:ns:90:boo"); - assertEquals("userdoc:ns:90:boo", docId.toString()); - assertEquals("userdoc", docId.getScheme().getType().toString()); - assertEquals("ns", docId.getScheme().getNamespace()); - assertEquals("boo", docId.getScheme().getNamespaceSpecific()); - assertEquals(90l, ((UserDocIdString) docId.getScheme()).getUserId()); - - docId = new DocumentId("userdoc:ns:18446744073709551615:boo"); - assertEquals("userdoc:ns:18446744073709551615:boo", docId.toString()); - assertEquals("userdoc", docId.getScheme().getType().toString()); - assertEquals("ns", docId.getScheme().getNamespace()); - assertEquals("boo", docId.getScheme().getNamespaceSpecific()); - assertEquals(new BigInteger("18446744073709551615").longValue(), ((UserDocIdString) docId.getScheme()).getUserId()); - - docId = new DocumentId("userdoc:ns:9223372036854775808:boo"); - assertEquals("userdoc:ns:9223372036854775808:boo", docId.toString()); - assertEquals("userdoc", docId.getScheme().getType().toString()); - assertEquals("ns", docId.getScheme().getNamespace()); - assertEquals("boo", docId.getScheme().getNamespaceSpecific()); - assertEquals(new BigInteger("9223372036854775808").longValue(), ((UserDocIdString) docId.getScheme()).getUserId()); - - BigInteger negativeUserId = new BigInteger("F00DCAFEDEADBABE", 16); - assertEquals(0xF00DCAFEDEADBABEl, negativeUserId.longValue()); - docId = new DocumentId("userdoc:ns:"+negativeUserId+":bar"); - assertEquals("userdoc:ns:17297704939806374590:bar", docId.toString()); - assertEquals(negativeUserId.longValue(), ((UserDocIdString) docId.getScheme()).getUserId()); - - docId = new DocumentId("orderdoc(31,19):ns2:1234:1268182861:foo"); - assertEquals("orderdoc(31,19):ns2:1234:1268182861:foo", docId.toString()); - assertEquals("orderdoc", docId.getScheme().getType().toString()); - assertEquals("ns2", docId.getScheme().getNamespace()); - assertEquals("foo", docId.getScheme().getNamespaceSpecific()); - assertEquals(31, ((OrderDocIdString)docId.getScheme()).getWidthBits()); - assertEquals(19, ((OrderDocIdString)docId.getScheme()).getDivisionBits()); - assertEquals("1234", ((OrderDocIdString)docId.getScheme()).getGroup()); - assertEquals(1234, ((OrderDocIdString)docId.getScheme()).getUserId()); - assertEquals(1268182861, ((OrderDocIdString)docId.getScheme()).getOrdering()); - } - - @Test public void testIdStrings() { - DocumentId docId; - docId = new DocumentId(new DocIdString("test", "baaaa")); - assertEquals("doc:test:baaaa", docId.toString()); - assertFalse(docId.hasDocType()); - - docId = new DocumentId(new UserDocIdString("test", 54, "something")); - assertEquals("userdoc:test:54:something", docId.toString()); - assertFalse(docId.hasDocType()); - - docId = new DocumentId(new UserDocIdString("test", 0xFFFFFFFFFFFFFFFFl, "something")); - assertEquals("userdoc:test:18446744073709551615:something", docId.toString()); - - //sign flipped - docId = new DocumentId(new UserDocIdString("test", -8193, "something")); - assertEquals("userdoc:test:18446744073709543423:something", docId.toString()); - - docId = new DocumentId(new IdIdString("namespace", "type", "g=group", "foobar")); + DocumentId docId = new DocumentId(new IdIdString("namespace", "type", "g=group", "foobar")); assertEquals("id:namespace:type:g=group:foobar", docId.toString()); assertTrue(docId.hasDocType()); assertEquals("type", docId.getDocType()); @@ -283,26 +191,15 @@ public class DocumentIdTestCase { assertTrue(user.getScheme().hasNumber()); assertEquals(42, user.getScheme().getNumber()); - user = new DocumentId("userdoc:ns:42:foo"); - assertFalse(user.getScheme().hasGroup()); - assertTrue(user.getScheme().hasNumber()); - assertEquals(42, user.getScheme().getNumber()); - DocumentId group = new DocumentId("id:ns:type:g=mygroup:foo"); assertTrue(group.getScheme().hasGroup()); assertFalse(group.getScheme().hasNumber()); assertEquals("mygroup", group.getScheme().getGroup()); - group = new DocumentId("groupdoc:ns:mygroup:foo"); + group = new DocumentId("id:ns:type:g=mygroup:foo"); assertTrue(group.getScheme().hasGroup()); assertFalse(group.getScheme().hasNumber()); assertEquals("mygroup", group.getScheme().getGroup()); - - DocumentId order = new DocumentId("orderdoc(5,2):ns:42:007:foo"); - assertTrue(order.getScheme().hasGroup()); - assertTrue(order.getScheme().hasNumber()); - assertEquals("42", order.getScheme().getGroup()); - assertEquals(42, order.getScheme().getNumber()); } @Test diff --git a/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java b/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java index c134f8e7770..cb818f12d3f 100644 --- a/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java +++ b/document/src/test/java/com/yahoo/document/GlobalIdTestCase.java @@ -86,10 +86,10 @@ public class GlobalIdTestCase { @Test public void testToBucketId() { - verifyGidToBucketIdMapping("userdoc:ns:1:abc"); - verifyGidToBucketIdMapping("userdoc:ns:1000:abc"); - verifyGidToBucketIdMapping("userdoc:hsgf:18446744073700000000:dfdfsdfg"); - verifyGidToBucketIdMapping("groupdoc:ns:somegroup:hmm"); + verifyGidToBucketIdMapping("id:ns:mytype:n=1:abc"); + verifyGidToBucketIdMapping("id:ns:mytype:n=1000:abc"); + verifyGidToBucketIdMapping("id:hsgf:mytype:n=9146744073700000000:dfdfsdfg"); + verifyGidToBucketIdMapping("id:ns:mytype:g=somegroup:hmm"); verifyGidToBucketIdMapping("doc:foo:test"); verifyGidToBucketIdMapping("doc:myns:http://foo.bar"); verifyGidToBucketIdMapping("doc:jsrthsdf:a234aleingzldkifvasdfgadf"); diff --git a/document/src/test/java/com/yahoo/document/select/BucketSelectorTestCase.java b/document/src/test/java/com/yahoo/document/select/BucketSelectorTestCase.java index a1ad09c2329..aea5ea7fda8 100644 --- a/document/src/test/java/com/yahoo/document/select/BucketSelectorTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/BucketSelectorTestCase.java @@ -17,11 +17,11 @@ public class BucketSelectorTestCase { @Test public void testExpressions() throws Exception { - assertBucketCount("id = \"userdoc:ns:123:foobar\"", 1); - assertBucketCount("id = \"userdoc:ns:123:foo*\"", 0); - assertBucketCount("id == \"userdoc:ns:123:f?oo*\"", 1); - assertBucketCount("id =~ \"userdoc:ns:123:foo*\"", 0); - assertBucketCount("id =~ \"userdoc:ns:123:foo?\"", 0); + assertBucketCount("id = \"id:ns:mytype:n=123:foobar\"", 1); + assertBucketCount("id = \"id:ns:mytype:n=123:foo*\"", 0); + assertBucketCount("id == \"id:ns:mytype:n=123:f?oo*\"", 1); + assertBucketCount("id =~ \"id:ns:mytype:n=123:foo*\"", 0); + assertBucketCount("id =~ \"id:ns:mytype:n=123:foo?\"", 0); assertBucketCount("id.user = 123", 1); assertBucketCount("id.user == 123", 1); assertBucketCount("id.group = \"yahoo.com\"", 1); @@ -39,7 +39,7 @@ public class BucketSelectorTestCase { assertBucket("id.bucket = 0x4000000000003018", new BucketId(16, 12312)); assertBucket("id.bucket == 0x4000000000000258", new BucketId(16, 600)); - assertBucket("id = \"userdoc:ns:123:foobar\"", new BucketId(0xeafff5320000007bL)); + assertBucket("id = \"id:ns:mytype:n=123:foobar\"", new BucketId(0xe8bd6e280000007bL)); assertBucket("id.user = 123", new BucketId(32, 123)); assertBucket("id.group = \"yahoo.com\"", new BucketId(32, 0x035837189a1acd50L)); @@ -52,8 +52,8 @@ public class BucketSelectorTestCase { @Test public void parenthesis_enclosed_expressions_inherit_bucket_selectors_from_children() throws Exception { - assertBucketCount("(id == \"userdoc:ns:123:foobar\")", 1); - assertBucket("(id = \"userdoc:ns:123:foobar\")", new BucketId(0xeafff5320000007bL)); + assertBucketCount("(id == \"id:ns:mytype:n=123:foobar\")", 1); + assertBucket("(id = \"id:ns:mytype:n=123:foobar\")", new BucketId(0xe8bd6e280000007bL)); assertBucketCount("(id.group = \"yahoo.com\" and (testdoctype1.hstringval == \"Doe\"))", 1); assertBucket("(id.group = \"yahoo.com\" and (testdoctype1 and (id.namespace == 'foo')))", new BucketId(32, 0x035837189a1acd50L)); } 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 846f85e925a..6457a3deb82 100644 --- a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java @@ -74,7 +74,6 @@ public class DocumentSelectorTestCase { assertParse("id.namespace = \"*\""); assertParse("id.hash() > 0"); assertParse("id.namespace.hash() > 0"); - assertParse("id.order(5,2) > 100"); assertParse("music.artist = \"*\""); assertParse("music.artist.lowercase() = \"*\""); assertParse("music_.artist = \"*\""); @@ -187,9 +186,9 @@ public class DocumentSelectorTestCase { assertParse("mytype"); // Test document id. - assertParse("id == \"userdoc:ns:mytest\""); + assertParse("id == \"id:ns:mytype::mytest\""); assertParse("id.namespace == \"myspace\""); - assertParse("id.scheme == \"userdoc\""); + assertParse("id.scheme == \"id\""); assertParse("id.type == \"mytype\""); assertParse("id.user == 1234"); assertParse("id.bucket == 8388608", "id.bucket == 0x800000"); @@ -260,7 +259,7 @@ public class DocumentSelectorTestCase { public void testDocumentRemove() throws ParseException { assertEquals(Result.TRUE, evaluate("test", createRemove("id:ns:test::1"))); assertEquals(Result.FALSE, evaluate("test", createRemove("id:ns:null::1"))); - assertEquals(Result.FALSE, evaluate("test", createRemove("userdoc:test:1234:1"))); + assertEquals(Result.TRUE, evaluate("test", createRemove("id:ns:test:n=1234:1"))); assertEquals(Result.INVALID, evaluate("test.hint", createRemove("id:ns:test::1"))); assertEquals(Result.FALSE, evaluate("test.hint", createRemove("id:ns:null::1"))); assertEquals(Result.INVALID, evaluate("test.hint == 0", createRemove("id:ns:test::1"))); @@ -276,7 +275,7 @@ public class DocumentSelectorTestCase { public void testDocumentGet() throws ParseException { assertEquals(Result.TRUE, evaluate("test", createGet("id:ns:test::1"))); assertEquals(Result.FALSE, evaluate("test", createGet("id:ns:null::1"))); - assertEquals(Result.FALSE, evaluate("test", createGet("userdoc:test:1234:1"))); + assertEquals(Result.TRUE, evaluate("test", createGet("id:ns:test:n=1234:1"))); assertEquals(Result.INVALID, evaluate("test.hint", createGet("id:ns:test::1"))); assertEquals(Result.FALSE, evaluate("test.hint", createGet("id:ns:null::1"))); assertEquals(Result.INVALID, evaluate("test.hint == 0", createGet("id:ns:test::1"))); @@ -328,9 +327,8 @@ public class DocumentSelectorTestCase { List<DocumentPut> documents = new ArrayList<>(); documents.add(createDocument("doc:myspace:anything", 24, 2.0f, "foo", "bar")); documents.add(createDocument("doc:anotherspace:foo", 13, 4.1f, "bar", "foo")); - documents.add(createDocument("userdoc:myspace:1234:mail1", 15, 1.0f, "some", "some")); - documents.add(createDocument("userdoc:myspace:5678:bar", 14, 2.4f, "Yet", "More")); - documents.add(createDocument("orderdoc(31,19):ns2:1234:5678:foo", 14, 2.4f, "Yet", "More")); + documents.add(createDocument("id:myspace:test:n=1234:mail1", 15, 1.0f, "some", "some")); + documents.add(createDocument("id:myspace:test:n=5678:bar", 14, 2.4f, "Yet", "More")); documents.add(createDocument("id:myspace:test:n=2345:mail2", 15, 1.0f, "bar", "baz")); documents.add(createDocument("id:myspace:test:g=mygroup:qux", 15, 1.0f, "quux", "corge")); documents.add(createDocument("doc:myspace:missingint", null, 2.0f, null, "bar")); @@ -354,16 +352,14 @@ public class DocumentSelectorTestCase { documents.get(1).getDocument().setFieldValue("structarray", aval); MapFieldValue<IntegerFieldValue, StringFieldValue> mval = - new MapFieldValue<>((MapDataType)documents.get(1).getDocument().getField("mymap") - .getDataType()); + new MapFieldValue<>((MapDataType)documents.get(1).getDocument().getField("mymap").getDataType()); mval.put(new IntegerFieldValue(3), new StringFieldValue("a")); mval.put(new IntegerFieldValue(5), new StringFieldValue("b")); mval.put(new IntegerFieldValue(7), new StringFieldValue("c")); documents.get(1).getDocument().setFieldValue("mymap", mval); MapFieldValue<StringFieldValue, Array> amval = - new MapFieldValue<>((MapDataType)documents.get(1).getDocument().getField("structarrmap") - .getDataType()); + new MapFieldValue<>((MapDataType)documents.get(1).getDocument().getField("structarrmap").getDataType()); amval.put(new StringFieldValue("foo"), aval); Array<Struct> abval = new Array<>(documents.get(1).getDocument().getField("structarray").getDataType()); @@ -381,8 +377,7 @@ public class DocumentSelectorTestCase { amval.put(new StringFieldValue("bar"), abval); documents.get(1).getDocument().setFieldValue("structarrmap", amval); - WeightedSet<StringFieldValue> wsval = new WeightedSet<>(documents.get(1).getDocument().getField("stringweightedset") - .getDataType()); + WeightedSet<StringFieldValue> wsval = new WeightedSet<>(documents.get(1).getDocument().getField("stringweightedset").getDataType()); wsval.add(new StringFieldValue("foo")); wsval.add(new StringFieldValue("val1")); wsval.add(new StringFieldValue("val2")); @@ -396,16 +391,14 @@ public class DocumentSelectorTestCase { Array aval2 = new Array(documents.get(2).getDocument().getField("structarray").getDataType()); documents.get(2).getDocument().setFieldValue("structarray", aval2); - Array<IntegerFieldValue> intvals1 = new Array<>(documents.get(0).getDocument().getField("intarray") - .getDataType()); + Array<IntegerFieldValue> intvals1 = new Array<>(documents.get(0).getDocument().getField("intarray").getDataType()); intvals1.add(new IntegerFieldValue(12)); intvals1.add(new IntegerFieldValue(40)); intvals1.add(new IntegerFieldValue(60)); intvals1.add(new IntegerFieldValue(84)); documents.get(0).getDocument().setFieldValue("intarray", intvals1); - Array<IntegerFieldValue> intvals2 = new Array<>(documents.get(1).getDocument().getField("intarray") - .getDataType()); + Array<IntegerFieldValue> intvals2 = new Array<>(documents.get(1).getDocument().getField("intarray").getDataType()); intvals2.add(new IntegerFieldValue(3)); intvals2.add(new IntegerFieldValue(56)); intvals2.add(new IntegerFieldValue(23)); @@ -485,18 +478,19 @@ public class DocumentSelectorTestCase { assertEquals(Result.TRUE, evaluate("test.hint + 1 > 13", documents.get(1))); // Case where field is not present (i.e. null) is defined for (in)equality comparisons, but // not for other relations. - assertEquals(Result.TRUE, evaluate("test.hint != 1234", documents.get(7))); - assertEquals(Result.FALSE, evaluate("test.hint == 1234", documents.get(7))); - assertEquals(Result.INVALID, evaluate("test.hint < 1234", documents.get(7))); + DocumentPut doc1234 = documents.get(6); + assertEquals(Result.TRUE, evaluate("test.hint != 1234", doc1234)); + assertEquals(Result.FALSE, evaluate("test.hint == 1234", doc1234)); + assertEquals(Result.INVALID, evaluate("test.hint < 1234", doc1234)); // Propagation of Invalid through logical operators should match C++ implementation - assertEquals(Result.FALSE, evaluate("test.hint < 1234 and false", documents.get(7))); - assertEquals(Result.INVALID, evaluate("test.hint < 1234 and true", documents.get(7))); - assertEquals(Result.TRUE, evaluate("test.hint < 1234 or true", documents.get(7))); - assertEquals(Result.INVALID, evaluate("test.hint < 1234 or false", documents.get(7))); + assertEquals(Result.FALSE, evaluate("test.hint < 1234 and false", doc1234)); + assertEquals(Result.INVALID, evaluate("test.hint < 1234 and true", doc1234)); + assertEquals(Result.TRUE, evaluate("test.hint < 1234 or true", doc1234)); + assertEquals(Result.INVALID, evaluate("test.hint < 1234 or false", doc1234)); // Must be possible to predicate a sub-expression on the presence of a field without // propagating up an Invalid value from the comparison. - assertEquals(Result.FALSE, evaluate("test.hint and test.hint < 1234", documents.get(7))); - assertEquals(Result.FALSE, evaluate("test.hint != null and test.hint < 1234", documents.get(7))); + assertEquals(Result.FALSE, evaluate("test.hint and test.hint < 1234", doc1234)); + assertEquals(Result.FALSE, evaluate("test.hint != null and test.hint < 1234", doc1234)); // Document types. assertEquals(Result.TRUE, evaluate("test", documents.get(0))); @@ -508,46 +502,38 @@ public class DocumentSelectorTestCase { // Field existence assertEquals(Result.TRUE, evaluate("test.hint", documents.get(0))); assertEquals(Result.TRUE, evaluate("test.hstring", documents.get(0))); - assertEquals(Result.FALSE, evaluate("test.hint", documents.get(7))); - assertEquals(Result.FALSE, evaluate("test.hstring", documents.get(7))); - assertEquals(Result.TRUE, evaluate("not test.hint", documents.get(7))); - assertEquals(Result.TRUE, evaluate("not test.hstring", documents.get(7))); + assertEquals(Result.FALSE, evaluate("test.hint", doc1234)); + assertEquals(Result.FALSE, evaluate("test.hstring", doc1234)); + assertEquals(Result.TRUE, evaluate("not test.hint", doc1234)); + assertEquals(Result.TRUE, evaluate("not test.hstring", doc1234)); assertEquals(Result.TRUE, evaluate("test.hint != null", documents.get(0))); assertEquals(Result.TRUE, evaluate("null != test.hint", documents.get(0))); assertEquals(Result.FALSE, evaluate("test.hint == null", documents.get(0))); assertEquals(Result.FALSE, evaluate("null == test.hint", documents.get(0))); - assertEquals(Result.TRUE, evaluate("null == test.hint", documents.get(7))); - assertEquals(Result.TRUE, evaluate("test.hint == null", documents.get(7))); - assertEquals(Result.FALSE, evaluate("test.hint != null", documents.get(7))); - assertEquals(Result.FALSE, evaluate("null != test.hint", documents.get(7))); + assertEquals(Result.TRUE, evaluate("null == test.hint", doc1234)); + assertEquals(Result.TRUE, evaluate("test.hint == null", doc1234)); + assertEquals(Result.FALSE, evaluate("test.hint != null", doc1234)); + assertEquals(Result.FALSE, evaluate("null != test.hint", doc1234)); - assertEquals(Result.TRUE, evaluate("test.hint or true", documents.get(7))); - assertEquals(Result.TRUE, evaluate("not test.hint and true", documents.get(7))); - assertEquals(Result.FALSE, evaluate("not test.hint and false", documents.get(7))); + assertEquals(Result.TRUE, evaluate("test.hint or true", doc1234)); + assertEquals(Result.TRUE, evaluate("not test.hint and true", doc1234)); + assertEquals(Result.FALSE, evaluate("not test.hint and false", doc1234)); // Id values. assertEquals(Result.TRUE, evaluate("id == \"doc:myspace:anything\"", documents.get(0))); assertEquals(Result.TRUE, evaluate(" iD== \"doc:myspace:anything\" ", documents.get(0))); assertEquals(Result.FALSE, evaluate("id == \"doc:myspa:nything\"", documents.get(0))); assertEquals(Result.TRUE, evaluate("Id.scHeme == \"doc\"", documents.get(0))); - assertEquals(Result.FALSE, evaluate("id.scheme == \"userdoc\"", documents.get(0))); - assertEquals(Result.TRUE, evaluate("id.type == \"test\"", documents.get(5))); - assertEquals(Result.FALSE, evaluate("id.type == \"wrong\"", documents.get(5))); + assertEquals(Result.FALSE, evaluate("id.scheme == \"id\"", documents.get(0))); + assertEquals(Result.TRUE, evaluate("id.type == \"test\"", documents.get(4))); + assertEquals(Result.FALSE, evaluate("id.type == \"wrong\"", documents.get(4))); assertEquals(Result.TRUE, evaluate("Id.namespaCe == \"myspace\"", documents.get(0))); assertEquals(Result.FALSE, evaluate("id.NaMespace == \"pace\"", documents.get(0))); assertEquals(Result.TRUE, evaluate("id.specific == \"anything\"", documents.get(0))); assertEquals(Result.TRUE, evaluate("id.user=1234", documents.get(2))); - assertEquals(Result.TRUE, evaluate("id.user=1234", documents.get(4))); - assertEquals(Result.TRUE, evaluate("id.group=\"1234\"", documents.get(4))); - assertEquals(Result.TRUE, evaluate("id.user=2345", documents.get(5))); - assertEquals(Result.TRUE, evaluate("id.group=\"mygroup\"", documents.get(6))); - - assertEquals(Result.TRUE, evaluate("id.order(31,19)=5678", documents.get(4))); - assertEquals(Result.TRUE, evaluate("id.order(31,19)<=5678", documents.get(4))); - assertEquals(Result.FALSE, evaluate("id.order(31,19)>5678", documents.get(4))); - assertEquals(Result.FALSE, evaluate("id.order(25,23)==5678", documents.get(4))); - assertEquals(Result.FALSE, evaluate("id.order(31,19)=5678", documents.get(3))); + assertEquals(Result.TRUE, evaluate("id.user=2345", documents.get(4))); + assertEquals(Result.TRUE, evaluate("id.group=\"mygroup\"", documents.get(5))); assertError("id.user == 1234", documents.get(0), "User identifier is null."); assertError("id.group == 1234", documents.get(3), "Group identifier is null."); diff --git a/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java index 25aca22b108..5e06085b8c9 100644 --- a/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java @@ -35,11 +35,6 @@ public class LogicalNodeTestCase { } @Override - public OrderingSpecification getOrdering(int order) { - return node.getOrdering(order); - } - - @Override public void accept(Visitor visitor) { node.accept(visitor); } diff --git a/document/src/test/java/com/yahoo/document/select/OrderingSpecificationTestCase.java b/document/src/test/java/com/yahoo/document/select/OrderingSpecificationTestCase.java deleted file mode 100644 index 8c0f7402704..00000000000 --- a/document/src/test/java/com/yahoo/document/select/OrderingSpecificationTestCase.java +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.select; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * @author HÃ¥kon Humberset - */ -public class OrderingSpecificationTestCase { - - @Test - public void testExpressions() throws Exception { - assertSelection("id.order(10,10) < 100", OrderingSpecification.DESCENDING, - new OrderingSpecification(OrderingSpecification.DESCENDING, (long)99, (short)10, (short)10)); - assertSelection("id.order(10,10) <= 100", OrderingSpecification.DESCENDING, - new OrderingSpecification(OrderingSpecification.DESCENDING, (long)100, (short)10, (short)10)); - assertSelection("id.order(10,10) > 100", OrderingSpecification.DESCENDING, null); - assertSelection("id.order(10,10) > 100", OrderingSpecification.ASCENDING, - new OrderingSpecification(OrderingSpecification.ASCENDING, (long)101, (short)10, (short)10)); - assertSelection("id.user==1234 AND id.order(10,10) > 100", OrderingSpecification.ASCENDING, - new OrderingSpecification(OrderingSpecification.ASCENDING, (long)101, (short)10, (short)10)); - assertSelection("id.order(10,10) >= 100", OrderingSpecification.ASCENDING, - new OrderingSpecification(OrderingSpecification.ASCENDING, (long)100, (short)10, (short)10)); - assertSelection("id.order(10,10) == 100", OrderingSpecification.ASCENDING, - new OrderingSpecification(OrderingSpecification.ASCENDING, (long)100, (short)10, (short)10)); - assertSelection("id.order(10,10) = 100", OrderingSpecification.DESCENDING, - new OrderingSpecification(OrderingSpecification.DESCENDING, (long)100, (short)10, (short)10)); - assertSelection("id.order(10,10) > 30 AND id.order(10,10) < 100", OrderingSpecification.ASCENDING, - new OrderingSpecification(OrderingSpecification.ASCENDING, (long)31, (short)10, (short)10)); - assertSelection("id.order(10,10) > 30 AND id.order(10,10) < 100", OrderingSpecification.DESCENDING, - new OrderingSpecification(OrderingSpecification.DESCENDING, (long)99, (short)10, (short)10)); - assertSelection("id.order(10,10) > 30 OR id.order(10,10) > 70", OrderingSpecification.ASCENDING, - new OrderingSpecification(OrderingSpecification.ASCENDING, (long)31, (short)10, (short)10)); - assertSelection("id.order(10,10) < 30 OR id.order(10,10) < 70", OrderingSpecification.DESCENDING, - new OrderingSpecification(OrderingSpecification.DESCENDING, (long)69, (short)10, (short)10)); - } - - public void assertSelection(String selection, int ordering, OrderingSpecification wanted) throws Exception { - DocumentSelector selector = new DocumentSelector(selection); - if (wanted != null) { - assertEquals(wanted, selector.getOrdering(ordering)); - } else { - assertNull(selector.getOrdering(ordering)); - } - } - -} diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt index 1421297b284..6458adccfd8 100644 --- a/document/src/tests/CMakeLists.txt +++ b/document/src/tests/CMakeLists.txt @@ -20,7 +20,6 @@ vespa_add_executable(document_gtest_runner_app TEST gid_filter_test.cpp globalidtest.cpp gtest_runner.cpp - orderingselectortest.cpp positiontypetest.cpp primitivefieldvaluetest.cpp stringtokenizertest.cpp diff --git a/document/src/tests/base/documentid_test.cpp b/document/src/tests/base/documentid_test.cpp index adb999d7430..9994fa5b60b 100644 --- a/document/src/tests/base/documentid_test.cpp +++ b/document/src/tests/base/documentid_test.cpp @@ -31,19 +31,9 @@ const IdType &getAs(const DocumentId &doc_id) { } template <typename IdType> -void checkUser(const string &id, int64_t user_id) { +void checkUser(const string &id, uint64_t user_id) { DocumentId doc_id(id); - EXPECT_EQUAL(user_id, getAs<IdType>(doc_id).getUserId()); -} - -void checkOrdering(const string &id, uint64_t ordering) { - DocumentId doc_id(id); - EXPECT_EQUAL(ordering, getAs<OrderDocIdString>(doc_id).getOrdering()); -} - -void checkGroup(const string &id, const string &group) { - DocumentId doc_id(id); - EXPECT_EQUAL(group, getAs<GroupDocIdString>(doc_id).getGroup()); + EXPECT_EQUAL(user_id, getAs<IdType>(doc_id).getNumber()); } void checkType(const string &id, const string &doc_type) { @@ -57,26 +47,6 @@ TEST("require that doc id can be parsed") { checkId(id, IdString::DOC, ns, ns_id); } -TEST("require that userdoc id can be parsed") { - const string id = "userdoc:" + ns + ":1234:" + ns_id; - checkId(id, IdString::USERDOC, ns, ns_id); - checkUser<UserDocIdString>(id, 1234); -} - -TEST("require that orderdoc id can be parsed") { - const string id = "orderdoc(31,19):" + ns + ":1234:1268182861:" + ns_id; - checkId(id, IdString::ORDERDOC, ns, ns_id); - checkUser<OrderDocIdString>(id, 1234); - checkOrdering(id, 1268182861); -} - -TEST("require that groupdoc id can be parsed") { - const string group = "mygroup"; - const string id = "groupdoc:" + ns + ":" + group + ":" + ns_id; - checkId(id, IdString::GROUPDOC, ns, ns_id); - checkGroup(id, group); -} - TEST("require that id id can be parsed") { const string id = "id:" + ns + ":" + type + "::" + ns_id; checkId(id, IdString::ID, ns, ns_id); @@ -92,16 +62,6 @@ TEST("require that we allow ':' in namespace specific part") { id="doc:" + ns + ":" + nss; checkId(id, IdString::DOC, ns, nss); - id="userdoc:" + ns + ":123:" + nss; - checkId(id, IdString::USERDOC, ns, nss); - checkUser<UserDocIdString>(id, 123); - - id="groupdoc:" + ns + ":123:" + nss; - checkId(id, IdString::GROUPDOC, ns, nss); - checkGroup(id, "123"); - - id="orderdoc(5,2):" + ns + ":42:007:" + nss; - checkId(id, IdString::ORDERDOC, ns, nss); } TEST("require that id id can specify location") { @@ -137,16 +97,16 @@ TEST("require that id id location is specified by local id only by default") { } TEST("require that local id can be empty") { - const string id = "userdoc:" + ns + ":1234:"; - checkId(id, IdString::USERDOC, ns, ""); - checkUser<UserDocIdString>(id, 1234); + const string id = "id:" + ns + ":type:n=1234:"; + checkId(id, IdString::ID, ns, ""); + checkUser<IdIdString>(id, 1234); } TEST("require that document ids can be assigned") { - DocumentId id1("userdoc:" + ns + ":1234:"); + DocumentId id1("id:" + ns + ":type:n=1234:"); DocumentId id2 = id1; - checkId(id2.toString(), IdString::USERDOC, ns, ""); - checkUser<UserDocIdString>(id2.toString(), 1234); + checkId(id2.toString(), IdString::ID, ns, ""); + checkUser<IdIdString>(id2.toString(), 1234); } TEST("require that illegal ids fail") { @@ -208,30 +168,11 @@ TEST("require that id strings reports features (hasNumber, hasGroup)") { EXPECT_EQUAL(42u, user.getScheme().getNumber()); EXPECT_EQUAL("foo", user.getScheme().getNamespaceSpecific()); - user = DocumentId("userdoc:ns:42:foo"); - EXPECT_TRUE(user.getScheme().hasNumber()); - EXPECT_FALSE(user.getScheme().hasGroup()); - EXPECT_EQUAL(42u, user.getScheme().getNumber()); - EXPECT_EQUAL("foo", user.getScheme().getNamespaceSpecific()); - DocumentId group("id:ns:type:g=mygroup:foo"); EXPECT_FALSE(group.getScheme().hasNumber()); EXPECT_TRUE(group.getScheme().hasGroup()); EXPECT_EQUAL("mygroup", group.getScheme().getGroup()); EXPECT_EQUAL("foo", group.getScheme().getNamespaceSpecific()); - - group = DocumentId("groupdoc:ns:mygroup:foo"); - EXPECT_FALSE(group.getScheme().hasNumber()); - EXPECT_TRUE(group.getScheme().hasGroup()); - EXPECT_EQUAL("mygroup", group.getScheme().getGroup()); - EXPECT_EQUAL("foo", group.getScheme().getNamespaceSpecific()); - - DocumentId order("orderdoc(5,2):ns:42:007:foo"); - EXPECT_TRUE(order.getScheme().hasNumber()); - EXPECT_TRUE(order.getScheme().hasGroup()); - EXPECT_EQUAL(42u, order.getScheme().getNumber()); - EXPECT_EQUAL("42", order.getScheme().getGroup()); - EXPECT_EQUAL("foo", order.getScheme().getNamespaceSpecific()); } } // namespace diff --git a/document/src/tests/bucketselectortest.cpp b/document/src/tests/bucketselectortest.cpp index fcd254a9fc6..d8950314a3a 100644 --- a/document/src/tests/bucketselectortest.cpp +++ b/document/src/tests/bucketselectortest.cpp @@ -57,11 +57,11 @@ namespace document { TEST(BucketSelectorTest, testSimple) { - ASSERT_BUCKET_COUNT("id = \"userdoc:ns:123:foobar\"", 1u); - ASSERT_BUCKET_COUNT("id = \"userdoc:ns:123:foo*\"", 0u); - ASSERT_BUCKET_COUNT("id == \"userdoc:ns:123:f?oo*\"", 1u); - ASSERT_BUCKET_COUNT("id =~ \"userdoc:ns:123:foo*\"", 0u); - ASSERT_BUCKET_COUNT("id =~ \"userdoc:ns:123:foo?\"", 0u); + ASSERT_BUCKET_COUNT("id = \"id:ns:testdoc:n=123:foobar\"", 1u); + ASSERT_BUCKET_COUNT("id = \"id:ns:testdoc:n=123:foo*\"", 0u); + ASSERT_BUCKET_COUNT("id == \"id:ns:testdoc:n=123:f?oo*\"", 1u); + ASSERT_BUCKET_COUNT("id =~ \"id:ns:testdoc:n=123:foo*\"", 0u); + ASSERT_BUCKET_COUNT("id =~ \"id:ns:testdoc:n=123:foo?\"", 0u); ASSERT_BUCKET_COUNT("id.user = 123", 1u); ASSERT_BUCKET_COUNT("id.user == 123", 1u); ASSERT_BUCKET_COUNT("id.group = \"yahoo.com\"", 1u); @@ -78,7 +78,7 @@ TEST(BucketSelectorTest, testSimple) ASSERT_BUCKET_COUNT("(testdoctype1 and id.bucket=0)", 1u); // Check that the correct buckets is found - ASSERT_BUCKET("id = \"userdoc:ns:123:foobar\"", + ASSERT_BUCKET("id = \"id:ns:testdoc:n=123:foobar\"", document::BucketId(58, 123)); ASSERT_BUCKET("id.bucket == 0x4000000000000258", document::BucketId(16, 600)); diff --git a/document/src/tests/buckettest.cpp b/document/src/tests/buckettest.cpp index 3de6d02b4b3..72e0a38c749 100644 --- a/document/src/tests/buckettest.cpp +++ b/document/src/tests/buckettest.cpp @@ -82,18 +82,12 @@ TEST(BucketTest, testBucketGeneration) DocumentId doc1("doc:ns:spec"); DocumentId doc2("doc:ns2:spec"); DocumentId doc3("doc:ns:spec2"); - DocumentId userDoc1("userdoc:ns:18:spec"); - DocumentId userDoc2("userdoc:ns2:18:spec2"); - DocumentId userDoc3("userdoc:ns:19:spec"); - DocumentId groupDoc1("groupdoc:ns:yahoo.com:spec"); - DocumentId groupDoc2("groupdoc:ns2:yahoo.com:spec2"); - DocumentId groupDoc3("groupdoc:ns:yahoo:spec"); - DocumentId orderDoc1("orderdoc(31,19):ns:13:1268182861:foo"); - DocumentId orderDoc2("orderdoc(31,19):ns:13:1205110861:foo"); - DocumentId orderDoc3("orderdoc(31,19):ns:13:1205715661:foo"); - DocumentId orderDoc4("orderdoc(4,0):ns:13:2:foo"); - DocumentId orderDoc5("orderdoc(4,0):ns:13:4:foo"); - DocumentId orderDoc6("orderdoc(4,0):ns:13:11:foo"); + DocumentId userDoc1("id:ns:mytype:n=18:spec"); + DocumentId userDoc2("id:ns2:mytype:n=18:spec2"); + DocumentId userDoc3("id:ns:mytype:n=19:spec"); + DocumentId groupDoc1("id:ns:mytype:g=yahoo.com:spec"); + DocumentId groupDoc2("id:ns2:mytype:g=yahoo.com:spec2"); + DocumentId groupDoc3("id:ns:mytype:g=yahoo:spec"); BucketId docBucket1(factory.getBucketId(doc1)); BucketId docBucket2(factory.getBucketId(doc2)); @@ -104,24 +98,10 @@ TEST(BucketTest, testBucketGeneration) BucketId groupDocBucket1(factory.getBucketId(groupDoc1)); BucketId groupDocBucket2(factory.getBucketId(groupDoc2)); BucketId groupDocBucket3(factory.getBucketId(groupDoc3)); - BucketId orderDocBucket1(factory.getBucketId(orderDoc1)); - BucketId orderDocBucket2(factory.getBucketId(orderDoc2)); - BucketId orderDocBucket3(factory.getBucketId(orderDoc3)); - BucketId orderDocBucket4(factory.getBucketId(orderDoc4)); - BucketId orderDocBucket5(factory.getBucketId(orderDoc5)); - BucketId orderDocBucket6(factory.getBucketId(orderDoc6)); - EXPECT_EQ(Hex(0xe99703f200000012ull), Hex(userDocBucket1.getRawId())); - EXPECT_EQ(Hex(0xebfa518a00000012ull), Hex(userDocBucket2.getRawId())); - EXPECT_EQ(Hex(0xeac1850800000013ull), Hex(userDocBucket3.getRawId())); - - EXPECT_EQ(Hex(0xeae764e90000000dull), Hex(orderDocBucket1.getRawId())); - EXPECT_EQ(Hex(0xeacb85f10000000dull), Hex(orderDocBucket2.getRawId())); - EXPECT_EQ(Hex(0xea68ddf10000000dull), Hex(orderDocBucket3.getRawId())); - - EXPECT_EQ(Hex(0xe87526540000000dull), Hex(orderDocBucket4.getRawId())); - EXPECT_EQ(Hex(0xea59f8f20000000dull), Hex(orderDocBucket5.getRawId())); - EXPECT_EQ(Hex(0xe9eb703d0000000dull), Hex(orderDocBucket6.getRawId())); + EXPECT_EQ(Hex(0xeb3089a300000012ull), Hex(userDocBucket1.getRawId())); + EXPECT_EQ(Hex(0xe87e777b00000012ull), Hex(userDocBucket2.getRawId())); + EXPECT_EQ(Hex(0xe80d16fc00000013ull), Hex(userDocBucket3.getRawId())); userDocBucket1.setUsedBits(16); EXPECT_EQ(Hex(0x4000000000000012ull), Hex(userDocBucket1.getId())); @@ -130,9 +110,9 @@ TEST(BucketTest, testBucketGeneration) userDocBucket3.setUsedBits(16); EXPECT_EQ(Hex(0x4000000000000013ull), Hex(userDocBucket3.getId())); - EXPECT_EQ(Hex(0xe90ce4b09a1acd50ull), Hex(groupDocBucket1.getRawId())); - EXPECT_EQ(Hex(0xe9cedaa49a1acd50ull), Hex(groupDocBucket2.getRawId())); - EXPECT_EQ(Hex(0xe8cdb18bafe81f24ull), Hex(groupDocBucket3.getRawId())); + EXPECT_EQ(Hex(0xeb82f2be9a1acd50ull), Hex(groupDocBucket1.getRawId())); + EXPECT_EQ(Hex(0xebff6e379a1acd50ull), Hex(groupDocBucket2.getRawId())); + EXPECT_EQ(Hex(0xe91b9600afe81f24ull), Hex(groupDocBucket3.getRawId())); groupDocBucket1.setUsedBits(16); EXPECT_EQ(Hex(0x400000000000cd50ull), Hex(groupDocBucket1.getId())); diff --git a/document/src/tests/cpp-globalidbucketids.txt b/document/src/tests/cpp-globalidbucketids.txt index 33dca454d3b..40bb505ad16 100644 --- a/document/src/tests/cpp-globalidbucketids.txt +++ b/document/src/tests/cpp-globalidbucketids.txt @@ -1,12 +1,6 @@ doc:ns:specific - gid(0x2c01a21163cb7d0ce85fddd6) - BucketId(0xeadd5fe811a2012c) doc:another:specific - gid(0xcd2ba528d1135e40605ce372) - BucketId(0xeae35c6028a52bcd) doc:ns:another - gid(0x1d5324270601e76a7a1f58b7) - BucketId(0xeb581f7a2724531d) -userdoc:ns:100:specific - gid(0x64000000e7bd2a0d13c71935) - BucketId(0xe919c71300000064) -userdoc:np:100:another - gid(0x64000000102745c9ceec3238) - BucketId(0xe832ecce00000064) -userdoc:ns:101:specific - gid(0x6500000026238735e9cd9bb8) - BucketId(0xe89bcde900000065) -groupdoc:ns:agroup:specific - gid(0x3272feb9fb729a50be795117) - BucketId(0xeb5179beb9fe7232) -groupdoc:np:agroup:another - gid(0x3272feb93ff5e65f3cf4aba9) - BucketId(0xe9abf43cb9fe7232) -groupdoc:ns:another:specific - gid(0xb32d73e51ae730d4fa104396) - BucketId(0xea4310fae5732db3) doc:ns:0 - gid(0x87817cf2f6d05976505e74be) - BucketId(0xea745e50f27c8187) doc:ns:1 - gid(0x911a03b253cb5b1c283b2024) - BucketId(0xe8203b28b2031a91) doc:ns:2 - gid(0x1d82e56be428cda364ed6875) - BucketId(0xe968ed646be5821d) diff --git a/document/src/tests/documentidtest.cpp b/document/src/tests/documentidtest.cpp index 198a8ce5e15..9befac431f6 100644 --- a/document/src/tests/documentidtest.cpp +++ b/document/src/tests/documentidtest.cpp @@ -26,12 +26,6 @@ TEST(DocumentIdTest, generateJavaComplianceFile) writeGlobalIdBucketId(ost, "doc:ns:specific"); writeGlobalIdBucketId(ost, "doc:another:specific"); writeGlobalIdBucketId(ost, "doc:ns:another"); - writeGlobalIdBucketId(ost, "userdoc:ns:100:specific"); - writeGlobalIdBucketId(ost, "userdoc:np:100:another"); - writeGlobalIdBucketId(ost, "userdoc:ns:101:specific"); - writeGlobalIdBucketId(ost, "groupdoc:ns:agroup:specific"); - writeGlobalIdBucketId(ost, "groupdoc:np:agroup:another"); - writeGlobalIdBucketId(ost, "groupdoc:ns:another:specific"); for (uint32_t i=0; i<20; ++i) { std::ostringstream ost2; ost2 << i; @@ -120,8 +114,7 @@ TEST(DocumentIdTest, testDocGlobalId) DocumentId did(id); unsigned char key[16]; - fastc_md5sum(reinterpret_cast<const unsigned char*>(id.c_str()), - id.size(), key); + fastc_md5sum(reinterpret_cast<const unsigned char*>(id.c_str()), id.size(), key); EXPECT_EQ(GlobalId(key), did.getGlobalId()); } @@ -130,10 +123,10 @@ TEST(DocumentIdTest, freestandingLocationFromGroupNameFuncMatchesIdLocation) { EXPECT_EQ( DocumentId("id::foo:g=zoid:bar").getScheme().getLocation(), - GroupDocIdString::locationFromGroupName("zoid")); + IdString::makeLocation("zoid")); EXPECT_EQ( DocumentId("id::bar:g=doink:baz").getScheme().getLocation(), - GroupDocIdString::locationFromGroupName("doink")); + IdString::makeLocation("doink")); } } // document diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 9ba38f5ca6b..97921109c60 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -199,7 +199,7 @@ DocumentSelectParserTest::createDocs() } _doc.push_back(createDoc( - "testdoctype1", "userdoc:myspace:1234:footype1", 15, 1.0, "some", "some", 0)); // DOC 2 + "testdoctype1", "id:myspace:testdoctype1:n=1234:footype1", 15, 1.0, "some", "some", 0)); // DOC 2 // Add empty struct and array { StructFieldValue sval(_doc.back()->getField("mystruct").getDataType()); @@ -209,32 +209,26 @@ DocumentSelectParserTest::createDocs() _doc.back()->setValue("structarray", aval); } _doc.push_back(createDoc( - "testdoctype1", "groupdoc:myspace:yahoo:bar", 14, 2.4, "Yet", "\xE4\xB8\xBA\xE4\xBB\x80", 0)); // DOC 3 + "testdoctype1", "id:myspace:testdoctype1:g=yahoo:bar", 14, 2.4, "Yet", "\xE4\xB8\xBA\xE4\xBB\x80", 0)); // DOC 3 _doc.push_back(createDoc( "testdoctype2", "doc:myspace:inheriteddoc", 10, 1.4, "inherited", "")); // DOC 4 _doc.push_back(createDoc( - "testdoctype1", "userdoc:footype:123456789:aardvark", + "testdoctype1", "id:footype:testdoctype1:n=123456789:aardvark", 10, 1.4, "inherited", "", 0)); // DOC 5 _doc.push_back(createDoc( - "testdoctype1", "userdoc:footype:1234:highlong", + "testdoctype1", "id:footype:testdoctype1:n=1234:highlong", 10, 1.4, "inherited", "", 2651257743)); // DOC 6 _doc.push_back(createDoc( - "testdoctype1", "userdoc:footype:1234:highlong", + "testdoctype1", "id:footype:testdoctype1:n=1234:highlong", 10, 1.4, "inherited", "", -2651257743)); // DOC 7 - _doc.push_back(createDoc( // DOC 8 - "testdoctype1", "orderdoc(4,4):footype:1234:12:highlong", - 10, 1.4, "inherited", "", -2651257743)); - _doc.push_back(createDoc( // DOC 9 - "testdoctype1", "orderdoc(4,4):footype:mygroup:12:highlong", - 10, 1.4, "inherited", "", -2651257743)); - _doc.push_back(createDoc( // DOC 10. As DOC 0 but with version 2. + _doc.push_back(createDoc( // DOC 8. As DOC 0 but with version 2. "testdoctype1", "doc:myspace:anything", 24, 2.0, "foo", "bar", 0)); _doc.push_back(createDoc( "testdoctype1", "id:footype:testdoctype1:n=12345:foo", - 10, 1.4, "inherited", "", 42)); // DOC 11 + 10, 1.4, "inherited", "", 42)); // DOC 9 _doc.push_back(createDoc( "testdoctype1", "id:myspace:testdoctype1:g=xyzzy:foo", - 10, 1.4, "inherited", "", 42)); // DOC 12 + 10, 1.4, "inherited", "", 42)); // DOC 10 _update.clear(); _update.push_back(createUpdate( @@ -242,9 +236,9 @@ DocumentSelectParserTest::createDocs() _update.push_back(createUpdate( "testdoctype1", "doc:anotherspace:foo", 10, "foo")); _update.push_back(createUpdate( - "testdoctype1", "userdoc:myspace:1234:footype1", 0, "foo")); + "testdoctype1", "id:myspace:testdoctype1:n=1234:footype1", 0, "foo")); _update.push_back(createUpdate( - "testdoctype1", "groupdoc:myspace:yahoo:bar", 3, "\xE4\xBA\xB8\xE4\xBB\x80")); + "testdoctype1", "id:myspace:testdoctype1:g=yahoo:bar", 3, "\xE4\xBA\xB8\xE4\xBB\x80")); _update.push_back(createUpdate( "testdoctype2", "doc:myspace:inheriteddoc", 10, "bar")); } @@ -398,23 +392,22 @@ TEST_F(DocumentSelectParserTest, testParseTerminals) verifyParse("_test_doctype3_._only_in_child_ == 0"); // Test document id with simple parser. - verifySimpleParse("id == \"userdoc:ns:mytest\""); + verifySimpleParse("id == \"id:ns:mytest\""); verifySimpleParse("id.namespace == \"myspace\""); - verifySimpleParse("id.scheme == \"userdoc\""); + verifySimpleParse("id.scheme == \"id\""); verifySimpleParse("id.type == \"testdoctype1\""); verifySimpleParse("id.group == \"yahoo.com\""); verifySimpleParse("id.user == 1234"); verifySimpleParse("id.user == 0x12456ab", "id.user == 19158699"); // Test document id - verifyParse("id == \"userdoc:ns:mytest\""); + verifyParse("id == \"id:ns:mytest\""); verifyParse("id.namespace == \"myspace\""); - verifyParse("id.scheme == \"userdoc\""); + verifyParse("id.scheme == \"id\""); verifyParse("id.type == \"testdoctype1\""); verifyParse("id.user == 1234"); verifyParse("id.user == 0x12456ab", "id.user == 19158699"); verifyParse("id.group == \"yahoo.com\""); - verifyParse("id.order(10,5) < 100"); verifyParse("id.specific == \"mypart\""); verifyParse("id.bucket == 1234"); @@ -633,9 +626,9 @@ void DocumentSelectParserTest::testOperators2() PARSEI(" iD== \"doc:myspace:anything\" ", *_doc[0], True); PARSEI("id == \"doc:myspa:nything\"", *_doc[0], False); PARSEI("Id.scHeme == \"doc\"", *_doc[0], True); - PARSEI("id.scheme == \"userdoc\"", *_doc[0], False); - PARSEI("id.type == \"testdoctype1\"", *_doc[11], True); - PARSEI("id.type == \"wrong_type\"", *_doc[11], False); + PARSEI("id.scheme == \"id\"", *_doc[0], False); + PARSEI("id.type == \"testdoctype1\"", *_doc[9], True); + PARSEI("id.type == \"wrong_type\"", *_doc[9], False); PARSEI("id.type == \"unknown\"", *_doc[0], Invalid); PARSEI("Id.namespaCe == \"myspace\"", *_doc[0], True); PARSEI("id.NaMespace == \"pace\"", *_doc[0], False); @@ -645,14 +638,8 @@ void DocumentSelectParserTest::testOperators2() PARSEI("id.group == 1234", *_doc[3], Invalid); PARSEI("id.group == \"yahoo\"", *_doc[3], True); PARSEI("id.bucket == 1234", *_doc[0], False); - PARSEI("id.order(4,4) == 12", *_doc[8], True); - PARSEI("id.order(4,4) < 20", *_doc[8], True); - PARSEI("id.order(4,4) > 12", *_doc[8], False); - PARSEI("id.order(5,5) <= 12", *_doc[8], Invalid); - PARSEI("id.order(4,4) <= 12", *_doc[8], True); - PARSEI("id.order(4,4) == 12", *_doc[0], Invalid); - PARSEI("id.user=12345", *_doc[11], True); - PARSEI("id.group == \"xyzzy\"", *_doc[12], True); + PARSEI("id.user=12345", *_doc[9], True); + PARSEI("id.group == \"xyzzy\"", *_doc[10], True); } void DocumentSelectParserTest::testOperators3() @@ -684,12 +671,8 @@ void DocumentSelectParserTest::testOperators3() std::string gidmatcher = "id.gid == \"" + _doc[0]->getId().getGlobalId().toString() + "\""; PARSEI(gidmatcher, *_doc[0], True); - PARSEI("id.user=123456789 and id = \"userdoc:footype:123456789:aardvark\"", *_doc[5], True); - PARSEI("id == \"userdoc:footype:123456789:badger\"", *_doc[5], False); - - PARSEI("id.user = 1234", *_doc[8], True); - PARSEI("id.group == \"1234\"", *_doc[8], True); - PARSEI("id.group == \"mygroup\"", *_doc[9], True); + PARSEI("id.user=123456789 and id = \"id:footype:testdoctype1:n=123456789:aardvark\"", *_doc[5], True); + PARSEI("id == \"id:footype:testdoctype1:n=123456789:badger\"", *_doc[5], False); } void DocumentSelectParserTest::testOperators4() @@ -734,10 +717,10 @@ void DocumentSelectParserTest::testOperators5() PARSEI("(0.234).lowercase() == 123", *_doc[0], Invalid); PARSE("\"foo\".hash() == 123", *_doc[0], False); PARSEI("(234).hash() == 123", *_doc[0], False); - PARSE("now() > 1311862500", *_doc[10], True); - PARSE("now() < 1611862500", *_doc[10], True); - PARSE("now() < 1311862500", *_doc[10], False); - PARSE("now() > 1611862500", *_doc[10], False); + PARSE("now() > 1311862500", *_doc[8], True); + PARSE("now() < 1611862500", *_doc[8], True); + PARSE("now() < 1311862500", *_doc[8], False); + PARSE("now() > 1611862500", *_doc[8], False); // Arithmetics PARSEI("id.specific.hash() % 10 = 8", *_doc[0], True); @@ -1129,7 +1112,7 @@ void DocumentSelectParserTest::testDocumentUpdates2() PARSEI(" iD== \"doc:myspace:anything\" ", *_update[0], True); PARSEI("id == \"doc:myspa:nything\"", *_update[0], False); PARSEI("Id.scHeme == \"doc\"", *_update[0], True); - PARSEI("id.scheme == \"userdoc\"", *_update[0], False); + PARSEI("id.scheme == \"id\"", *_update[0], False); PARSEI("Id.namespaCe == \"myspace\"", *_update[0], True); PARSEI("id.NaMespace == \"pace\"", *_update[0], False); PARSEI("id.specific == \"anything\"", *_update[0], True); @@ -1199,7 +1182,7 @@ TEST_F(DocumentSelectParserTest, testDocumentIdsInRemoves) { PARSE("testdoctype1", DocumentId("id:ns:testdoctype1::1"), True); PARSE("testdoctype1", DocumentId("id:ns:null::1"), False); - PARSE("testdoctype1", DocumentId("userdoc:testdoctype1:1234:1"), False); + PARSE("testdoctype1", DocumentId("id::testdoctype2:n=1234:1"), False); PARSE("testdoctype1.headerval", DocumentId("id:ns:testdoctype1::1"), Invalid); // FIXME: Should ideally be False. As long as there always is an AND node with doctype in a selection expression // we won't end up sending removes using the wrong route. @@ -1409,12 +1392,11 @@ TEST_F(DocumentSelectParserTest, test_token_used_as_ident_preserves_casing) createDocs(); using namespace std::string_literals; - // TYPE, SCHEME, ORDER etc are tokens that may also be used as identifiers + // TYPE, SCHEME etc are tokens that may also be used as identifiers // without introducing parsing ambiguities. In this context their original // casing should be preserved. EXPECT_EQ("(== (VAR Type) 123)"s, parse_to_tree("$Type == 123")); EXPECT_EQ("(== (VAR giD) 123)"s, parse_to_tree("$giD == 123")); - EXPECT_EQ("(== (VAR ORDER) 123)"s, parse_to_tree("$ORDER == 123")); } TEST_F(DocumentSelectParserTest, test_ambiguous_field_spec_expression_is_handled_correctly) diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 5521fac58e8..089ab5a2a2d 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -388,7 +388,7 @@ TEST(DocumentTest, testSimpleUsage) std::unique_ptr<ByteBuffer> buffer(value.serialize()); buffer->flip(); Document value2(*repo.getDocumentType("test"), - DocumentId("userdoc::3:foo")); + DocumentId("id::test:n=3:foo")); EXPECT_TRUE(value != value2); value2.deserialize(repo, *buffer); EXPECT_TRUE(value2.hasValue(intF)); diff --git a/document/src/tests/globalidtest.cpp b/document/src/tests/globalidtest.cpp index c6c974011ce..ab2af875e9f 100644 --- a/document/src/tests/globalidtest.cpp +++ b/document/src/tests/globalidtest.cpp @@ -84,18 +84,17 @@ namespace { TEST_F(GlobalIdTest, testBucketIdConversion) { - verifyDocumentId("userdoc:ns:1:abc"); - verifyDocumentId("userdoc:ns:1000:abc"); - verifyDocumentId("userdoc:hsgf:18446744073700000000:dfdfsdfg"); - verifyDocumentId("groupdoc:ns:somegroup:hmm"); + verifyDocumentId("id:ns:test:n=1:abc"); + verifyDocumentId("id:ns:test:n=1000:abc"); + verifyDocumentId("id:hsgf:test:n=18446744073700000000:dfdfsdfg"); + verifyDocumentId("id:ns:mytype:g=somegroup:hmm"); verifyDocumentId("doc::test"); verifyDocumentId("doc:myns:http://foo.bar"); verifyDocumentId("doc:jsrthsdf:a234aleingzldkifvasdfgadf"); } void -GlobalIdTest::verifyGlobalIdRange(const std::vector<DocumentId>& ids, - uint32_t countBits) +GlobalIdTest::verifyGlobalIdRange(const std::vector<DocumentId>& ids, uint32_t countBits) { BucketIdFactory factory; for (uint32_t i=0, n=ids.size(); i<n; ++i) { @@ -158,12 +157,11 @@ TEST_F(GlobalIdTest, testGidRangeConversion) switch (scheme) { case 0: ost << "doc:" << name_space.str() << ":"; break; - case 1: ost << "userdoc:" << name_space.str() << ":"; + case 1: ost << "id:" << name_space.str() << ":mytype:n="; ost << randomizer.nextUint32() << ":"; break; - case 2: ost << "groupdoc:" << name_space.str() << ":"; - for (uint32_t i=0, n=randomizer.nextUint32(1, 10); i<n; ++i) - { + case 2: ost << "id:" << name_space.str() << ":mytype:g="; + for (uint32_t i=0, n=randomizer.nextUint32(1, 10); i<n; ++i) { ost << (char) ('a' + randomizer.nextUint32(0, 25)); } ost << ":"; diff --git a/document/src/tests/orderingselectortest.cpp b/document/src/tests/orderingselectortest.cpp deleted file mode 100644 index bb3fe10f198..00000000000 --- a/document/src/tests/orderingselectortest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/document/select/orderingselector.h> -#include <vespa/document/bucket/bucketidfactory.h> -#include <vespa/document/base/testdocrepo.h> - -#include <vespa/document/select/parser.h> -#include <memory> -#include <gtest/gtest.h> - -using document::select::Node; -using document::select::Parser; - -namespace document { - -#define ASSERT_MATCH(expression, ordering, correct) \ -{ \ - BucketIdFactory idfactory; \ - TestDocRepo repo; \ - OrderingSelector selector; \ - Parser parser(repo.getTypeRepo(), idfactory); \ - std::unique_ptr<Node> node(parser.parse(expression)); \ - ASSERT_TRUE(node); \ - OrderingSpecification::UP spec = selector.select(*node, ordering); \ - if (spec.get() == NULL && correct.get() == NULL) { \ - return;\ - }\ - if (spec.get() == NULL && correct.get() != NULL) { \ - FAIL() << "Was NULL, expected " << correct->toString(); \ - } \ - if (correct.get() == NULL && spec.get() != NULL) { \ - FAIL() << "Expected NULL, was " << spec->toString(); \ - } \ - EXPECT_EQ(*correct, *spec); \ -} - -TEST(OrderingSelectorTest, testSimple) -{ - ASSERT_MATCH("id.order(10,10) < 100", OrderingSpecification::DESCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::DESCENDING, (long)99, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) <= 100", OrderingSpecification::DESCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::DESCENDING, (long)100, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) > 100", OrderingSpecification::DESCENDING, OrderingSpecification::UP()); - - ASSERT_MATCH("id.order(10,10) > 100", OrderingSpecification::ASCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::ASCENDING, (long)101, (short)10, (short)10))); - - ASSERT_MATCH("id.user==1234 AND id.order(10,10) > 100", OrderingSpecification::ASCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::ASCENDING, (long)101, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) >= 100", OrderingSpecification::ASCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::ASCENDING, (long)100, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) == 100", OrderingSpecification::ASCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::ASCENDING, (long)100, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) = 100", OrderingSpecification::DESCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::DESCENDING, (long)100, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) > 30 AND id.order(10,10) < 100", OrderingSpecification::ASCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::ASCENDING, (long)31, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) > 30 AND id.order(10,10) < 100", OrderingSpecification::DESCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::DESCENDING, (long)99, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) > 30 OR id.order(10,10) > 70", OrderingSpecification::ASCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::ASCENDING, (long)31, (short)10, (short)10))); - - ASSERT_MATCH("id.order(10,10) < 30 OR id.order(10,10) < 70", OrderingSpecification::DESCENDING, - OrderingSpecification::UP( - new OrderingSpecification(OrderingSpecification::DESCENDING, (long)69, (short)10, (short)10))); -} - - -} diff --git a/document/src/vespa/document/base/idstring.cpp b/document/src/vespa/document/base/idstring.cpp index 223baa6fd8d..5166b03428e 100644 --- a/document/src/vespa/document/base/idstring.cpp +++ b/document/src/vespa/document/base/idstring.cpp @@ -276,24 +276,15 @@ union LocationUnion { IdString::LocationType _location[2]; }; -IdString::LocationType makeLocation(stringref s) { - LocationUnion location; - fastc_md5sum(reinterpret_cast<const unsigned char*>(s.data()), s.size(), location._key); - return location._location[0]; -} - uint64_t parseNumber(stringref number) { char* errPos = NULL; errno = 0; uint64_t n = strtoul(number.data(), &errPos, 10); if (*errPos) { - throw IdParseException( - "'n'-value must be a 64-bit number. It was " + - number, VESPA_STRLOC); + throw IdParseException("'n'-value must be a 64-bit number. It was " + number, VESPA_STRLOC); } if (errno == ERANGE) { - throw IdParseException("'n'-value out of range " - "(" + number + ")", VESPA_STRLOC); + throw IdParseException("'n'-value out of range (" + number + ")", VESPA_STRLOC); } return n; } @@ -301,8 +292,7 @@ uint64_t parseNumber(stringref number) { void setLocation(IdString::LocationType &loc, IdString::LocationType val, bool &has_set_location, stringref key_values) { if (has_set_location) { - throw IdParseException("Illegal key combination in " - + key_values); + throw IdParseException("Illegal key combination in " + key_values); } loc = val; has_set_location = true; @@ -311,6 +301,13 @@ void setLocation(IdString::LocationType &loc, IdString::LocationType val, } // namespace +IdString::LocationType +IdString::makeLocation(stringref s) { + LocationUnion location; + fastc_md5sum(reinterpret_cast<const unsigned char*>(s.data()), s.size(), location._key); + return location._location[0]; +} + IdIdString::IdIdString(stringref id) : IdString(4, 3, id), _location(0), diff --git a/document/src/vespa/document/base/idstring.h b/document/src/vespa/document/base/idstring.h index c458e7a62f4..c77289fd659 100644 --- a/document/src/vespa/document/base/idstring.h +++ b/document/src/vespa/document/base/idstring.h @@ -26,6 +26,7 @@ public: /** @throws document::IdParseException If parsing of id scheme failed. */ static IdString::UP createIdString(vespalib::stringref id) { return createIdString(id.data(), id.size()); } static IdString::UP createIdString(const char *id, size_t sz); + static LocationType makeLocation(vespalib::stringref s); ~IdString() {} IdString* clone() const override = 0; diff --git a/document/src/vespa/document/select/CMakeLists.txt b/document/src/vespa/document/select/CMakeLists.txt index bc73498622d..a4536f82c21 100644 --- a/document/src/vespa/document/select/CMakeLists.txt +++ b/document/src/vespa/document/select/CMakeLists.txt @@ -25,7 +25,6 @@ vespa_add_library(document_select OBJECT gid_filter.cpp invalidconstant.cpp operator.cpp - orderingselector.cpp orderingspecification.cpp result.cpp resultset.cpp diff --git a/document/src/vespa/document/select/gid_filter.cpp b/document/src/vespa/document/select/gid_filter.cpp index 71a57a0886a..a9a6b8e9bc7 100644 --- a/document/src/vespa/document/select/gid_filter.cpp +++ b/document/src/vespa/document/select/gid_filter.cpp @@ -122,8 +122,7 @@ private: uint32_t location_from_string_literal_node( const StringValueNode& node) const { - auto full_location = GroupDocIdString::locationFromGroupName( - node.getValue()); + auto full_location = IdString::makeLocation(node.getValue()); return truncate_location(full_location); } diff --git a/document/src/vespa/document/select/grammar/lexer.ll b/document/src/vespa/document/select/grammar/lexer.ll index 6483b5e8534..bd011c8ebf6 100644 --- a/document/src/vespa/document/select/grammar/lexer.ll +++ b/document/src/vespa/document/select/grammar/lexer.ll @@ -129,7 +129,6 @@ SQ_STRING \'(\\([\\tnfr']|x{HEXDIGIT}{2})|[^'\\])*\' (?i:"bucket") STRING_TOKEN(BUCKET) (?i:"gid") STRING_TOKEN(GID) (?i:"type") STRING_TOKEN(TYPE) -(?i:"order") STRING_TOKEN(ORDER) "now\(\)" NAMED_TOKEN(NOW_FUNC) /* This _is_ case-sensitive in the legacy parser */ diff --git a/document/src/vespa/document/select/grammar/parser.yy b/document/src/vespa/document/select/grammar/parser.yy index f96bd50378f..76b7cb7eeba 100644 --- a/document/src/vespa/document/select/grammar/parser.yy +++ b/document/src/vespa/document/select/grammar/parser.yy @@ -73,7 +73,7 @@ %token <string_val> FP_MAP_LOOKUP FP_ARRAY_LOOKUP %token <double_val> FLOAT %token <i64_val> INTEGER -%token <string_val> USER GROUP SCHEME NAMESPACE SPECIFIC BUCKET GID TYPE ORDER +%token <string_val> USER GROUP SCHEME NAMESPACE SPECIFIC BUCKET GID TYPE %type <string_val> ident mangled_ident %type <abstract_node> bool_ @@ -84,7 +84,7 @@ %type <field_expr_node> field_spec %destructor { delete $$; } IDENTIFIER STRING FP_MAP_LOOKUP FP_ARRAY_LOOKUP -%destructor { delete $$; } USER GROUP SCHEME NAMESPACE SPECIFIC BUCKET GID TYPE ORDER +%destructor { delete $$; } USER GROUP SCHEME NAMESPACE SPECIFIC BUCKET GID TYPE %destructor { delete $$; } null_ bool_ number string doc_type ident id_arg id_spec %destructor { delete $$; } variable mangled_ident field_spec value arith_expr %destructor { delete $$; } comparison leaf logical_expr expression @@ -227,7 +227,6 @@ ident | SPECIFIC { $$ = $1; } | BUCKET { $$ = $1; } | GID { $$ = $1; } - | ORDER { $$ = $1; } ; id_arg @@ -245,7 +244,6 @@ id_spec : ID %prec NON_DOT { $$ = new IdValueNode(bucket_id_factory, "id", ""); } /* Prefer shifting instead of reducing */ | ID "." id_arg { $$ = new IdValueNode(bucket_id_factory, "id", *steal<string>($3)); } | ID "." IDENTIFIER "(" ")" { $$ = new FunctionValueNode(*steal<string>($3), std::make_unique<IdValueNode>(bucket_id_factory, "id", "")); } - | ID "." ORDER "(" INTEGER "," INTEGER ")" { $$ = new IdValueNode(bucket_id_factory, "id", *steal<string>($3), $5, $7); } ; variable diff --git a/document/src/vespa/document/select/orderingselector.cpp b/document/src/vespa/document/select/orderingselector.cpp deleted file mode 100644 index 836647aab26..00000000000 --- a/document/src/vespa/document/select/orderingselector.cpp +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "orderingselector.h" -#include "node.h" -#include "valuenodes.h" -#include "visitor.h" -#include "compare.h" -#include "branch.h" - -#include <vespa/document/base/documentid.h> - -namespace document { - -using namespace select; - -namespace { - /** - * Visitor class that is used for visiting a node tree generated by a - * document selection expression. - * - * The visitor class contains the set of buckets expression can match. - */ - struct OrderingVisitor : public document::select::Visitor - { - OrderingSpecification::UP _spec; - OrderingSpecification::Order _order; - - OrderingVisitor(OrderingSpecification::Order order) - : _order(order) { - } - - OrderingSpecification::UP pickOrdering(const OrderingSpecification& a, const OrderingSpecification& b, bool isAnd) { - if (a.getWidthBits() == b.getWidthBits() && a.getDivisionBits() == b.getDivisionBits() && a.getOrder() == b.getOrder()) { - if ((a.getOrder() == OrderingSpecification::ASCENDING && isAnd) || - (a.getOrder() == OrderingSpecification::DESCENDING && !isAnd)) { - return OrderingSpecification::UP( - new OrderingSpecification(a.getOrder(), std::max(a.getOrderingStart(), b.getOrderingStart()), b.getWidthBits(), a.getDivisionBits())); - } else { - return OrderingSpecification::UP( - new OrderingSpecification(a.getOrder(), std::min(a.getOrderingStart(), b.getOrderingStart()), b.getWidthBits(), a.getDivisionBits())); - } - } - return OrderingSpecification::UP(); - } - - void visitAndBranch(const document::select::And& node) override { - OrderingVisitor left(_order); - node.getLeft().visit(left); - node.getRight().visit(*this); - - if (left._spec.get() == NULL) { - return; - } - - // If only left part is known return that part. - if (_spec.get() == NULL) { - _spec = std::move(left._spec); - return; - } - - // Both are set... - _spec = pickOrdering(*_spec, *left._spec, true); - } - - void visitOrBranch(const document::select::Or& node) override { - OrderingVisitor left(_order); - node.getLeft().visit(left); - node.getRight().visit(*this); - - // If one part is unknown we have to keep unknown status - if (left._spec.get() == NULL || _spec.get() == NULL) { - return; - } - - _spec = pickOrdering(*_spec, *left._spec, false); - } - - void visitNotBranch(const document::select::Not&) override {} - - void compare(const select::IdValueNode& node, - const select::ValueNode& valnode, - const select::Operator& op, OrderingSpecification::Order order) - { - if (node.getType() != IdValueNode::ORDER) { - return; - } - - if (node.getWidthBits() == -1 || node.getDivisionBits() == -1) { - return; - } - - const IntegerValueNode* val( - dynamic_cast<const IntegerValueNode*>(&valnode)); - if (!val) return; - - if (op == document::select::FunctionOperator::EQ) { - _spec.reset(new OrderingSpecification(order, val->getValue(), node.getWidthBits(), node.getDivisionBits())); - } - - if (order == OrderingSpecification::ASCENDING) { - if (op == document::select::FunctionOperator::LEQ) { - _spec.reset(new OrderingSpecification(order, 0, node.getWidthBits(), node.getDivisionBits())); - } - if (op == document::select::FunctionOperator::GT) { - _spec.reset(new OrderingSpecification(order, val->getValue() + 1, node.getWidthBits(), node.getDivisionBits())); - } - if (op == document::select::FunctionOperator::GEQ) { - _spec.reset(new OrderingSpecification(order, val->getValue(), node.getWidthBits(), node.getDivisionBits())); - } - } else { - if (op == document::select::FunctionOperator::LT) { - _spec.reset(new OrderingSpecification(order, val->getValue() - 1, node.getWidthBits(), node.getDivisionBits())); - } - if (op == document::select::FunctionOperator::LEQ) { - _spec.reset(new OrderingSpecification(order, val->getValue(), node.getWidthBits(), node.getDivisionBits())); - } - } - } - - void visitComparison(const document::select::Compare& node) override { - const IdValueNode* lid(dynamic_cast<const IdValueNode*>( - &node.getLeft())); - if (lid) { - compare(*lid, node.getRight(), node.getOperator(), _order); - } else { - const IdValueNode* rid(dynamic_cast<const IdValueNode*>( - &node.getRight())); - if (rid) { - compare(*rid, node.getLeft(), node.getOperator(), _order); - } - } - } - - void visitConstant(const document::select::Constant&) override {} - void visitInvalidConstant(const document::select::InvalidConstant &) override {} - void visitDocumentType(const document::select::DocType&) override {} - void visitArithmeticValueNode(const ArithmeticValueNode &) override {} - void visitFunctionValueNode(const FunctionValueNode &) override {} - void visitIdValueNode(const IdValueNode &) override {} - void visitFieldValueNode(const FieldValueNode &) override {} - void visitFloatValueNode(const FloatValueNode &) override {} - void visitVariableValueNode(const VariableValueNode &) override {} - void visitIntegerValueNode(const IntegerValueNode &) override {} - void visitCurrentTimeValueNode(const CurrentTimeValueNode &) override {} - void visitStringValueNode(const StringValueNode &) override {} - void visitNullValueNode(const NullValueNode &) override {} - void visitInvalidValueNode(const InvalidValueNode &) override {} - }; -} - -OrderingSpecification::UP -OrderingSelector::select(const document::select::Node& expression, OrderingSpecification::Order order) const -{ - OrderingVisitor v(order); - expression.visit(v); - return std::move(v._spec); -} - -} // document diff --git a/document/src/vespa/document/select/orderingselector.h b/document/src/vespa/document/select/orderingselector.h deleted file mode 100644 index 0d4c9702f8b..00000000000 --- a/document/src/vespa/document/select/orderingselector.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include <vector> -#include <utility> -#include <memory> -#include "orderingspecification.h" - -namespace document { -namespace select { - class Node; -} - -class OrderingSelector { -public: - /** - * Return the ordering specification implied by this document selection expression. - * - * @param expression The document selection expression to parse. - * @param ordering The ordering the user has selected to visit (ASCENDING/DESCENDING) - */ - OrderingSpecification::UP select(const select::Node& expression, OrderingSpecification::Order ordering) const; - -private: -}; - -} // document - diff --git a/document/src/vespa/document/select/valuenodes.cpp b/document/src/vespa/document/select/valuenodes.cpp index 452d277874c..bc94e3667d2 100644 --- a/document/src/vespa/document/select/valuenodes.cpp +++ b/document/src/vespa/document/select/valuenodes.cpp @@ -465,8 +465,6 @@ IdValueNode::IdValueNode(const BucketIdFactory& bucketIdFactory, case 'u': _type = USER; break; - case 'o': - _type = ORDER; break; } } @@ -524,19 +522,6 @@ IdValueNode::getValue(const DocumentId& id) const case GID: value = id.getGlobalId().toString(); break; - case ORDER: - if (id.getScheme().getType() == IdString::ORDERDOC) { - const OrderDocIdString& ods( - static_cast<const OrderDocIdString&>(id.getScheme())); - if (ods.getWidthBits() == _widthBits - && ods.getDivisionBits() == _divisionBits) - { - return std::unique_ptr<Value>(new IntegerValue( - static_cast<const OrderDocIdString&>(id.getScheme()) - .getOrdering(), false)); - } - } - return std::unique_ptr<Value>(new InvalidValue()); case USER: if (id.getScheme().hasNumber()) { return std::unique_ptr<Value>( @@ -617,23 +602,6 @@ IdValueNode::traceValue(const DocumentId& id, std::ostream& out) const value = id.getGlobalId().toString(); out << "Resolved gid to \"" << value << "\".\n"; break; - case ORDER: - if (id.getScheme().getType() == IdString::ORDERDOC) { - const OrderDocIdString& ods( - static_cast<const OrderDocIdString&>(id.getScheme())); - if (ods.getWidthBits() == _widthBits - && ods.getDivisionBits() == _divisionBits) - { - std::unique_ptr<Value> result(new IntegerValue( - static_cast<const OrderDocIdString&>(id.getScheme()) - .getOrdering(), false)); - out << "Resolved id.order to int " << *result << "\n"; - return result; - } - } - out << "Could not resolve id.order(" << _widthBits << ", " - << _divisionBits << ") of doc " << id << ".\n"; - return std::unique_ptr<Value>(new InvalidValue()); case USER: if (id.getScheme().hasNumber()) { std::unique_ptr<Value> result( @@ -668,9 +636,6 @@ IdValueNode::print(std::ostream& out, bool verbose, if (_type != ALL) { out << '.' << _typestring; } - if (_type == ORDER) { - out << "(" << _widthBits << "," << _divisionBits << ")"; - } if (hadParentheses()) out << ')'; } diff --git a/document/src/vespa/document/select/valuenodes.h b/document/src/vespa/document/select/valuenodes.h index 0b7d23e1e30..4ddbee16f8c 100644 --- a/document/src/vespa/document/select/valuenodes.h +++ b/document/src/vespa/document/select/valuenodes.h @@ -239,7 +239,7 @@ private: class IdValueNode : public ValueNode { public: - enum Type { SCHEME, NS, TYPE, USER, GROUP, GID, SPEC, BUCKET, ORDER, ALL }; + enum Type { SCHEME, NS, TYPE, USER, GROUP, GID, SPEC, BUCKET, ALL }; IdValueNode(const BucketIdFactory& bucketIdFactory, vespalib::stringref name, vespalib::stringref type, |