diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-07-23 14:58:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-23 14:58:55 +0200 |
commit | 01862bd9cb0608a3cda36800eb73e6dc9bfa5157 (patch) | |
tree | 1d5f6f17849e3385d63bcaa9dbd291f8a71493c9 | |
parent | 9858249df9d40ba1c3b9eff850eade210ca964f9 (diff) | |
parent | b60233cdb1979703f7fb75d27d38b94a4a6156c0 (diff) |
Merge pull request #10080 from vespa-engine/balder/short-circuit-and-or
Balder/short circuit and or
29 files changed, 374 insertions, 862 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json index 81cf5509a57..134200d96ec 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -3601,723 +3601,6 @@ ], "fields": [] }, - "com.yahoo.document.select.convert.NowQueryExpression": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(com.yahoo.document.select.rule.AttributeNode, com.yahoo.document.select.rule.ComparisonNode, com.yahoo.document.select.rule.ArithmeticNode)", - "public java.lang.String getDocumentType()", - "public java.lang.String toString()" - ], - "fields": [] - }, - "com.yahoo.document.select.convert.NowQueryNode": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(long)", - "public void <init>(com.yahoo.document.select.rule.ArithmeticNode)", - "public java.lang.String toString()" - ], - "fields": [] - }, - "com.yahoo.document.select.convert.SelectionExpressionConverter": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.Visitor" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public java.util.Map getQueryMap()", - "public void visit(com.yahoo.document.select.rule.ArithmeticNode)", - "public void visit(com.yahoo.document.select.rule.AttributeNode)", - "public void visit(com.yahoo.document.select.rule.ComparisonNode)", - "public void visit(com.yahoo.document.select.rule.DocumentNode)", - "public void visit(com.yahoo.document.select.rule.EmbracedNode)", - "public void visit(com.yahoo.document.select.rule.IdNode)", - "public void visit(com.yahoo.document.select.rule.LiteralNode)", - "public void visit(com.yahoo.document.select.rule.LogicNode)", - "public void visit(com.yahoo.document.select.rule.NegationNode)", - "public void visit(com.yahoo.document.select.rule.NowNode)", - "public void visit(com.yahoo.document.select.rule.SearchColumnNode)", - "public void visit(com.yahoo.document.select.rule.VariableNode)" - ], - "fields": [] - }, - "com.yahoo.document.select.parser.CharStream": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public", - "interface", - "abstract" - ], - "methods": [ - "public abstract char readChar()", - "public abstract int getBeginColumn()", - "public abstract int getBeginLine()", - "public abstract int getEndColumn()", - "public abstract int getEndLine()", - "public abstract void backup(int)", - "public abstract char beginToken()", - "public abstract java.lang.String getImage()", - "public abstract char[] getSuffix(int)", - "public abstract void done()", - "public abstract void setTabSize(int)", - "public abstract int getTabSize()", - "public abstract void setTrackLineColumn(boolean)", - "public abstract boolean isTrackLineColumn()" - ], - "fields": [] - }, - "com.yahoo.document.select.parser.ParseException": { - "superClass": "java.lang.Exception", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(com.yahoo.document.select.parser.Token, int[][], java.lang.String[])", - "public void <init>()", - "public void <init>(java.lang.String)" - ], - "fields": [ - "protected static final java.lang.String EOL", - "public com.yahoo.document.select.parser.Token currentToken", - "public int[][] expectedTokenSequences", - "public java.lang.String[] tokenImage" - ] - }, - "com.yahoo.document.select.parser.SelectInput": { - "superClass": "com.yahoo.javacc.FastCharStream", - "interfaces": [ - "com.yahoo.document.select.parser.CharStream" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(java.lang.String)" - ], - "fields": [] - }, - "com.yahoo.document.select.parser.SelectParser": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.parser.SelectParserConstants" - ], - "attributes": [ - "public" - ], - "methods": [ - "public final com.yahoo.document.select.rule.ExpressionNode expression()", - "public final com.yahoo.document.select.rule.ExpressionNode logic()", - "public final com.yahoo.document.select.rule.ExpressionNode negation()", - "public final com.yahoo.document.select.rule.NowNode now()", - "public final com.yahoo.document.select.rule.ExpressionNode relational()", - "public final com.yahoo.document.select.rule.ExpressionNode arithmetic()", - "public final com.yahoo.document.select.rule.VariableNode variable()", - "public final com.yahoo.document.select.rule.ExpressionNode attribute()", - "public final com.yahoo.document.select.rule.ExpressionNode value()", - "public final com.yahoo.document.select.rule.DocumentNode document()", - "public final void identifier()", - "public final com.yahoo.document.select.rule.IdNode id()", - "public final com.yahoo.document.select.rule.SearchColumnNode searchColumn()", - "public final com.yahoo.document.select.rule.LiteralNode literal()", - "public void <init>(com.yahoo.document.select.parser.CharStream)", - "public void ReInit(com.yahoo.document.select.parser.CharStream)", - "public void <init>(com.yahoo.document.select.parser.SelectParserTokenManager)", - "public void ReInit(com.yahoo.document.select.parser.SelectParserTokenManager)", - "public final com.yahoo.document.select.parser.Token getNextToken()", - "public final com.yahoo.document.select.parser.Token getToken(int)", - "public com.yahoo.document.select.parser.ParseException generateParseException()", - "public final boolean trace_enabled()", - "public final void enable_tracing()", - "public final void disable_tracing()" - ], - "fields": [ - "public com.yahoo.document.select.parser.SelectParserTokenManager token_source", - "public com.yahoo.document.select.parser.Token token", - "public com.yahoo.document.select.parser.Token jj_nt" - ] - }, - "com.yahoo.document.select.parser.SelectParserConstants": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public", - "interface", - "abstract" - ], - "methods": [], - "fields": [ - "public static final int EOF", - "public static final int INTEGER", - "public static final int DECIMAL", - "public static final int HEX", - "public static final int OCTAL", - "public static final int FLOAT", - "public static final int EXPONENT", - "public static final int LBRACE", - "public static final int RBRACE", - "public static final int ADD", - "public static final int SUB", - "public static final int MUL", - "public static final int DIV", - "public static final int MOD", - "public static final int DOT", - "public static final int COMMA", - "public static final int NE", - "public static final int GE", - "public static final int LE", - "public static final int REGEX", - "public static final int EQ", - "public static final int GLOB", - "public static final int GT", - "public static final int LT", - "public static final int DOLLAR", - "public static final int STRING", - "public static final int ID", - "public static final int SEARCHCOLUMN", - "public static final int ID_SCHEME", - "public static final int ID_TYPE", - "public static final int ID_NAMESPACE", - "public static final int ID_SPECIFIC", - "public static final int ID_USER", - "public static final int ID_GROUP", - "public static final int ID_ORDER", - "public static final int ID_BUCKET", - "public static final int NULL", - "public static final int NOW", - "public static final int TRUE", - "public static final int FALSE", - "public static final int AND", - "public static final int OR", - "public static final int NOT", - "public static final int IDENTIFIER", - "public static final int DEFAULT", - "public static final java.lang.String[] tokenImage" - ] - }, - "com.yahoo.document.select.parser.SelectParserTokenManager": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.parser.SelectParserConstants" - ], - "attributes": [ - "public" - ], - "methods": [ - "protected com.yahoo.document.select.parser.Token jjFillToken()", - "public com.yahoo.document.select.parser.Token getNextToken()", - "public void <init>(com.yahoo.document.select.parser.CharStream)", - "public void <init>(com.yahoo.document.select.parser.CharStream, int)", - "public void ReInit(com.yahoo.document.select.parser.CharStream)", - "public void ReInit(com.yahoo.document.select.parser.CharStream, int)", - "public void SwitchTo(int)" - ], - "fields": [ - "public static final java.lang.String[] jjstrLiteralImages", - "public static final java.lang.String[] lexStateNames", - "public static final int[] jjnewLexState", - "protected com.yahoo.document.select.parser.CharStream input_stream", - "protected int curChar" - ] - }, - "com.yahoo.document.select.parser.SelectParserUtils": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public static long decodeLong(java.lang.String)", - "public static java.lang.String quote(java.lang.String, char)", - "public static java.lang.String unquote(java.lang.String)" - ], - "fields": [] - }, - "com.yahoo.document.select.parser.Token": { - "superClass": "java.lang.Object", - "interfaces": [ - "java.io.Serializable" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public void <init>(int)", - "public void <init>(int, java.lang.String)", - "public java.lang.Object getValue()", - "public java.lang.String toString()", - "public static com.yahoo.document.select.parser.Token newToken(int, java.lang.String)", - "public static com.yahoo.document.select.parser.Token newToken(int)" - ], - "fields": [ - "public int kind", - "public int beginLine", - "public int beginColumn", - "public int endLine", - "public int endColumn", - "public java.lang.String image", - "public com.yahoo.document.select.parser.Token next", - "public com.yahoo.document.select.parser.Token specialToken" - ] - }, - "com.yahoo.document.select.parser.TokenMgrException": { - "superClass": "java.lang.RuntimeException", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "protected static final java.lang.String addEscapes(java.lang.String)", - "protected static java.lang.String LexicalErr(boolean, int, int, int, java.lang.String, int)", - "public java.lang.String getMessage()", - "public void <init>()", - "public void <init>(java.lang.String, int)", - "public void <init>(boolean, int, int, int, java.lang.String, int, int)" - ], - "fields": [ - "public static final int LEXICAL_ERROR", - "public static final int STATIC_LEXER_ERROR", - "public static final int INVALID_LEXICAL_STATE", - "public static final int LOOP_DETECTED" - ] - }, - "com.yahoo.document.select.rule.ArithmeticNode$NodeItem": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(int, com.yahoo.document.select.rule.ExpressionNode)", - "public int getOperator()", - "public com.yahoo.document.select.rule.ExpressionNode getNode()" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.ArithmeticNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public com.yahoo.document.select.rule.ArithmeticNode add(java.lang.String, com.yahoo.document.select.rule.ExpressionNode)", - "public java.util.List getItems()", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public java.lang.String toString()", - "public java.lang.String operatorToString(int)", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)", - "public void accept(com.yahoo.document.select.Visitor)" - ], - "fields": [ - "public static final int NOP", - "public static final int ADD", - "public static final int SUB", - "public static final int MOD", - "public static final int DIV", - "public static final int MUL" - ] - }, - "com.yahoo.document.select.rule.AttributeNode$Item": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(java.lang.String)", - "public java.lang.String getName()", - "public com.yahoo.document.select.rule.AttributeNode$Item setName(java.lang.String)", - "public int getType()", - "public com.yahoo.document.select.rule.AttributeNode$Item setType(int)", - "public java.lang.String toString()" - ], - "fields": [ - "public static final int ATTRIBUTE", - "public static final int FUNCTION" - ] - }, - "com.yahoo.document.select.rule.AttributeNode$VariableValueList": { - "superClass": "java.util.ArrayList", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.AttributeNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(com.yahoo.document.select.rule.ExpressionNode, java.util.List)", - "public com.yahoo.document.select.rule.ExpressionNode getValue()", - "public com.yahoo.document.select.rule.AttributeNode setValue(com.yahoo.document.select.rule.ExpressionNode)", - "public java.util.List getItems()", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.ComparisonNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(com.yahoo.document.select.rule.ExpressionNode, java.lang.String, com.yahoo.document.select.rule.ExpressionNode)", - "public com.yahoo.document.select.rule.ExpressionNode getLHS()", - "public com.yahoo.document.select.rule.ComparisonNode setLHS(com.yahoo.document.select.rule.ExpressionNode)", - "public java.lang.String getOperator()", - "public com.yahoo.document.select.rule.ComparisonNode setOperator(java.lang.String)", - "public com.yahoo.document.select.rule.ExpressionNode getRHS()", - "public com.yahoo.document.select.rule.ComparisonNode setRHS(com.yahoo.document.select.rule.ExpressionNode)", - "public com.yahoo.document.select.OrderingSpecification getOrdering(com.yahoo.document.select.rule.IdNode, com.yahoo.document.select.rule.LiteralNode, java.lang.String, int)", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public com.yahoo.document.select.ResultList evaluateListsTrue(com.yahoo.document.select.rule.AttributeNode$VariableValueList, com.yahoo.document.select.rule.AttributeNode$VariableValueList)", - "public com.yahoo.document.select.ResultList evaluateListsFalse(com.yahoo.document.select.rule.AttributeNode$VariableValueList, com.yahoo.document.select.rule.AttributeNode$VariableValueList)", - "public com.yahoo.document.select.ResultList evaluateListAndSingle(com.yahoo.document.select.rule.AttributeNode$VariableValueList, java.lang.Object)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.DocumentNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(java.lang.String)", - "public java.lang.String getType()", - "public com.yahoo.document.select.rule.DocumentNode setType(java.lang.String)", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public java.lang.Object evaluate(com.yahoo.document.DocumentOperation)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.EmbracedNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(com.yahoo.document.select.rule.ExpressionNode)", - "public com.yahoo.document.select.rule.ExpressionNode getNode()", - "public com.yahoo.document.select.rule.EmbracedNode setNode(com.yahoo.document.select.rule.ExpressionNode)", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public java.lang.String toString()", - "public void accept(com.yahoo.document.select.Visitor)", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.ExpressionNode": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public", - "interface", - "abstract" - ], - "methods": [ - "public abstract java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public abstract com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public abstract com.yahoo.document.select.OrderingSpecification getOrdering(int)", - "public abstract void accept(com.yahoo.document.select.Visitor)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.IdNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public java.lang.String getField()", - "public com.yahoo.document.select.rule.IdNode setField(java.lang.String)", - "public com.yahoo.document.select.rule.IdNode setWidthBits(short)", - "public com.yahoo.document.select.rule.IdNode setDivisionBits(short)", - "public short getWidthBits()", - "public short getDivisionBits()", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.LiteralNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(java.lang.Object)", - "public java.lang.Object getValue()", - "public com.yahoo.document.select.rule.LiteralNode setValue(java.lang.Object)", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.LogicNode$NodeItem": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public", - "final" - ], - "methods": [ - "public void <init>(com.yahoo.document.select.rule.LogicNode, int, com.yahoo.document.select.rule.ExpressionNode)", - "public int getOperator()", - "public com.yahoo.document.select.rule.ExpressionNode getNode()" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.LogicNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public java.util.List getItems()", - "public com.yahoo.document.select.rule.LogicNode add(java.lang.String, com.yahoo.document.select.rule.ExpressionNode)", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()", - "public java.lang.String operatorToString(int)" - ], - "fields": [ - "public static final int NOP", - "public static final int OR", - "public static final int AND" - ] - }, - "com.yahoo.document.select.rule.NegationNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(com.yahoo.document.select.rule.ExpressionNode)", - "public com.yahoo.document.select.rule.ExpressionNode getNode()", - "public com.yahoo.document.select.rule.NegationNode setNode(com.yahoo.document.select.rule.ExpressionNode)", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.NowNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public java.lang.String toString()", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)", - "public void accept(com.yahoo.document.select.Visitor)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.SearchColumnNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public int getField()", - "public com.yahoo.document.select.rule.SearchColumnNode setField(int)", - "public com.yahoo.document.BucketDistribution getDistribution()", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)" - ], - "fields": [] - }, - "com.yahoo.document.select.rule.VariableNode": { - "superClass": "java.lang.Object", - "interfaces": [ - "com.yahoo.document.select.rule.ExpressionNode" - ], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>(java.lang.String)", - "public java.lang.Object getValue()", - "public com.yahoo.document.select.rule.VariableNode setValue(java.lang.String)", - "public com.yahoo.document.select.BucketSet getBucketSet(com.yahoo.document.BucketIdFactory)", - "public java.lang.Object evaluate(com.yahoo.document.select.Context)", - "public void accept(com.yahoo.document.select.Visitor)", - "public java.lang.String toString()", - "public com.yahoo.document.select.OrderingSpecification getOrdering(int)" - ], - "fields": [] - }, - "com.yahoo.document.select.simple.IdSpecParser": { - "superClass": "com.yahoo.document.select.simple.Parser", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public com.yahoo.document.select.rule.IdNode getId()", - "public boolean isUserSpec()", - "public boolean parse(java.lang.CharSequence)" - ], - "fields": [] - }, - "com.yahoo.document.select.simple.IntegerParser": { - "superClass": "com.yahoo.document.select.simple.Parser", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public com.yahoo.document.select.rule.LiteralNode getValue()", - "public boolean parse(java.lang.CharSequence)" - ], - "fields": [] - }, - "com.yahoo.document.select.simple.OperatorParser": { - "superClass": "com.yahoo.document.select.simple.Parser", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public java.lang.String getOperator()", - "public boolean parse(java.lang.CharSequence)" - ], - "fields": [] - }, - "com.yahoo.document.select.simple.Parser": { - "superClass": "java.lang.Object", - "interfaces": [], - "attributes": [ - "public", - "abstract" - ], - "methods": [ - "public void <init>()", - "public abstract boolean parse(java.lang.CharSequence)", - "public java.lang.CharSequence getRemaining()", - "protected void setRemaining(java.lang.CharSequence)", - "protected int eatWhite(java.lang.CharSequence)", - "protected boolean icmp(char, char)" - ], - "fields": [] - }, - "com.yahoo.document.select.simple.SelectionParser": { - "superClass": "com.yahoo.document.select.simple.Parser", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public com.yahoo.document.select.rule.ExpressionNode getNode()", - "public boolean parse(java.lang.CharSequence)" - ], - "fields": [] - }, - "com.yahoo.document.select.simple.StringParser": { - "superClass": "com.yahoo.document.select.simple.Parser", - "interfaces": [], - "attributes": [ - "public" - ], - "methods": [ - "public void <init>()", - "public com.yahoo.document.select.rule.LiteralNode getValue()", - "public boolean parse(java.lang.CharSequence)" - ], - "fields": [] - }, "com.yahoo.document.serialization.AnnotationReader": { "superClass": "java.lang.Object", "interfaces": [], diff --git a/document/src/main/java/com/yahoo/document/select/Context.java b/document/src/main/java/com/yahoo/document/select/Context.java index ac2bb6b9f0d..481131b4776 100644 --- a/document/src/main/java/com/yahoo/document/select/Context.java +++ b/document/src/main/java/com/yahoo/document/select/Context.java @@ -7,7 +7,8 @@ import java.util.HashMap; import java.util.Map; public class Context { - private DocumentOperation documentOperation = null; + private DocumentOperation documentOperation; + private Map<String, Object> variables = new HashMap<>(); public Context(DocumentOperation documentOperation) { this.documentOperation = documentOperation; @@ -28,7 +29,4 @@ public class Context { public void setVariables(Map<String, Object> variables) { this.variables = variables; } - - private Map<String, Object> variables = new HashMap<String, Object>(); - } 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 7f5b92ea233..1ee6ff45c99 100644 --- a/document/src/main/java/com/yahoo/document/select/DocumentSelector.java +++ b/document/src/main/java/com/yahoo/document/select/DocumentSelector.java @@ -84,7 +84,7 @@ public class DocumentSelector { * @return True if the document is accepted. * @throws RuntimeException if the evaluation enters an illegal state */ - public ResultList getMatchingResultList(Context context) { + private ResultList getMatchingResultList(Context context) { return ResultList.toResultList(expression.evaluate(context)); } diff --git a/document/src/main/java/com/yahoo/document/select/NowCheckVisitor.java b/document/src/main/java/com/yahoo/document/select/NowCheckVisitor.java index 5efcdec848a..fd799e36a70 100644 --- a/document/src/main/java/com/yahoo/document/select/NowCheckVisitor.java +++ b/document/src/main/java/com/yahoo/document/select/NowCheckVisitor.java @@ -1,8 +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.select; -import com.yahoo.document.select.Visitor; -import com.yahoo.document.select.rule.*; +import com.yahoo.document.select.rule.ArithmeticNode; +import com.yahoo.document.select.rule.AttributeNode; +import com.yahoo.document.select.rule.ComparisonNode; +import com.yahoo.document.select.rule.DocumentNode; +import com.yahoo.document.select.rule.EmbracedNode; +import com.yahoo.document.select.rule.IdNode; +import com.yahoo.document.select.rule.LiteralNode; +import com.yahoo.document.select.rule.LogicNode; +import com.yahoo.document.select.rule.NegationNode; +import com.yahoo.document.select.rule.NowNode; +import com.yahoo.document.select.rule.SearchColumnNode; +import com.yahoo.document.select.rule.VariableNode; /** * Traverse and check if there exists any now() function in the expression tree. diff --git a/document/src/main/java/com/yahoo/document/select/Result.java b/document/src/main/java/com/yahoo/document/select/Result.java index 784b7fdc7e7..5f057da900c 100644 --- a/document/src/main/java/com/yahoo/document/select/Result.java +++ b/document/src/main/java/com/yahoo/document/select/Result.java @@ -15,7 +15,7 @@ public enum Result { FALSE, INVALID; - // Inherit doc from Object. + @Override public String toString() { return name().toLowerCase(); } @@ -38,7 +38,7 @@ public enum Result { */ public static Result toResult(Object value) { if (value == null || value == Result.FALSE || value == Boolean.FALSE || - (Number.class.isInstance(value) && ((Number)value).doubleValue() == 0)) { + (value instanceof Number && ((Number)value).doubleValue() == 0)) { return Result.FALSE; } else if (value == INVALID) { return Result.INVALID; diff --git a/document/src/main/java/com/yahoo/document/select/ResultList.java b/document/src/main/java/com/yahoo/document/select/ResultList.java index 8d73c475981..edf05eb044e 100644 --- a/document/src/main/java/com/yahoo/document/select/ResultList.java +++ b/document/src/main/java/com/yahoo/document/select/ResultList.java @@ -43,7 +43,7 @@ public class ResultList { } } - List<ResultPair> results = new ArrayList<ResultPair>(); + private List<ResultPair> results = new ArrayList<>(); public ResultList() { } @@ -86,7 +86,7 @@ public class ResultList { } } - boolean combineVariables(FieldPathIteratorHandler.VariableMap output, FieldPathIteratorHandler.VariableMap input) { + private boolean combineVariables(FieldPathIteratorHandler.VariableMap output, FieldPathIteratorHandler.VariableMap input) { // First, verify that all variables are overlapping for (Map.Entry<String, FieldPathIteratorHandler.IndexValue> entry : output.entrySet()) { FieldPathIteratorHandler.IndexValue found = input.get(entry.getKey()); @@ -116,13 +116,19 @@ public class ResultList { return true; } - public ResultList combineAND(ResultList other) + public interface LazyResultList { + ResultList getResult(); + } + + public ResultList combineAND(LazyResultList other) { + if (Result.FALSE == toResult()) return ResultList.toResultList(false); + ResultList result = new ResultList(); // TODO: optimize for (ResultPair pair : results) { - for (ResultPair otherPair : other.results) { + for (ResultPair otherPair : other.getResult().results) { FieldPathIteratorHandler.VariableMap varMap = (FieldPathIteratorHandler.VariableMap)pair.variables.clone(); if (combineVariables(varMap, otherPair.variables)) { @@ -144,13 +150,15 @@ public class ResultList { return Result.INVALID; } - public ResultList combineOR(ResultList other) + public ResultList combineOR(LazyResultList other) { + if (Result.TRUE == toResult()) return ResultList.toResultList(true); + ResultList result = new ResultList(); // TODO: optimize for (ResultPair pair : results) { - for (ResultPair otherPair : other.results) { + for (ResultPair otherPair : other.getResult().results) { FieldPathIteratorHandler.VariableMap varMap = (FieldPathIteratorHandler.VariableMap)pair.variables.clone(); if (combineVariables(varMap, otherPair.variables)) { @@ -188,7 +196,7 @@ public class ResultList { } return retVal; } else if (value == null || value == Result.FALSE || value == Boolean.FALSE || - (Number.class.isInstance(value) && ((Number)value).doubleValue() == 0)) { + (value instanceof Number && ((Number)value).doubleValue() == 0)) { return new ResultList(Result.FALSE); } else if (value == Result.INVALID) { return new ResultList(Result.INVALID); diff --git a/document/src/main/java/com/yahoo/document/select/convert/NowQueryExpression.java b/document/src/main/java/com/yahoo/document/select/convert/NowQueryExpression.java index d379a73aec1..a4ce6afb099 100644 --- a/document/src/main/java/com/yahoo/document/select/convert/NowQueryExpression.java +++ b/document/src/main/java/com/yahoo/document/select/convert/NowQueryExpression.java @@ -16,7 +16,7 @@ public class NowQueryExpression { private final ComparisonNode comparison; private final NowQueryNode now; - public NowQueryExpression(AttributeNode attribute, ComparisonNode comparison, ArithmeticNode arithmetic) { + NowQueryExpression(AttributeNode attribute, ComparisonNode comparison, ArithmeticNode arithmetic) { this.attribute = attribute; this.comparison = comparison; this.now = (arithmetic != null ? new NowQueryNode(arithmetic) : new NowQueryNode(0)); diff --git a/document/src/main/java/com/yahoo/document/select/convert/NowQueryNode.java b/document/src/main/java/com/yahoo/document/select/convert/NowQueryNode.java index 121fa0a45eb..0bd94a3854c 100644 --- a/document/src/main/java/com/yahoo/document/select/convert/NowQueryNode.java +++ b/document/src/main/java/com/yahoo/document/select/convert/NowQueryNode.java @@ -10,10 +10,10 @@ import com.yahoo.document.select.rule.ArithmeticNode; */ public class NowQueryNode { private final long value; - public NowQueryNode(long value) { + NowQueryNode(long value) { this.value = value; } - public NowQueryNode(ArithmeticNode node) { + NowQueryNode(ArithmeticNode node) { // Assumes that the structure is checked and verified earlier this.value = Long.parseLong(node.getItems().get(1).getNode().toString()); } diff --git a/document/src/main/java/com/yahoo/document/select/convert/SelectionExpressionConverter.java b/document/src/main/java/com/yahoo/document/select/convert/SelectionExpressionConverter.java index 46721254b9f..a5708871529 100644 --- a/document/src/main/java/com/yahoo/document/select/convert/SelectionExpressionConverter.java +++ b/document/src/main/java/com/yahoo/document/select/convert/SelectionExpressionConverter.java @@ -3,7 +3,20 @@ package com.yahoo.document.select.convert; import com.yahoo.document.select.NowCheckVisitor; import com.yahoo.document.select.Visitor; -import com.yahoo.document.select.rule.*; +import com.yahoo.document.select.rule.ArithmeticNode; +import com.yahoo.document.select.rule.AttributeNode; +import com.yahoo.document.select.rule.ComparisonNode; +import com.yahoo.document.select.rule.DocumentNode; +import com.yahoo.document.select.rule.EmbracedNode; +import com.yahoo.document.select.rule.ExpressionNode; +import com.yahoo.document.select.rule.IdNode; +import com.yahoo.document.select.rule.LiteralNode; +import com.yahoo.document.select.rule.LogicNode; +import com.yahoo.document.select.rule.NegationNode; +import com.yahoo.document.select.rule.NowNode; +import com.yahoo.document.select.rule.SearchColumnNode; +import com.yahoo.document.select.rule.VariableNode; + import java.util.HashMap; import java.util.Map; @@ -15,14 +28,13 @@ import java.util.Map; */ public class SelectionExpressionConverter implements Visitor { - private Map<String, NowQueryExpression> expressionMap = new HashMap<String, NowQueryExpression>(); + private Map<String, NowQueryExpression> expressionMap = new HashMap<>(); private class BuildState { public AttributeNode attribute; public ComparisonNode comparison; public ArithmeticNode arithmetic; public NowNode now; - public boolean hasNow() { return now != null; } } private BuildState state; @@ -38,7 +50,7 @@ public class SelectionExpressionConverter implements Visitor { } public Map<String, String> getQueryMap() { - Map<String, String> ret = new HashMap<String, String>(); + Map<String, String> ret = new HashMap<>(); for (NowQueryExpression expression : expressionMap.values()) { ret.put(expression.getDocumentType(), expression.toString()); } @@ -92,7 +104,6 @@ public class SelectionExpressionConverter implements Visitor { } state.comparison = node; if (state.attribute != null && - state.comparison != null && (state.arithmetic != null || state.now != null)) { NowQueryExpression expression = new NowQueryExpression(state.attribute, state.comparison, state.arithmetic); expressionMap.put(expression.getDocumentType(), expression); diff --git a/document/src/main/java/com/yahoo/document/select/convert/package-info.java b/document/src/main/java/com/yahoo/document/select/convert/package-info.java index a3cd3c7c55b..aa7276099b0 100644 --- a/document/src/main/java/com/yahoo/document/select/convert/package-info.java +++ b/document/src/main/java/com/yahoo/document/select/convert/package-info.java @@ -1,7 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. @ExportPackage -@PublicApi package com.yahoo.document.select.convert; -import com.yahoo.api.annotations.PublicApi; import com.yahoo.osgi.annotation.ExportPackage; diff --git a/document/src/main/java/com/yahoo/document/select/parser/SelectParserUtils.java b/document/src/main/java/com/yahoo/document/select/parser/SelectParserUtils.java index 6537eefaa7a..2bfed803ea7 100644 --- a/document/src/main/java/com/yahoo/document/select/parser/SelectParserUtils.java +++ b/document/src/main/java/com/yahoo/document/select/parser/SelectParserUtils.java @@ -10,7 +10,7 @@ import java.math.BigInteger; */ public class SelectParserUtils { - public static long decodeLong(String str) { + static long decodeLong(String str) { if (str.startsWith("0x") || str.startsWith("0X")) { str = Long.toString(new BigInteger(str.substring(2), 16).longValue()); } diff --git a/document/src/main/java/com/yahoo/document/select/parser/package-info.java b/document/src/main/java/com/yahoo/document/select/parser/package-info.java index 11cda77e3e4..476f0409c6f 100644 --- a/document/src/main/java/com/yahoo/document/select/parser/package-info.java +++ b/document/src/main/java/com/yahoo/document/select/parser/package-info.java @@ -1,7 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. @ExportPackage -@PublicApi package com.yahoo.document.select.parser; -import com.yahoo.api.annotations.PublicApi; import com.yahoo.osgi.annotation.ExportPackage; 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 813c3b27612..c39bd7e668d 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 @@ -3,7 +3,10 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketIdFactory; import com.yahoo.document.datatypes.NumericFieldValue; -import com.yahoo.document.select.*; +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; import java.util.ArrayList; @@ -21,7 +24,7 @@ public class ArithmeticNode implements ExpressionNode { public static final int DIV = 4; public static final int MUL = 5; - private final List<NodeItem> items = new ArrayList<NodeItem>(); + private final List<NodeItem> items = new ArrayList<>(); public ArithmeticNode() { // empty @@ -36,15 +39,15 @@ public class ArithmeticNode implements ExpressionNode { return items; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { return null; } - // Inherit doc from ExpressionNode. + @Override public Object evaluate(Context context) { StringBuilder ret = null; - Stack<ValueItem> buf = new Stack<ValueItem>(); + Stack<ValueItem> buf = new Stack<>(); for (int i = 0; i < items.size(); ++i) { NodeItem item = items.get(i); Object val = item.node.evaluate(context); @@ -77,7 +80,7 @@ public class ArithmeticNode implements ExpressionNode { ret.append(val); continue; } - } else if (Number.class.isInstance(val)) { + } else if (val instanceof Number) { if (!buf.isEmpty()) { while (buf.peek().operator > item.operator) { popOffTheTop(buf); @@ -171,10 +174,12 @@ public class ArithmeticNode implements ExpressionNode { } } + @Override public OrderingSpecification getOrdering(int order) { return null; } + @Override public void accept(Visitor visitor) { visitor.visit(this); } @@ -183,7 +188,7 @@ public class ArithmeticNode implements ExpressionNode { public int operator; public Number value; - public ValueItem(int operator, Number value) { + ValueItem(int operator, Number value) { this.operator = operator; this.value = value; } @@ -193,7 +198,7 @@ public class ArithmeticNode implements ExpressionNode { private int operator; private ExpressionNode node; - public NodeItem(int operator, ExpressionNode node) { + NodeItem(int operator, ExpressionNode node) { this.operator = operator; this.node = node; } 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 b6d75acd0ea..3e03709d0f1 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 @@ -2,10 +2,21 @@ package com.yahoo.document.select.rule; import com.yahoo.collections.BobHash; -import com.yahoo.document.*; +import com.yahoo.document.BucketIdFactory; +import com.yahoo.document.Document; +import com.yahoo.document.DocumentGet; +import com.yahoo.document.DocumentPut; +import com.yahoo.document.DocumentRemove; +import com.yahoo.document.DocumentUpdate; +import com.yahoo.document.FieldPath; import com.yahoo.document.datatypes.FieldPathIteratorHandler; import com.yahoo.document.datatypes.FieldValue; -import com.yahoo.document.select.*; +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; import java.util.ArrayList; import java.util.List; @@ -16,7 +27,7 @@ import java.util.List; public class AttributeNode implements ExpressionNode { private ExpressionNode value; - private final List<Item> items = new ArrayList<Item>(); + private final List<Item> items = new ArrayList<>(); public AttributeNode(ExpressionNode value, List items) { this.value = value; @@ -43,14 +54,14 @@ public class AttributeNode implements ExpressionNode { return items; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { return null; } - // Inherit doc from ExpressionNode. + @Override public Object evaluate(Context context) { - String pos = value.toString(); + StringBuilder pos = new StringBuilder(value.toString()); Object obj = value.evaluate(context); StringBuilder builder = new StringBuilder(); @@ -74,7 +85,7 @@ public class AttributeNode implements ExpressionNode { obj = evaluateFunction(item.getName(), obj); } - pos = pos + "." + item; + pos.append(".").append(item); } if (builder.length() > 0) { @@ -98,7 +109,7 @@ public class AttributeNode implements ExpressionNode { private static Object applyFunction(String function, Object value) { if (function.equalsIgnoreCase("abs")) { - if (Number.class.isInstance(value)) { + if (value instanceof Number) { Number nValue = (Number)value; if (value instanceof Double) { return nValue.doubleValue() * (nValue.doubleValue() < 0 ? -1 : 1); @@ -157,6 +168,7 @@ public class AttributeNode implements ExpressionNode { return applyFunction(function, value); } + @Override public void accept(Visitor visitor) { visitor.visit(this); } @@ -171,6 +183,7 @@ public class AttributeNode implements ExpressionNode { return ret.toString(); } + @Override public OrderingSpecification getOrdering(int order) { return null; } 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 13a990566e3..a7ab3d62c58 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 @@ -7,9 +7,13 @@ 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.select.*; +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; -import java.util.List; import java.util.regex.Pattern; /** @@ -46,17 +50,6 @@ public class ComparisonNode implements ExpressionNode { } /** - * Sets the left hand side of this comparison. - * - * @param lhs The new left hand side. - * @return This, to allow chaining. - */ - public ComparisonNode setLHS(ExpressionNode lhs) { - this.lhs = lhs; - return this; - } - - /** * Returns the comparison operator of this. * * @return The operator. @@ -85,17 +78,6 @@ public class ComparisonNode implements ExpressionNode { return rhs; } - /** - * Sets the right hand side of this comparison. - * - * @param rhs The new right hand side. - * @return This, to allow chaining. - */ - public ComparisonNode setRHS(ExpressionNode rhs) { - this.rhs = rhs; - return this; - } - public OrderingSpecification getOrdering(IdNode lhs, LiteralNode rhs, String operator, int order) { if (lhs.getWidthBits() == -1 || lhs.getDivisionBits() == -1 || !(rhs.getValue() instanceof Long)) { return null; @@ -126,17 +108,18 @@ public class ComparisonNode implements ExpressionNode { 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)rhs, operator, order); + return getOrdering((IdNode)rhs, (LiteralNode)lhs, operator, order); } return null; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { if (operator.equals("==") || operator.equals("=")) { if (lhs instanceof IdNode && rhs instanceof LiteralNode) { @@ -144,9 +127,9 @@ public class ComparisonNode implements ExpressionNode { } else if (rhs instanceof IdNode && lhs instanceof LiteralNode) { return compare(factory, (IdNode)rhs, (LiteralNode)lhs, operator); } else if (lhs instanceof SearchColumnNode && rhs instanceof LiteralNode) { - return compare(factory, (SearchColumnNode)lhs, (LiteralNode)rhs); + return compare((SearchColumnNode)lhs, (LiteralNode)rhs); } else if (rhs instanceof SearchColumnNode && lhs instanceof LiteralNode) { - return compare(factory, (SearchColumnNode)rhs, (LiteralNode)lhs); + return compare((SearchColumnNode)rhs, (LiteralNode)lhs); } } return null; @@ -155,12 +138,11 @@ public class ComparisonNode implements ExpressionNode { /** * Compares a search column node with a literal node. * - * @param factory The bucket id factory used. * @param node The search column node. * @param literal The literal node to compare to. * @return The bucket set containing the buckets covered. */ - private BucketSet compare(BucketIdFactory factory, SearchColumnNode node, LiteralNode literal) { + private BucketSet compare(SearchColumnNode node, LiteralNode literal) { Object value = literal.getValue(); int bucketCount = (int) Math.pow(2, 16); if (value instanceof Long) { @@ -211,7 +193,7 @@ public class ComparisonNode implements ExpressionNode { return null; } - // Inherit doc from Node. + @Override public Object evaluate(Context context) { Object oLeft = lhs.evaluate(context); Object oRight = rhs.evaluate(context); @@ -254,7 +236,7 @@ public class ComparisonNode implements ExpressionNode { } } - public ResultList evaluateListsTrue(AttributeNode.VariableValueList lhs, AttributeNode.VariableValueList rhs) { + private ResultList evaluateListsTrue(AttributeNode.VariableValueList lhs, AttributeNode.VariableValueList rhs) { if (lhs.size() != rhs.size()) { return new ResultList(Result.FALSE); } @@ -272,7 +254,7 @@ public class ComparisonNode implements ExpressionNode { return new ResultList(Result.TRUE); } - public ResultList evaluateListsFalse(AttributeNode.VariableValueList lhs, AttributeNode.VariableValueList rhs) { + private ResultList evaluateListsFalse(AttributeNode.VariableValueList lhs, AttributeNode.VariableValueList rhs) { ResultList lst = evaluateListsTrue(lhs, rhs); if (lst.toResult() == Result.TRUE) { return new ResultList(Result.FALSE); @@ -283,7 +265,7 @@ public class ComparisonNode implements ExpressionNode { } } - public ResultList evaluateListAndSingle(AttributeNode.VariableValueList lhs, Object rhs) { + private ResultList evaluateListAndSingle(AttributeNode.VariableValueList lhs, Object rhs) { if (rhs == null && lhs == null) { return new ResultList(Result.TRUE); } @@ -293,9 +275,9 @@ public class ComparisonNode implements ExpressionNode { } ResultList retVal = new ResultList(); - for (int i = 0; i < lhs.size(); i++) { - Result result = evaluateBool(lhs.get(i).getValue(), rhs); - retVal.add((FieldPathIteratorHandler.VariableMap)lhs.get(i).getVariables().clone(), result); + for (ResultList.VariableValue value : lhs) { + Result result = evaluateBool(value.getValue(), rhs); + retVal.add((FieldPathIteratorHandler.VariableMap)value.getVariables().clone(), result); } return retVal; @@ -440,11 +422,11 @@ public class ComparisonNode implements ExpressionNode { } } + @Override public void accept(Visitor visitor) { visitor.visit(this); } - // Inherit doc from Object. @Override public String toString() { return lhs + " " + operator + " " + rhs; 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 c0907693dab..9b766a56eb3 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 @@ -1,7 +1,13 @@ // 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.rule; -import com.yahoo.document.*; +import com.yahoo.document.BucketIdFactory; +import com.yahoo.document.DocumentGet; +import com.yahoo.document.DocumentOperation; +import com.yahoo.document.DocumentPut; +import com.yahoo.document.DocumentRemove; +import com.yahoo.document.DocumentType; +import com.yahoo.document.DocumentUpdate; import com.yahoo.document.select.BucketSet; import com.yahoo.document.select.Context; import com.yahoo.document.select.OrderingSpecification; 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 e1bd4b2d53f..7bf3413bafb 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 @@ -27,11 +27,12 @@ public class EmbracedNode implements ExpressionNode { return this; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { return node.getBucketSet(factory); } + @Override public Object evaluate(Context context) { return node.evaluate(context); } @@ -41,10 +42,12 @@ public class EmbracedNode implements ExpressionNode { return "(" + node + ")"; } + @Override public void accept(Visitor visitor) { 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 29f49c4459c..9350b8ac1c5 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 @@ -21,14 +21,14 @@ public interface ExpressionNode { * @param doc The document to evaluate over. * @return The value of this. */ - public Object evaluate(Context doc); + Object evaluate(Context doc); /** * Returns the set of bucket ids covered by this node. * * @param factory The factory used by the current application. */ - public BucketSet getBucketSet(BucketIdFactory factory); + BucketSet getBucketSet(BucketIdFactory factory); /** * If this document selection implies a specific ordering (using the orderdoc scheme), @@ -36,13 +36,13 @@ public interface ExpressionNode { * * @param order The order in which we are looking to traverse the ordering (ASCENDING or DESCENDING) */ - public OrderingSpecification getOrdering(int order); + OrderingSpecification getOrdering(int order); /** * Perform visitation of this node. * * @param visitor The visitor that wishes to visit the node. */ - public void accept(Visitor visitor); + void accept(Visitor visitor); } 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 3c15a2866cc..3ca53c1d07d 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,8 +3,11 @@ package com.yahoo.document.select.rule; import com.yahoo.document.DocumentId; import com.yahoo.document.BucketIdFactory; -import com.yahoo.document.select.*; -import com.yahoo.document.idstring.*; +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; /** * @author Simon Thoresen Hult @@ -46,7 +49,7 @@ public class IdNode implements ExpressionNode { return divisionBits; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { return null; } @@ -55,7 +58,7 @@ public class IdNode implements ExpressionNode { return null; } - // Inherit doc from ExpressionNode. + @Override public Object evaluate(Context context) { DocumentId id = context.getDocumentOperation().getId(); if (id == null) { @@ -97,6 +100,7 @@ public class IdNode implements ExpressionNode { return null; } + @Override public void accept(Visitor visitor) { visitor.visit(this); } 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 a7b112fac70..1ae397398b3 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 @@ -30,7 +30,7 @@ public class LogicNode implements ExpressionNode { public static final int AND = 2; // The items contained in this. - private final List<NodeItem> items = new ArrayList<NodeItem>(); + private final List<NodeItem> items = new ArrayList<>(); /** * Construct an empty logic expression. @@ -55,7 +55,7 @@ public class LogicNode implements ExpressionNode { return this; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { Stack<BucketItem> buf = new Stack<>(); for (NodeItem item : items) { @@ -72,6 +72,7 @@ public class LogicNode implements ExpressionNode { return buf.pop().buckets; } + @Override public OrderingSpecification getOrdering(int order) { Stack<OrderingItem> buf = new Stack<>(); for (NodeItem item : items) { @@ -159,23 +160,21 @@ public class LogicNode implements ExpressionNode { buf.push(lhs); } - // Inherit doc from ExpressionNode. @Override public Object evaluate(Context context) { Stack<ValueItem> buf = new Stack<>(); for (NodeItem item : items) { - if ( ! buf.isEmpty()) { - while (buf.peek().operator > item.operator) { + if ( buf.size() > 1) { + while ((buf.peek().getOperator() >= item.operator)) { combineValues(buf); } } - - buf.push(new ValueItem(item.operator, ResultList.toResultList(item.node.evaluate(context)))); + buf.push(new LazyValueItem(item, context)); } while (buf.size() > 1) { combineValues(buf); } - return buf.pop().value; + return buf.pop().getResult(); } /** @@ -186,24 +185,14 @@ public class LogicNode implements ExpressionNode { private void combineValues(Stack<ValueItem> buf) { ValueItem rhs = buf.pop(); ValueItem lhs = buf.pop(); - - switch (rhs.operator) { - case AND: - buf.push(new ValueItem(lhs.operator, lhs.value.combineAND(rhs.value))); - break; - case OR: - buf.push(new ValueItem(lhs.operator, lhs.value.combineOR(rhs.value))); - break; - default: - throw new IllegalStateException("Arithmetic operator " + rhs.operator + " not supported."); - } + buf.push(new LazyCombinedItem(lhs, rhs)); } + @Override public void accept(Visitor visitor) { visitor.visit(this); } - // Inherit doc from Object. @Override public String toString() { StringBuilder ret = new StringBuilder(); @@ -222,7 +211,7 @@ public class LogicNode implements ExpressionNode { * @param operator The operator index to convert. * @return The string representation. */ - public String operatorToString(int operator) { + private String operatorToString(int operator) { switch (operator) { case NOP: return null; @@ -257,13 +246,58 @@ public class LogicNode implements ExpressionNode { /** * Private class to store results in a stack. */ - private final class ValueItem { - private int operator; - private ResultList value; - - public ValueItem(int operator, ResultList value) { + private abstract class ValueItem implements ResultList.LazyResultList { + private final int operator; + ValueItem(int operator) { this.operator = operator; - this.value = value; + } + int getOperator() { return operator; } + } + + private final class LazyValueItem extends ValueItem { + private final NodeItem item; + private final Context context; + private ResultList lazyResult = null; + + LazyValueItem(NodeItem item, Context context) { + super(item.operator); + this.item = item; + this.context = context; + } + @Override + public ResultList getResult() { + if (lazyResult == null) { + lazyResult = ResultList.toResultList(item.node.evaluate(context)); + } + return lazyResult; + } + } + + private final class LazyCombinedItem extends ValueItem { + private final ValueItem lhs; + private final ValueItem rhs; + private ResultList lazyResult = null; + + LazyCombinedItem(ValueItem lhs, ValueItem rhs) { + super(lhs.getOperator()); + this.lhs = lhs; + this.rhs = rhs; + } + @Override + public ResultList getResult() { + if (lazyResult == null) { + switch (rhs.getOperator()) { + case AND: + lazyResult = lhs.getResult().combineAND(rhs); + break; + case OR: + lazyResult = lhs.getResult().combineOR(rhs); + break; + default: + throw new IllegalStateException("Logical operator " + rhs.getOperator() + " not supported."); + } + } + return lazyResult; } } @@ -274,7 +308,7 @@ public class LogicNode implements ExpressionNode { private int operator; private BucketSet buckets; - public BucketItem(int operator, BucketSet buckets) { + BucketItem(int operator, BucketSet buckets) { this.operator = operator; this.buckets = buckets; } @@ -287,7 +321,7 @@ public class LogicNode implements ExpressionNode { private int operator; private OrderingSpecification ordering; - public OrderingItem(int operator, OrderingSpecification orderSpec) { + OrderingItem(int operator, OrderingSpecification orderSpec) { this.operator = operator; this.ordering = orderSpec; } @@ -300,7 +334,7 @@ public class LogicNode implements ExpressionNode { private int operator; private ExpressionNode node; - public NodeItem(int operator, ExpressionNode node) { + NodeItem(int operator, ExpressionNode node) { this.operator = operator; this.node = 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 c89759bbf07..ba75b13747d 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 @@ -28,16 +28,17 @@ public class NegationNode implements ExpressionNode { return this; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { return null; } - // Inherit doc from ExpressionNode. + @Override public Object evaluate(Context context) { return Result.invert(Result.toResult(node.evaluate(context))); } + @Override public void accept(Visitor visitor) { visitor.visit(this); } @@ -47,6 +48,7 @@ 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 900423addff..567d9ddcb1f 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 @@ -1,22 +1,25 @@ // 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.rule; + import com.yahoo.document.BucketIdFactory; -import com.yahoo.document.select.*; +import com.yahoo.document.select.BucketSet; +import com.yahoo.document.select.Context; +import com.yahoo.document.select.OrderingSpecification; +import com.yahoo.document.select.Visitor; /** * @author Ulf Lilleengen */ public class NowNode implements ExpressionNode { - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { return null; } - // Inherit doc from ExpressionNode. + @Override public Object evaluate(Context context) { - Object ret = System.currentTimeMillis() / 1000; - return ret; + return System.currentTimeMillis() / 1000; } @Override @@ -24,10 +27,11 @@ public class NowNode implements ExpressionNode { return "now()"; } + @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/SearchColumnNode.java b/document/src/main/java/com/yahoo/document/select/rule/SearchColumnNode.java index ffcf576dcfc..071e51c192f 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/SearchColumnNode.java +++ b/document/src/main/java/com/yahoo/document/select/rule/SearchColumnNode.java @@ -3,7 +3,10 @@ package com.yahoo.document.select.rule; import com.yahoo.document.BucketDistribution; import com.yahoo.document.BucketIdFactory; -import com.yahoo.document.select.*; +import com.yahoo.document.select.BucketSet; +import com.yahoo.document.select.Context; +import com.yahoo.document.select.OrderingSpecification; +import com.yahoo.document.select.Visitor; /** * @author Simon Thoresen Hult @@ -31,16 +34,17 @@ public class SearchColumnNode implements ExpressionNode { return distribution; } - // Inherit doc from ExpressionNode. + @Override public BucketSet getBucketSet(BucketIdFactory factory) { return null; } - // Inherit doc from ExpressionNode. + @Override public Object evaluate(Context context) { return distribution.getColumn(factory.getBucketId(context.getDocumentOperation().getId())); } + @Override public void accept(Visitor visitor) { visitor.visit(this); } @@ -50,6 +54,7 @@ public class SearchColumnNode implements ExpressionNode { return "searchcolumn." + field; } + @Override public OrderingSpecification getOrdering(int order) { return null; } diff --git a/document/src/main/java/com/yahoo/document/select/rule/package-info.java b/document/src/main/java/com/yahoo/document/select/rule/package-info.java index 0b80dd5f25d..6c643397264 100644 --- a/document/src/main/java/com/yahoo/document/select/rule/package-info.java +++ b/document/src/main/java/com/yahoo/document/select/rule/package-info.java @@ -1,7 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. @ExportPackage -@PublicApi package com.yahoo.document.select.rule; -import com.yahoo.api.annotations.PublicApi; import com.yahoo.osgi.annotation.ExportPackage; diff --git a/document/src/main/java/com/yahoo/document/select/simple/IdSpecParser.java b/document/src/main/java/com/yahoo/document/select/simple/IdSpecParser.java index f792c4b8c0f..db4d46e871b 100644 --- a/document/src/main/java/com/yahoo/document/select/simple/IdSpecParser.java +++ b/document/src/main/java/com/yahoo/document/select/simple/IdSpecParser.java @@ -9,7 +9,7 @@ import com.yahoo.document.select.rule.IdNode; public class IdSpecParser extends Parser { private IdNode id; public IdNode getId() { return id; } - public boolean isUserSpec() { return "user".equals(id.getField()); } + boolean isUserSpec() { return "user".equals(id.getField()); } public boolean parse(CharSequence s) { boolean retval = false; int pos = eatWhite(s); diff --git a/document/src/main/java/com/yahoo/document/select/simple/StringParser.java b/document/src/main/java/com/yahoo/document/select/simple/StringParser.java index d43c57aee03..50d4915e360 100644 --- a/document/src/main/java/com/yahoo/document/select/simple/StringParser.java +++ b/document/src/main/java/com/yahoo/document/select/simple/StringParser.java @@ -14,7 +14,7 @@ public class StringParser extends Parser { int pos = eatWhite(s); if (pos + 1 < s.length()) { if (s.charAt(pos++) == '"') { - StringBuffer str = new StringBuffer(""); + StringBuilder str = new StringBuilder(); for(; (pos < s.length()) && (s.charAt(pos) != '"');pos++) { if ((pos < s.length()) && (s.charAt(pos) == '\\')) { pos++; diff --git a/document/src/main/java/com/yahoo/document/select/simple/package-info.java b/document/src/main/java/com/yahoo/document/select/simple/package-info.java index e6885d54fd4..936d63a7697 100644 --- a/document/src/main/java/com/yahoo/document/select/simple/package-info.java +++ b/document/src/main/java/com/yahoo/document/select/simple/package-info.java @@ -1,7 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. @ExportPackage -@PublicApi package com.yahoo.document.select.simple; -import com.yahoo.api.annotations.PublicApi; import com.yahoo.osgi.annotation.ExportPackage; diff --git a/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java new file mode 100644 index 00000000000..25aca22b108 --- /dev/null +++ b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java @@ -0,0 +1,126 @@ +package com.yahoo.document.select; + +import com.yahoo.document.BucketIdFactory; +import com.yahoo.document.select.rule.ExpressionNode; +import com.yahoo.document.select.rule.LiteralNode; +import com.yahoo.document.select.rule.LogicNode; +import org.junit.Test; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LogicalNodeTestCase { + private static class TracedNode implements ExpressionNode { + private final AtomicInteger evalOrder; + private final ExpressionNode node; + private int evaluatedAs = -1; + + TracedNode(AtomicInteger evalOrder, ExpressionNode node) { + this.evalOrder = evalOrder; + this.node = node; + } + @Override + public Object evaluate(Context doc) { + evaluatedAs = evalOrder.getAndIncrement(); + return node.evaluate(doc); + } + + @Override + public BucketSet getBucketSet(BucketIdFactory factory) { + return node.getBucketSet(factory); + } + + @Override + public OrderingSpecification getOrdering(int order) { + return node.getOrdering(order); + } + + @Override + public void accept(Visitor visitor) { + node.accept(visitor); + } + boolean isEvaluated() { return evaluatedAs >= 0; } + int getEvalOrder() { return evaluatedAs; } + } + private static Result evaluate(ExpressionNode node) { + return ((ResultList)node.evaluate(new Context(null))).toResult(); + } + + private static TracedNode createTraced(AtomicInteger evalOrder, char node) { + return new TracedNode(evalOrder, new LiteralNode(node == 'T')); + } + + private static void addOperator(LogicNode logical, char operator, ExpressionNode node) { + if (operator == '&') { + logical.add("and", node); + } else if (operator == '|') { + logical.add("or", node); + } else { + throw new IllegalArgumentException("Bad operator '" + operator + "'"); + } + } + + static private void verifyEvaluationOrder(String expr, boolean expectedResult, List<Integer> expectedEvaluationOrder ) { + assertEquals(1, expr.length()%2); + assertEquals(expectedEvaluationOrder.size()*2 - 1, expr.length()); + TracedNode [] traced = new TracedNode[expectedEvaluationOrder.size()]; + AtomicInteger evalOrder = new AtomicInteger(0); + for (int i=0; i < traced.length; i++) { + traced[i] = createTraced(evalOrder, expr.charAt(i*2)); + } + LogicNode logical = new LogicNode().add(null, traced[0]); + for (int i=1; i < traced.length; i++) { + addOperator(logical, expr.charAt(i*2-1), traced[i]); + } + for (TracedNode node : traced) { + assertFalse(node.isEvaluated()); + } + assertEquals(Result.toResult(expectedResult), evaluate(logical)); + for (int i = 0; i < traced.length; i++) { + assertEquals(expectedEvaluationOrder.get(i).intValue(), traced[i].getEvalOrder()); + } + } + @Test + public void testFullyExhaustedAND() { + verifyEvaluationOrder("T&T", true, List.of(0,1)); + + } + @Test + public void testShortCircuitAND() { + verifyEvaluationOrder("F&T", false, List.of(0,-1)); + } + + @Test + public void testFullyExhaustedOR() { + verifyEvaluationOrder("F|T", true, List.of(0,1)); + } + + @Test + public void testShortCircuitOR() { + verifyEvaluationOrder("T|F", true, List.of(0,-1)); + } + + @Test + public void testLeft2Right() { + verifyEvaluationOrder("T&T&T&T&T", true, List.of(0,1,2,3,4)); + verifyEvaluationOrder("T&T&F&T&F", false, List.of(0,1,2,-1,-1)); + + verifyEvaluationOrder("F|F|F|F|T", true, List.of(0,1,2,3,4)); + verifyEvaluationOrder("F|F|F|F|F", false, List.of(0,1,2,3,4)); + verifyEvaluationOrder("F|F|T|F|T", true, List.of(0,1,2,-1,-1)); + } + + @Test + public void testLeft2RightWithPriority() { + verifyEvaluationOrder("T&F|T", true, List.of(0,1,2)); + verifyEvaluationOrder("F&T|T", true, List.of(0,-1,1)); + + verifyEvaluationOrder("T|F&T", true, List.of(0,-1,-1)); + verifyEvaluationOrder("F|F&T", false, List.of(0,1,-1)); + verifyEvaluationOrder("F|T&T", true, List.of(0,1,2)); + } +} diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestCase.java index fd5f43c23c1..cb32ce75e03 100755 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestCase.java @@ -47,6 +47,7 @@ import com.yahoo.messagebus.routing.RoutingSpec; import com.yahoo.messagebus.routing.RoutingTableSpec; import com.yahoo.messagebus.test.Receptor; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import java.util.ArrayList; @@ -60,7 +61,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -68,7 +69,6 @@ import static org.junit.Assert.assertTrue; /** * @author Simon Thoresen Hult */ -@SuppressWarnings("deprecation") public class PolicyTestCase { private static final int TIMEOUT = 300; @@ -313,7 +313,7 @@ public class PolicyTestCase { for (int i = 0; i < 10; ++i) { RoutingNode leaf = frame.select(1).get(0); String recipient = leaf.getRoute().toString(); - assertTrue(recipient.equals("docproc/cluster.default/*/chain.default")); + assertEquals(recipient, "docproc/cluster.default/*/chain.default"); lst.add(recipient); leaf.handleReply(new EmptyReply()); @@ -496,7 +496,7 @@ public class PolicyTestCase { if (prev == null) { assertNotNull(next); } else { - assertFalse(prev.equals(next)); + assertNotEquals(prev, next); } prev = next; leaf.handleReply(new EmptyReply()); @@ -612,6 +612,32 @@ public class PolicyTestCase { frame.destroy(); } + @Test + public void testDocumentSelectorDualCluster() { + PolicyTestFrame frame = new PolicyTestFrame(manager); + frame.setHop(new HopSpec("test", "[DocumentRouteSelector:raw:" + + "route[2]\n" + + "route[0].name \"foo\"\n" + + "route[0].selector \"(testdoc AND (testdoc.intfield / 1000 > 0))\"\n" + + "route[0].feed \"myfeed\"\n" + + "route[1].name \"bar\"\n" + + "route[1].selector \"(other AND (other.intfield / 1000 > 0))\"\n" + + "route[1].feed \"myfeed\"\n]").addRecipient("foo").addRecipient("bar")); + + frame.setMessage(new GetDocumentMessage(new DocumentId("doc:scheme:"), "fieldSet")); + frame.assertSelect(Arrays.asList("bar", "foo")); + + Document doc = new Document(manager.getDocumentType("testdoc"), new DocumentId("doc:scheme:")); + doc.setFieldValue("intfield", 3000); + Message put = new PutDocumentMessage(new DocumentPut(doc)); + frame.setMessage(put); + frame.assertSelect(Arrays.asList("foo")); + + frame.setMessage(put); + frame.assertMergeOneReply("foo"); + + frame.destroy(); + } @Test public void testDocumentRouteSelectorIgnore() { @@ -676,7 +702,7 @@ public class PolicyTestCase { assertSelect(frame, 32, Arrays.asList("docproc/cluster.default/9/chain.default")); frame.getNetwork().unregisterSession("9/chain.default"); assertTrue(frame.waitSlobrok("docproc/cluster.default/*/chain.default", 7)); - assertSelect(frame, 32, new ArrayList<String>()); + assertSelect(frame, 32, new ArrayList<>()); // Test merge behavior. frame.setHop(new HopSpec("test", "[RoundRobin]").addRecipient("docproc/cluster.default/0/chain.default")); |