EAGLE-1079 - Fix checkstyle issues in antlr module
fix checkstyle in eagle-antlr module
https://issues.apache.org/jira/browse/EAGLE-1079
Author: @coheigea coheigea@apache.org
Reviewer: @yonzhang2012 yonzhang2012@apache.org
Closes #982
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ANDExpression.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ANDExpression.java
index f575e0f..7136343 100644
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ANDExpression.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ANDExpression.java
@@ -20,14 +20,14 @@
import java.util.List;
public class ANDExpression {
- // TODO use Set data structure to dedupe for optimization?
- private List<AtomicExpression> atomicExpressionList = new ArrayList<AtomicExpression>();
+ // TODO use Set data structure to dedupe for optimization?
+ private List<AtomicExpression> atomicExpressionList = new ArrayList<AtomicExpression>();
- public List<AtomicExpression> getAtomicExprList() {
- return atomicExpressionList;
- }
+ public List<AtomicExpression> getAtomicExprList() {
+ return atomicExpressionList;
+ }
- public void setAtomicExprList(List<AtomicExpression> list) {
- this.atomicExpressionList = list;
- }
+ public void setAtomicExprList(List<AtomicExpression> list) {
+ this.atomicExpressionList = list;
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/AtomicExpression.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/AtomicExpression.java
index f831ede..391755c 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/AtomicExpression.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/AtomicExpression.java
@@ -17,51 +17,57 @@
package org.apache.eagle.query.parser;
public class AtomicExpression {
- private String key;
- private ComparisonOperator op;
- private String value;
- private TokenType keyType;
- private TokenType valueType;
+ private String key;
+ private ComparisonOperator op;
+ private String value;
+ private TokenType keyType;
+ private TokenType valueType;
- public String getKey() {
- return key;
- }
- public void setKey(String key) {
- this.key = key;
- }
- public ComparisonOperator getOp() {
- return op;
- }
- public void setOp(ComparisonOperator op) {
- this.op = op;
- }
- public String getValue() {
- return value;
- }
- public void setValue(String value) {
- this.value = value;
- }
- public String toString(){
- if(this.valueType == TokenType.STRING){
- return key + op + "\"" + value + "\"";
- }else{
- return key + op + value;
- }
- }
+ public String getKey() {
+ return key;
+ }
- public TokenType getKeyType() {
- return keyType;
- }
+ public void setKey(String key) {
+ this.key = key;
+ }
- public void setKeyType(TokenType keyType) {
- this.keyType = keyType;
- }
-
- public TokenType getValueType() {
- return valueType;
- }
+ public ComparisonOperator getOp() {
+ return op;
+ }
- public void setValueType(TokenType type) {
- this.valueType = type;
- }
+ public void setOp(ComparisonOperator op) {
+ this.op = op;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String toString() {
+ if (this.valueType == TokenType.STRING) {
+ return key + op + "\"" + value + "\"";
+ } else {
+ return key + op + value;
+ }
+ }
+
+ public TokenType getKeyType() {
+ return keyType;
+ }
+
+ public void setKeyType(TokenType keyType) {
+ this.keyType = keyType;
+ }
+
+ public TokenType getValueType() {
+ return valueType;
+ }
+
+ public void setValueType(TokenType type) {
+ this.valueType = type;
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ComparisonOperator.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ComparisonOperator.java
index 3a1be37..e789fa8 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ComparisonOperator.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ComparisonOperator.java
@@ -17,39 +17,39 @@
package org.apache.eagle.query.parser;
public enum ComparisonOperator {
- EQUAL("="),
- LIKE("=~"),
- IN("IN"),
- NOT_IN("NOT IN"),
- LESS("<"),
- LESS_OR_EQUAL("<="),
- GREATER(">"),
- GREATER_OR_EQUAL(">="),
- NOT_EQUAL("!="),
- NOT_LIKE("!=~"),
- CONTAINS("CONTAINS"),
- NOT_CONTAINS("NOT CONTAINS"),
- IS("IS"),
- IS_NOT("IS NOT");
+ EQUAL("="),
+ LIKE("=~"),
+ IN("IN"),
+ NOT_IN("NOT IN"),
+ LESS("<"),
+ LESS_OR_EQUAL("<="),
+ GREATER(">"),
+ GREATER_OR_EQUAL(">="),
+ NOT_EQUAL("!="),
+ NOT_LIKE("!=~"),
+ CONTAINS("CONTAINS"),
+ NOT_CONTAINS("NOT CONTAINS"),
+ IS("IS"),
+ IS_NOT("IS NOT");
- private final String _op;
- private ComparisonOperator(String op){
- _op = op;
- }
-
- public String toString(){
- return _op;
- }
-
- public static ComparisonOperator locateOperator(String op){
- op = op.replaceAll("\\s+"," ");
- for(ComparisonOperator o : ComparisonOperator.values()){
- if(op.toUpperCase().equals(o._op)){
- return o;
- }
- }
- throw new UnsupportedExpressionOperatorException(op);
- }
+ private final String storedOp;
+ private ComparisonOperator(String op) {
+ storedOp = op;
+ }
+
+ public String toString() {
+ return storedOp;
+ }
+
+ public static ComparisonOperator locateOperator(String op) {
+ op = op.replaceAll("\\s+"," ");
+ for (ComparisonOperator o : ComparisonOperator.values()) {
+ if (op.toUpperCase().equals(o.storedOp)) {
+ return o;
+ }
+ }
+ throw new UnsupportedExpressionOperatorException(op);
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleANTLRErrorStrategy.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleANTLRErrorStrategy.java
index e016ea9..f06ff57 100644
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleANTLRErrorStrategy.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleANTLRErrorStrategy.java
@@ -19,30 +19,29 @@
import org.antlr.v4.runtime.*;
public class EagleANTLRErrorStrategy extends DefaultErrorStrategy {
- /** Instead of recovering from exception {@code e}, re-throw it wrapped
- * in a {@link org.antlr.v4.runtime.misc.ParseCancellationException} so it is not caught by the
- * rule function catches. Use {@link Exception#getCause()} to get the
- * original {@link org.antlr.v4.runtime.RecognitionException}.
- */
- @Override
- public void recover(Parser recognizer, RecognitionException e) {
- for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
- context.exception = e;
- }
- super.recover(recognizer,e);
- }
+ /** Instead of recovering from exception {@code e}, re-throw it wrapped
+ * in a {@link org.antlr.v4.runtime.misc.ParseCancellationException} so it is not caught by the
+ * rule function catches. Use {@link Exception#getCause()} to get the
+ * original {@link org.antlr.v4.runtime.RecognitionException}.
+ */
+ @Override
+ public void recover(Parser recognizer, RecognitionException e) {
+ for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
+ context.exception = e;
+ }
+ super.recover(recognizer,e);
+ }
- /** Make sure we don't attempt to recover inline; if the parser
- * successfully recovers, it won't throw an exception.
- */
- @Override
- public Token recoverInline(Parser recognizer)
- throws RecognitionException
- {
- InputMismatchException e = new InputMismatchException(recognizer);
- for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
- context.exception = e;
- }
- return super.recoverInline(recognizer);
- }
+ /** Make sure we don't attempt to recover inline; if the parser
+ * successfully recovers, it won't throw an exception.
+ */
+ @Override
+ public Token recoverInline(Parser recognizer)
+ throws RecognitionException {
+ InputMismatchException e = new InputMismatchException(recognizer);
+ for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
+ context.exception = e;
+ }
+ return super.recoverInline(recognizer);
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryFilterListenerImpl.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryFilterListenerImpl.java
index a631e53..23fa3d5 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryFilterListenerImpl.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryFilterListenerImpl.java
@@ -29,148 +29,162 @@
import java.util.Stack;
import java.util.regex.Matcher;
-public class EagleQueryFilterListenerImpl implements EagleFilterListener{
- private final static Logger LOG = LoggerFactory.getLogger(EagleQueryFilterListenerImpl.class);
- private Stack<ORExpression> _stack = new Stack<ORExpression>();
-
- public ORExpression result(){
- return _stack.pop();
- }
-
- public void enterEquation(EagleFilterParser.EquationContext ctx){
- }
-
- public void exitEquation(EagleFilterParser.EquationContext ctx){
- TerminalNode id = ctx.ID();
- TerminalNode op = ctx.OP();
- List<TerminalNode> values = ctx.VALUE();
- TerminalNode value = values.get(0);
+public class EagleQueryFilterListenerImpl implements EagleFilterListener {
+ private static final Logger LOG = LoggerFactory.getLogger(EagleQueryFilterListenerImpl.class);
+ private Stack<ORExpression> stack = new Stack<ORExpression>();
- if(values.size() == 2){
- // value op value
- id = values.get(0);
- value = values.get(1);
- }
-
- if(LOG.isDebugEnabled()) LOG.debug("ID:" + id.getText() + ", OP:" + op.getText() + ", VALUE:" + value);
-
- AtomicExpression kv = new AtomicExpression();
- kv.setKey(id.getText());
- kv.setOp(ComparisonOperator.locateOperator(op.getText()));
-
- try{
- kv.setValueType(TokenType.locate(value.getText()));
- }catch (Exception ex){
- LOG.error("Failed to locate value type for: " + value.getText() + " due to exception: " + ex.getMessage(), ex);
- }
-
- try{
- kv.setKeyType(TokenType.locate(id.getText()));
- }catch (Exception ex){
- LOG.error("Failed to locate id type for: " + id.getText() + " due to exception: " + ex.getMessage(), ex);
- }
-
-// if(id != null){
- kv.setKey(postProcessNode(id.getText(),kv.getKeyType()));
-// }
-
-// if(value != null){
- kv.setValue(postProcessNode(value.getText(),kv.getValueType()));
- // As to List value, it will escape in List parser but not here
- if(kv.getValueType() != TokenType.LIST) kv.setValue(StringEscapeUtils.unescapeJava(kv.getValue()));
-// }
-
- // push to stack
- ORExpression orExpr = new ORExpression();
- ANDExpression andExpr = new ANDExpression();
- andExpr.getAtomicExprList().add(kv);
- orExpr.getANDExprList().add(andExpr);
- _stack.push(orExpr);
- }
-
- private String postProcessNode(String text,TokenType type){
- int len = text.length();
- int start=0,end = len;
- if(text.startsWith("\"")) start=1;
- if(text.endsWith("\"")) end = len -1;
- text = text.substring(start, end);
- if(type == TokenType.EXP){
- Matcher matcher = TokenConstant.EXP_PATTERN.matcher(text);
- if(matcher.find()){
- text = matcher.group(1);
- }
- text = text.replace(TokenConstant.ID_PREFIX,TokenConstant.WHITE_SPACE);
- }
- return text;
- }
-
- public void enterCombine(EagleFilterParser.CombineContext ctx){
-
- }
-
- public void exitCombine(EagleFilterParser.CombineContext ctx){
- int numChild = ctx.getChildCount();
- if(numChild == 1){
- if(LOG.isDebugEnabled()) LOG.debug("Only one child, skip ...");
- return; // does nothing for a combine which has only one equation
- }
-
- if((ctx.LPAREN() != null) && (ctx.RPAREN() != null)){
- if(LOG.isDebugEnabled()) LOG.debug("LPAREN + RPAREN rule matched, skip ...");
- return; // does nothing for a combine which is within parenthesis
- }
- ORExpression orExprRight = _stack.pop();
- ORExpression orExprLeft = _stack.pop();
- TerminalNode node = ctx.AND();
- if(node != null){
- ORExpression newORExpr = new ORExpression();
- for(ANDExpression left : orExprLeft.getANDExprList()){
- for(ANDExpression right : orExprRight.getANDExprList()){
- ANDExpression tmp = new ANDExpression();
- tmp.getAtomicExprList().addAll(left.getAtomicExprList());
- tmp.getAtomicExprList().addAll(right.getAtomicExprList());
- newORExpr.getANDExprList().add(tmp);
- }
- }
- _stack.push(newORExpr);
- return;
- }
-
- node = ctx.OR();
- if(node != null){
- ORExpression newORExpr = new ORExpression();
- for(ANDExpression andExpr : orExprLeft.getANDExprList()){
- newORExpr.getANDExprList().add(andExpr);
- }
- for(ANDExpression andExpr : orExprRight.getANDExprList()){
- newORExpr.getANDExprList().add(andExpr);
- }
- _stack.push(newORExpr);
- return;
- }
- LOG.warn("Should never come here!");
- }
-
- public void enterFilter(EagleFilterParser.FilterContext ctx){
-
- }
-
- public void exitFilter(EagleFilterParser.FilterContext ctx){
- // print all relations (KeyValueFilter AND KeyValueFilter) OR (KeyValueFilter AND KeyValueFilter) OR (KeyValueFilter AND KeyValueFilter)"
- ORExpression orExpr = _stack.peek();
- if(LOG.isDebugEnabled()) LOG.debug(orExpr.toString());
- }
-
- public void visitTerminal(TerminalNode node){
-
- }
- public void visitErrorNode(ErrorNode node){
-
- }
- public void enterEveryRule(ParserRuleContext ctx){
+ public ORExpression result() {
+ return stack.pop();
}
-
- public void exitEveryRule(ParserRuleContext ctx){
-
+
+ public void enterEquation(EagleFilterParser.EquationContext ctx) {
+ }
+
+ public void exitEquation(EagleFilterParser.EquationContext ctx) {
+ TerminalNode id = ctx.ID();
+ TerminalNode op = ctx.OP();
+ List<TerminalNode> values = ctx.VALUE();
+ TerminalNode value = values.get(0);
+
+ if (values.size() == 2) {
+ // value op value
+ id = values.get(0);
+ value = values.get(1);
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("ID:" + id.getText() + ", OP:" + op.getText() + ", VALUE:" + value);
+ }
+
+ AtomicExpression kv = new AtomicExpression();
+ kv.setKey(id.getText());
+ kv.setOp(ComparisonOperator.locateOperator(op.getText()));
+
+ try {
+ kv.setValueType(TokenType.locate(value.getText()));
+ } catch (Exception ex) {
+ LOG.error("Failed to locate value type for: " + value.getText() + " due to exception: " + ex.getMessage(), ex);
+ }
+
+ try {
+ kv.setKeyType(TokenType.locate(id.getText()));
+ } catch (Exception ex) {
+ LOG.error("Failed to locate id type for: " + id.getText() + " due to exception: " + ex.getMessage(), ex);
+ }
+
+ // if (id != null) {
+ kv.setKey(postProcessNode(id.getText(),kv.getKeyType()));
+ // }
+
+ // if (value != null) {
+ kv.setValue(postProcessNode(value.getText(),kv.getValueType()));
+ // As to List value, it will escape in List parser but not here
+ if (kv.getValueType() != TokenType.LIST) {
+ kv.setValue(StringEscapeUtils.unescapeJava(kv.getValue()));
+ }
+ // }
+
+ // push to stack
+ ORExpression orExpr = new ORExpression();
+ ANDExpression andExpr = new ANDExpression();
+ andExpr.getAtomicExprList().add(kv);
+ orExpr.getANDExprList().add(andExpr);
+ stack.push(orExpr);
+ }
+
+ private String postProcessNode(String text,TokenType type) {
+ int len = text.length();
+ int start = 0;
+ int end = len;
+ if (text.startsWith("\"")) {
+ start = 1;
+ }
+ if (text.endsWith("\"")) {
+ end = len - 1;
+ }
+ text = text.substring(start, end);
+ if (type == TokenType.EXP) {
+ Matcher matcher = TokenConstant.EXP_PATTERN.matcher(text);
+ if (matcher.find()) {
+ text = matcher.group(1);
+ }
+ text = text.replace(TokenConstant.ID_PREFIX,TokenConstant.WHITE_SPACE);
+ }
+ return text;
+ }
+
+ public void enterCombine(EagleFilterParser.CombineContext ctx) {
+
+ }
+
+ public void exitCombine(EagleFilterParser.CombineContext ctx) {
+ int numChild = ctx.getChildCount();
+ if (numChild == 1) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Only one child, skip ...");
+ }
+ return; // does nothing for a combine which has only one equation
+ }
+
+ if ((ctx.LPAREN() != null) && (ctx.RPAREN() != null)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("LPAREN + RPAREN rule matched, skip ...");
+ }
+ return; // does nothing for a combine which is within parenthesis
+ }
+ ORExpression orExprRight = stack.pop();
+ ORExpression orExprLeft = stack.pop();
+ TerminalNode node = ctx.AND();
+ if (node != null) {
+ ORExpression newORExpr = new ORExpression();
+ for (ANDExpression left : orExprLeft.getANDExprList()) {
+ for (ANDExpression right : orExprRight.getANDExprList()) {
+ ANDExpression tmp = new ANDExpression();
+ tmp.getAtomicExprList().addAll(left.getAtomicExprList());
+ tmp.getAtomicExprList().addAll(right.getAtomicExprList());
+ newORExpr.getANDExprList().add(tmp);
+ }
+ }
+ stack.push(newORExpr);
+ return;
+ }
+
+ node = ctx.OR();
+ if (node != null) {
+ ORExpression newORExpr = new ORExpression();
+ for (ANDExpression andExpr : orExprLeft.getANDExprList()) {
+ newORExpr.getANDExprList().add(andExpr);
+ }
+ for (ANDExpression andExpr : orExprRight.getANDExprList()) {
+ newORExpr.getANDExprList().add(andExpr);
+ }
+ stack.push(newORExpr);
+ return;
+ }
+ LOG.warn("Should never come here!");
+ }
+
+ public void enterFilter(EagleFilterParser.FilterContext ctx) {
+
+ }
+
+ public void exitFilter(EagleFilterParser.FilterContext ctx) {
+ // print all relations (KeyValueFilter AND KeyValueFilter) OR (KeyValueFilter AND KeyValueFilter) OR (KeyValueFilter AND KeyValueFilter)"
+ ORExpression orExpr = stack.peek();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(orExpr.toString());
+ }
+ }
+
+ public void visitTerminal(TerminalNode node) {
+ }
+
+ public void visitErrorNode(ErrorNode node) {
+ }
+
+ public void enterEveryRule(ParserRuleContext ctx) {
+ }
+
+ public void exitEveryRule(ParserRuleContext ctx) {
}
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParseException.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParseException.java
index 48fc694..c8321ca 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParseException.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParseException.java
@@ -16,14 +16,14 @@
*/
package org.apache.eagle.query.parser;
-public class EagleQueryParseException extends Exception{
- private static final long serialVersionUID = -8440811651318471641L;
+public class EagleQueryParseException extends Exception {
+ private static final long serialVersionUID = -8440811651318471641L;
- public EagleQueryParseException(String message){
- super(message);
- }
+ public EagleQueryParseException(String message) {
+ super(message);
+ }
- public EagleQueryParseException(String message, Throwable cause) {
- super(message, cause);
- }
+ public EagleQueryParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParser.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParser.java
index f2315b2..7ef5721 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParser.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/EagleQueryParser.java
@@ -24,31 +24,32 @@
import org.slf4j.LoggerFactory;
public class EagleQueryParser {
- private static final Logger LOG = LoggerFactory.getLogger(EagleQueryParser.class);
- private String _query;
- public EagleQueryParser(String query){
- _query = query;
- }
+ private static final Logger LOG = LoggerFactory.getLogger(EagleQueryParser.class);
+ private String query;
- public ORExpression parse() throws EagleQueryParseException{
- try{
- EagleFilterLexer lexer = new EagleFilterLexer(new ANTLRInputStream(_query));
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- tokens.fill();
- EagleFilterParser p = new EagleFilterParser(tokens);
- p.setErrorHandler(new EagleANTLRErrorStrategy());
- p.setBuildParseTree(true);
- EagleQueryFilterListenerImpl listener = new EagleQueryFilterListenerImpl();
- p.addParseListener(listener);
- EagleFilterParser.FilterContext fc = p.filter();
- if(fc.exception != null){
- LOG.error("Can not successfully parse the query:" + _query, fc.exception);
- throw fc.exception;
- }
- return listener.result();
- }catch(Exception ex){
- LOG.error("Can not successfully parse the query:", ex);
- throw new EagleQueryParseException("can not successfully parse the query:" + _query);
- }
- }
+ public EagleQueryParser(String query) {
+ this.query = query;
+ }
+
+ public ORExpression parse() throws EagleQueryParseException {
+ try {
+ EagleFilterLexer lexer = new EagleFilterLexer(new ANTLRInputStream(query));
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ tokens.fill();
+ EagleFilterParser p = new EagleFilterParser(tokens);
+ p.setErrorHandler(new EagleANTLRErrorStrategy());
+ p.setBuildParseTree(true);
+ EagleQueryFilterListenerImpl listener = new EagleQueryFilterListenerImpl();
+ p.addParseListener(listener);
+ EagleFilterParser.FilterContext fc = p.filter();
+ if (fc.exception != null) {
+ LOG.error("Can not successfully parse the query:" + query, fc.exception);
+ throw fc.exception;
+ }
+ return listener.result();
+ } catch (Exception ex) {
+ LOG.error("Can not successfully parse the query:", ex);
+ throw new EagleQueryParseException("can not successfully parse the query:" + query);
+ }
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/LogicalOperator.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/LogicalOperator.java
index 374186e..8c95991 100644
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/LogicalOperator.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/LogicalOperator.java
@@ -17,7 +17,7 @@
package org.apache.eagle.query.parser;
public enum LogicalOperator {
- AND,
- OR,
- NOT
+ AND,
+ OR,
+ NOT
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ORExpression.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ORExpression.java
index 3a43a6d..2c414f4 100644
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ORExpression.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/ORExpression.java
@@ -20,41 +20,41 @@
import java.util.List;
public class ORExpression {
- private List<ANDExpression> andExprList = new ArrayList<ANDExpression>();
+ private List<ANDExpression> andExprList = new ArrayList<ANDExpression>();
- public List<ANDExpression> getANDExprList() {
- return andExprList;
- }
+ public List<ANDExpression> getANDExprList() {
+ return andExprList;
+ }
- public void setANDExprList(List<ANDExpression> list) {
- this.andExprList = list;
- }
-
- public String toString(){
- StringBuffer sb = new StringBuffer();
- boolean first = true;
- for(ANDExpression andRel : andExprList){
- if(first)
- first = false;
- else{
- sb.append(" ");
- sb.append(LogicalOperator.OR);
- sb.append(" ");
- }
- sb.append("(");
- boolean firstAND = true;
- for(AtomicExpression kv : andRel.getAtomicExprList()){
- if(firstAND)
- firstAND = false;
- else{
- sb.append(" ");
- sb.append(LogicalOperator.AND);
- sb.append(" ");
- }
- sb.append(kv);
- }
- sb.append(")");
- }
- return sb.toString();
- }
+ public void setANDExprList(List<ANDExpression> list) {
+ this.andExprList = list;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ boolean first = true;
+ for (ANDExpression andRel : andExprList) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(" ");
+ sb.append(LogicalOperator.OR);
+ sb.append(" ");
+ }
+ sb.append("(");
+ boolean firstAND = true;
+ for (AtomicExpression kv : andRel.getAtomicExprList()) {
+ if (firstAND) {
+ firstAND = false;
+ } else {
+ sb.append(" ");
+ sb.append(LogicalOperator.AND);
+ sb.append(" ");
+ }
+ sb.append(kv);
+ }
+ sb.append(")");
+ }
+ return sb.toString();
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/TokenConstant.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/TokenConstant.java
index f93a63e..79cef21 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/TokenConstant.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/TokenConstant.java
@@ -20,31 +20,33 @@
import java.util.regex.Pattern;
public final class TokenConstant {
- public final static Pattern EXP_PATTERN= Pattern.compile("^EXP\\{(.+)\\}(\\s+AS\\s+)?\\s*(.+)?\\s*$",Pattern.CASE_INSENSITIVE);
- public final static Pattern STRING_PATTERN= Pattern.compile("^(\"(.*?\n)*.*\")$");
- public final static Pattern ARRAY_PATTERN= Pattern.compile("^(\\(.*\\))$");
- public final static Pattern NUMBER_PATTERN= Pattern.compile("^((-|\\+)?\\s*[0-9]+(\\.[0-9]+)?)$");
- public final static Pattern NULL_PATTERN= Pattern.compile("^(NULL|null)$");
- public final static Pattern ID_PATTERN= Pattern.compile("^@(.+)$");
+ public static final Pattern EXP_PATTERN = Pattern.compile("^EXP\\{(.+)\\}(\\s+AS\\s+)?\\s*(.+)?\\s*$",Pattern.CASE_INSENSITIVE);
+ public static final Pattern STRING_PATTERN = Pattern.compile("^(\"(.*?\n)*.*\")$");
+ public static final Pattern ARRAY_PATTERN = Pattern.compile("^(\\(.*\\))$");
+ public static final Pattern NUMBER_PATTERN = Pattern.compile("^((-|\\+)?\\s*[0-9]+(\\.[0-9]+)?)$");
+ public static final Pattern NULL_PATTERN = Pattern.compile("^(NULL|null)$");
+ public static final Pattern ID_PATTERN = Pattern.compile("^@(.+)$");
- public final static String ID_PREFIX = "@";
- public final static String WHITE_SPACE = "";
+ public static final String ID_PREFIX = "@";
+ public static final String WHITE_SPACE = "";
- public static boolean isExpression(String query){
- if(query == null) return false;
+ public static boolean isExpression(String query) {
+ if (query == null) {
+ return false;
+ }
Matcher matcher = EXP_PATTERN.matcher(query);
return matcher.matches();
}
/**
- * EXP{ expression } AS alias => expression
+ * EXP{ expression } AS alias => expression.
*
* @param expression
* @return
*/
- public static String parseExpressionContent(String expression){
+ public static String parseExpressionContent(String expression) {
Matcher matcher = EXP_PATTERN.matcher(expression);
- if(matcher.find()){
+ if (matcher.find()) {
expression = matcher.group(1);
}
return expression;
diff --git a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/UnsupportedExpressionOperatorException.java b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/UnsupportedExpressionOperatorException.java
index 40997c9..de30b8b 100644
--- a/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/UnsupportedExpressionOperatorException.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/main/java/org/apache/eagle/query/parser/UnsupportedExpressionOperatorException.java
@@ -16,10 +16,10 @@
*/
package org.apache.eagle.query.parser;
-public class UnsupportedExpressionOperatorException extends RuntimeException{
- private static final long serialVersionUID = 565210592983703093L;
+public class UnsupportedExpressionOperatorException extends RuntimeException {
+ private static final long serialVersionUID = 565210592983703093L;
- public UnsupportedExpressionOperatorException(String message){
- super(message);
- }
+ public UnsupportedExpressionOperatorException(String message) {
+ super(message);
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestEagleQueryParser.java b/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestEagleQueryParser.java
index 2f5b47b..3430b29 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestEagleQueryParser.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestEagleQueryParser.java
@@ -23,810 +23,810 @@
import org.slf4j.LoggerFactory;
public class TestEagleQueryParser {
-
- private static final Logger LOG = LoggerFactory.getLogger(TestEagleQueryParser.class);
-
- @Test
- public void testSingleExpression(){
- String query = "@cluster=\"a\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("a", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"a\")", or.toString());
- }
- @Test
- public void testLessThanExpression(){
- String query = "@field1<\"1\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("(@field1<\"1\")", or.toString());
- }
+ private static final Logger LOG = LoggerFactory.getLogger(TestEagleQueryParser.class);
- @Test
- public void testLessOrEqualExpression(){
- String query = "@field1<=\"1\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("<=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("(@field1<=\"1\")", or.toString());
- }
+ @Test
+ public void testSingleExpression() {
+ String query = "@cluster=\"a\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("a", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"a\")", or.toString());
+ }
- @Test
- public void testGreaterThanExpression(){
- String query = "@field1>\"1\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals(">", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("(@field1>\"1\")", or.toString());
- }
+ @Test
+ public void testLessThanExpression() {
+ String query = "@field1<\"1\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("(@field1<\"1\")", or.toString());
+ }
- @Test
- public void testGreaterOrEqualExpression(){
- String query = "@field1>=\"1\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals(">=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ @Test
+ public void testLessOrEqualExpression() {
+ String query = "@field1<=\"1\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("<=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("(@field1<=\"1\")", or.toString());
+ }
- LOG.info(or.toString());
- Assert.assertEquals("(@field1>=\"1\")", or.toString());
- }
+ @Test
+ public void testGreaterThanExpression() {
+ String query = "@field1>\"1\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals(">", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("(@field1>\"1\")", or.toString());
+ }
- @Test
- public void testMultipleANDExpression(){
- String query = "@cluster=\"abc\" AND @host=\"dc123.xyz.com\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(2, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("abc", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("@host", or.getANDExprList().get(0).getAtomicExprList().get(1).getKey());
- Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(0).getAtomicExprList().get(1).getValue());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(1).getValueType());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(1).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"abc\" AND @host=\"dc123.xyz.com\")", or.toString());
-
- query = "@datacenter=\"dc1\" AND @cluster=\"abc\" AND @host=\"dc123.xyz.com\" ";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(3, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@datacenter", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("dc1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(1).getKey());
- Assert.assertEquals("abc", or.getANDExprList().get(0).getAtomicExprList().get(1).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(1).getOp().toString());
- Assert.assertEquals("@host", or.getANDExprList().get(0).getAtomicExprList().get(2).getKey());
- Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(0).getAtomicExprList().get(2).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(2).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("(@datacenter=\"dc1\" AND @cluster=\"abc\" AND @host=\"dc123.xyz.com\")", or.toString());
- }
-
- @Test
- public void testMultipleORExpression(){
- String query = "@cluster=\"abc\" OR @host=\"dc123.xyz.com\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==2);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals(1, or.getANDExprList().get(1).getAtomicExprList().size());
- Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("abc", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("@host", or.getANDExprList().get(1).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(1).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(1).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("(@cluster=\"abc\") OR (@host=\"dc123.xyz.com\")", or.toString());
-
- query = "@datacenter=\"dc1\" OR @cluster=\"abc\" OR @host=\"dc123.xyz.com\"";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- } Assert.assertTrue(or.getANDExprList().size()==3);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals(1, or.getANDExprList().get(1).getAtomicExprList().size());
- Assert.assertEquals(1, or.getANDExprList().get(2).getAtomicExprList().size());
- Assert.assertEquals("@datacenter", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("dc1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("@cluster", or.getANDExprList().get(1).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("abc", or.getANDExprList().get(1).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(1).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("@host", or.getANDExprList().get(2).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(2).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(2).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("(@datacenter=\"dc1\") OR (@cluster=\"abc\") OR (@host=\"dc123.xyz.com\")", or.toString());
- }
-
- @Test
- public void testANDORCombination(){
- String query = "@cluster=\"abc\" OR @host=\"dc123.xyz.com\" AND @datacenter=\"dc1\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- } LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"abc\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\")", or.toString());
-
- query = "(@cluster=\"abc\" AND @host=\"dc123.xyz.com\") AND @datacenter=\"dc1\"";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- } LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"abc\" AND @host=\"dc123.xyz.com\" AND @datacenter=\"dc1\")", or.toString());
+ @Test
+ public void testGreaterOrEqualExpression() {
+ String query = "@field1>=\"1\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals(">=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- query = "(@cluster=\"abc\" OR @host=\"dc123.xyz.com\") AND @datacenter=\"dc1\"";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"abc\" AND @datacenter=\"dc1\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\")", or.toString());
-
- query = "(@cluster=\"abc\" OR @host=\"dc123.xyz.com\") AND (@datacenter=\"dc1\" OR @cluster=\"bcd\")";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"abc\" AND @datacenter=\"dc1\") OR (@cluster=\"abc\" AND @cluster=\"bcd\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\") OR (@host=\"dc123.xyz.com\" AND @cluster=\"bcd\")", or.toString());
-
- query = "(@cluster=\"abc\" OR @host=\"dc123.xyz.com\") AND (@datacenter=\"dc1\" AND @cluster=\"bcd\")";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"abc\" AND @datacenter=\"dc1\" AND @cluster=\"bcd\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\" AND @cluster=\"bcd\")", or.toString());
- }
-
- @Test
- public void testNegativeCase(){
- String query = "@cluster = \"a\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- LOG.info(or.toString());
- Assert.assertEquals("(@cluster=\"a\")", or.toString());
-
- query = "@cluster = a\"";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(Exception ex){
- LOG.error("Can not successfully parse the query:" + query, ex);
- }
- Assert.assertTrue(or == null);
-
- query = "@cluster = \"\"a\"";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(Exception ex){
- LOG.error("Can not successfully parse the query:" + query, ex);
- }
- Assert.assertNotNull(or);
+ LOG.info(or.toString());
+ Assert.assertEquals("(@field1>=\"1\")", or.toString());
+ }
- query = "@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND @remediationID=8888\" AND @remediationStatus=\"status\"";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(Exception ex){
- LOG.error("Can not successfully parse the query:" + query, ex);
- }
- Assert.assertTrue(or == null);
- }
-
- @Test
- public void testSimpleWildcardMatchQuery(){
- String expected = "-[]/{}()*+?.\\^$|";
- String query = "@user=\"-[]/{}()*+?.\\\\^$|\"";
- System.out.println(query);
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@user", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals(expected, or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("(@user=\""+expected+"\")", or.toString());
- }
+ @Test
+ public void testMultipleANDExpression() {
+ String query = "@cluster=\"abc\" AND @host=\"dc123.xyz.com\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(2, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("abc", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("@host", or.getANDExprList().get(0).getAtomicExprList().get(1).getKey());
+ Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(0).getAtomicExprList().get(1).getValue());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(1).getValueType());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(1).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"abc\" AND @host=\"dc123.xyz.com\")", or.toString());
- @Test
- public void testNumberQuery() {
- String query = "@field1 >= -1.234";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals(-1.234, Double.parseDouble(or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()), 0.0001);
- Assert.assertEquals(">=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ query = "@datacenter=\"dc1\" AND @cluster=\"abc\" AND @host=\"dc123.xyz.com\" ";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(3, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@datacenter", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("dc1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(1).getKey());
+ Assert.assertEquals("abc", or.getANDExprList().get(0).getAtomicExprList().get(1).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(1).getOp().toString());
+ Assert.assertEquals("@host", or.getANDExprList().get(0).getAtomicExprList().get(2).getKey());
+ Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(0).getAtomicExprList().get(2).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(2).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("(@datacenter=\"dc1\" AND @cluster=\"abc\" AND @host=\"dc123.xyz.com\")", or.toString());
+ }
- @Test
- public void testContainQuery() {
- String query = "@name contains \"jame\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ @Test
+ public void testMultipleORExpression() {
+ String query = "@cluster=\"abc\" OR @host=\"dc123.xyz.com\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size()==2);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals(1, or.getANDExprList().get(1).getAtomicExprList().size());
+ Assert.assertEquals("@cluster", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("abc", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("@host", or.getANDExprList().get(1).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(1).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(1).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("(@cluster=\"abc\") OR (@host=\"dc123.xyz.com\")", or.toString());
- @Test
- public void testNotContainQuery() {
- String query = "@name not contains \"jame\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "@datacenter=\"dc1\" OR @cluster=\"abc\" OR @host=\"dc123.xyz.com\"";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ } Assert.assertTrue(or.getANDExprList().size()==3);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals(1, or.getANDExprList().get(1).getAtomicExprList().size());
+ Assert.assertEquals(1, or.getANDExprList().get(2).getAtomicExprList().size());
+ Assert.assertEquals("@datacenter", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("dc1", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("@cluster", or.getANDExprList().get(1).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("abc", or.getANDExprList().get(1).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(1).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("@host", or.getANDExprList().get(2).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("dc123.xyz.com", or.getANDExprList().get(2).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(2).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("(@datacenter=\"dc1\") OR (@cluster=\"abc\") OR (@host=\"dc123.xyz.com\")", or.toString());
+ }
- query = "@name NOT CONTAINS \"jame\"";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ @Test
+ public void testANDORCombination() {
+ String query = "@cluster=\"abc\" OR @host=\"dc123.xyz.com\" AND @datacenter=\"dc1\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ } LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"abc\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\")", or.toString());
- query = "@name NOT CONTAINS \"jame\"";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ query = "(@cluster=\"abc\" AND @host=\"dc123.xyz.com\") AND @datacenter=\"dc1\"";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ } LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"abc\" AND @host=\"dc123.xyz.com\" AND @datacenter=\"dc1\")", or.toString());
- @Test
- public void testNullQuery() {
- String query = "@name is null";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("null", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "(@cluster=\"abc\" OR @host=\"dc123.xyz.com\") AND @datacenter=\"dc1\"";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"abc\" AND @datacenter=\"dc1\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\")", or.toString());
- query = "@name IS NULL";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "(@cluster=\"abc\" OR @host=\"dc123.xyz.com\") AND (@datacenter=\"dc1\" OR @cluster=\"bcd\")";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"abc\" AND @datacenter=\"dc1\") OR (@cluster=\"abc\" AND @cluster=\"bcd\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\") OR (@host=\"dc123.xyz.com\" AND @cluster=\"bcd\")", or.toString());
- query = "@name is not null";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("null", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "(@cluster=\"abc\" OR @host=\"dc123.xyz.com\") AND (@datacenter=\"dc1\" AND @cluster=\"bcd\")";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"abc\" AND @datacenter=\"dc1\" AND @cluster=\"bcd\") OR (@host=\"dc123.xyz.com\" AND @datacenter=\"dc1\" AND @cluster=\"bcd\")", or.toString());
+ }
- query = "@name is not NULL";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ @Test
+ public void testNegativeCase() {
+ String query = "@cluster = \"a\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ LOG.info(or.toString());
+ Assert.assertEquals("(@cluster=\"a\")", or.toString());
- query = "@name = NULL";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "@cluster = a\"";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (Exception ex) {
+ LOG.error("Can not successfully parse the query:" + query, ex);
+ }
+ Assert.assertTrue(or == null);
- query = "@name != NULL";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("!=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ query = "@cluster = \"\"a\"";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (Exception ex) {
+ LOG.error("Can not successfully parse the query:" + query, ex);
+ }
+ Assert.assertNotNull(or);
- @Test
- public void testIsOrIsNotQuery(){
- String query = "@name is \"james\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("james", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "@cluster=\"cluster1\" AND @datacenter=\"dc1\" AND @remediationID=8888\" AND @remediationStatus=\"status\"";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (Exception ex) {
+ LOG.error("Can not successfully parse the query:" + query, ex);
+ }
+ Assert.assertTrue(or == null);
+ }
- query = "@name is not \"james\"";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("james", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ @Test
+ public void testSimpleWildcardMatchQuery() {
+ String expected = "-[]/{}()*+?.\\^$|";
+ String query = "@user=\"-[]/{}()*+?.\\\\^$|\"";
+ System.out.println(query);
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@user", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals(expected, or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("(@user=\""+expected+"\")", or.toString());
+ }
- query = "@name is 1.234";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("1.234", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ @Test
+ public void testNumberQuery() {
+ String query = "@field1 >= -1.234";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@field1", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals(-1.234, Double.parseDouble(or.getANDExprList().get(0).getAtomicExprList().get(0).getValue()), 0.0001);
+ Assert.assertEquals(">=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
- query = "@name is not 1.234";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("1.234", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ @Test
+ public void testContainQuery() {
+ String query = "@name contains \"jame\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
- @Test
- public void testINListQuery() {
- String query = "@name in (\"jame\",\"lebron\")";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("(\"jame\",\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ @Test
+ public void testNotContainQuery() {
+ String query = "@name not contains \"jame\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- query = "@name NOT IN (1,\"lebron\")";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("(1,\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("NOT IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "@name NOT CONTAINS \"jame\"";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- query = "@name not in (1,\"lebron\")";
- parser = new EagleQueryParser(query);
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("(1,\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("NOT IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ query = "@name NOT CONTAINS \"jame\"";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("jame", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("NOT CONTAINS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
- @Test
- public void testEmptyString() {
- String query = "@name = \"\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertNotNull(or);
- Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ @Test
+ public void testNullQuery() {
+ String query = "@name is null";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("null", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- /**
- * Will split tokens for escaped string
- *
- * "va\"lue" => "va\"lue"
- * ("va\"lue","va,lue") => ["va\\\"lue","va,lue"]
- *
- */
- @Test
- public void testEscapedQuotesString(){
- String query = "@value = \"value\\\"content, and another content\"";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertNotNull(or);
- Assert.assertEquals("@value", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("value\"content, and another content", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "@name IS NULL";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- query = "@value in (\"value\\\"content, and another content\",\"others item\")";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertNotNull(or);
- Assert.assertEquals("@value", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("(\"value\\\"content, and another content\",\"others item\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ query = "@name is not null";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("null", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- query = "@value in (\"value\\\"content, and another content\",\"others item\",-1.2345)";
- parser = new EagleQueryParser(query);
- or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertNotNull(or);
- Assert.assertEquals("@value", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("(\"value\\\"content, and another content\",\"others item\",-1.2345)", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ query = "@name is not NULL";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- @Test
- public void testCompareAtomicExpression(){
- String query = "EXP{@mapProgress} < EXP{@reduceProgress}";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("mapProgress", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("reduceProgress", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("(mapProgress<reduceProgress)", or.toString());
- }
+ query = "@name = NULL";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- @Test
- public void testCompareArithmeticExpressionWithNumeric(){
- String query = "EXP{(@mapProgress + @reduceProgress) / (@endTime - @startTime)} < 0.005";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("(mapProgress + reduceProgress) / (endTime - startTime)", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("0.005", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- LOG.info(or.toString());
- Assert.assertEquals("((mapProgress + reduceProgress) / (endTime - startTime)<0.005)", or.toString());
- }
+ query = "@name != NULL";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("NULL", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("!=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NULL, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
- @Test
- public void testComplexExpressionWithNestedBrace(){
- String query = "EXP{((@a + @b) / @c) + @d}< 0.005";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
- Assert.assertEquals("((a + b) / c) + d", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
- Assert.assertEquals("0.005", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
- Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
- Assert.assertEquals("(((a + b) / c) + d<0.005)", or.toString());
- }
+ @Test
+ public void testIsOrIsNotQuery() {
+ String query = "@name is \"james\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("james", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- @Test
- public void testComplexExpressionWithAndCondition(){
- String query = "(EXP{@a + @b} > 3) AND (@b >10)";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- ANDExpression and = or.getANDExprList().get(0);
- Assert.assertEquals(2, and.getAtomicExprList().size());
- Assert.assertEquals("a + b>3", and.getAtomicExprList().get(0).toString());
- Assert.assertEquals("@b>10", and.getAtomicExprList().get(1).toString());
-
- AtomicExpression leftExpression = and.getAtomicExprList().get(0);
- Assert.assertEquals("a + b", leftExpression.getKey());
- Assert.assertEquals(TokenType.EXP, leftExpression.getKeyType());
- Assert.assertEquals(">", leftExpression.getOp().toString());
- Assert.assertEquals("3", leftExpression.getValue());
- Assert.assertEquals(TokenType.NUMBER, leftExpression.getValueType());
- AtomicExpression rightExpression = and.getAtomicExprList().get(1);
- Assert.assertEquals("@b", rightExpression.getKey());
- Assert.assertEquals(TokenType.ID, rightExpression.getKeyType());
- Assert.assertEquals(">", rightExpression.getOp().toString());
- Assert.assertEquals("10",rightExpression.getValue());
- Assert.assertEquals(TokenType.NUMBER, rightExpression.getValueType());
- }
+ query = "@name is not \"james\"";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("james", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- @Test
- public void testComplexExpressionWithConditionAndNestedBrace(){
- String query = "(EXP{(@a + @b) / ((@c + @d)*(@e)/(@d))} > EXP{@c + @d}) AND (EXP{@e + @f} > EXP{@h + @i})";
- EagleQueryParser parser = new EagleQueryParser(query);
- ORExpression or = null;
- try{
- or = parser.parse();
- }catch(EagleQueryParseException ex){
- Assert.fail(ex.getMessage());
- }
- Assert.assertTrue(or.getANDExprList().size()==1);
- ANDExpression and = or.getANDExprList().get(0);
- Assert.assertEquals(2, and.getAtomicExprList().size());
- Assert.assertEquals("(a + b) / ((c + d)*(e)/(d))>c + d", and.getAtomicExprList().get(0).toString());
- Assert.assertEquals("e + f>h + i", and.getAtomicExprList().get(1).toString());
-
- AtomicExpression leftExpression = and.getAtomicExprList().get(0);
- Assert.assertEquals("(a + b) / ((c + d)*(e)/(d))", leftExpression.getKey());
- Assert.assertEquals(">", leftExpression.getOp().toString());
- Assert.assertEquals("c + d", leftExpression.getValue());
-
- AtomicExpression rightExpression = and.getAtomicExprList().get(1);
- Assert.assertEquals("e + f", rightExpression.getKey());
- Assert.assertEquals(">", rightExpression.getOp().toString());
- Assert.assertEquals("h + i",rightExpression.getValue());
- }
+ query = "@name is 1.234";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("1.234", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- @Test
- public void testNegativeExpressionCase(){
- String query = "(EXP{(@a + @b) / ((@c + @d)*(@e)/(@d))}} > EXP{@c + @d}) AND (EXP{@e + @f} > EXP{@h + @i})";
- EagleQueryParser parser = new EagleQueryParser(query);
- boolean parseFail = true;
- try{
- parser.parse();
- }catch(EagleQueryParseException ex){
- parseFail = false;
- }
- Assert.assertFalse(parseFail);
-
- query = "(EXP{{(@a + @b) / ((@c + @d)*(@e)/(@d))}} > EXP{@c + @d}) AND (EXP{@e + @f} > EXP{@h + @i})";
- parser = new EagleQueryParser(query);
- parseFail = true;
- try{
- parser.parse();
- }catch(EagleQueryParseException ex){
- parseFail = false;
- }
- Assert.assertFalse(parseFail);
+ query = "@name is not 1.234";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("1.234", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IS NOT", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.NUMBER, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
- query = "(EXP{(@a + @b) / ((@c + @d)*(@e)/(@d))} > EXP{@c + @d}) AND EXP{})";
- parser = new EagleQueryParser(query);
- parseFail = true;
- try{
- parser.parse();
- }catch(EagleQueryParseException ex){
- parseFail = false;
- }
- Assert.assertFalse(parseFail);
+ @Test
+ public void testINListQuery() {
+ String query = "@name in (\"jame\",\"lebron\")";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("(\"jame\",\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- }
+ query = "@name NOT IN (1,\"lebron\")";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("(1,\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("NOT IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
- @Test
- public void testIsExpression(){
- Assert.assertTrue(TokenConstant.isExpression("EXP{ count }"));
- Assert.assertFalse(TokenConstant.isExpression("count"));
- }
+ query = "@name not in (1,\"lebron\")";
+ parser = new EagleQueryParser(query);
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("(1,\"lebron\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("NOT IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
+
+ @Test
+ public void testEmptyString() {
+ String query = "@name = \"\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertNotNull(or);
+ Assert.assertEquals("@name", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
+
+ /**
+ * Will split tokens for escaped string
+ *
+ * "va\"lue" => "va\"lue"
+ * ("va\"lue","va,lue") => ["va\\\"lue","va,lue"]
+ *
+ */
+ @Test
+ public void testEscapedQuotesString() {
+ String query = "@value = \"value\\\"content, and another content\"";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertNotNull(or);
+ Assert.assertEquals("@value", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("value\"content, and another content", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("=", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.STRING, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+
+ query = "@value in (\"value\\\"content, and another content\",\"others item\")";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertNotNull(or);
+ Assert.assertEquals("@value", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("(\"value\\\"content, and another content\",\"others item\")", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+
+ query = "@value in (\"value\\\"content, and another content\",\"others item\",-1.2345)";
+ parser = new EagleQueryParser(query);
+ or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertNotNull(or);
+ Assert.assertEquals("@value", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("(\"value\\\"content, and another content\",\"others item\",-1.2345)", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("IN", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals(TokenType.LIST, or.getANDExprList().get(0).getAtomicExprList().get(0).getValueType());
+ }
+
+ @Test
+ public void testCompareAtomicExpression() {
+ String query = "EXP{@mapProgress} < EXP{@reduceProgress}";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("mapProgress", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("reduceProgress", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("(mapProgress<reduceProgress)", or.toString());
+ }
+
+ @Test
+ public void testCompareArithmeticExpressionWithNumeric() {
+ String query = "EXP{(@mapProgress + @reduceProgress) / (@endTime - @startTime)} < 0.005";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("(mapProgress + reduceProgress) / (endTime - startTime)", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("0.005", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ LOG.info(or.toString());
+ Assert.assertEquals("((mapProgress + reduceProgress) / (endTime - startTime)<0.005)", or.toString());
+ }
+
+ @Test
+ public void testComplexExpressionWithNestedBrace() {
+ String query = "EXP{((@a + @b) / @c) + @d}< 0.005";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ Assert.assertEquals(1, or.getANDExprList().get(0).getAtomicExprList().size());
+ Assert.assertEquals("((a + b) / c) + d", or.getANDExprList().get(0).getAtomicExprList().get(0).getKey());
+ Assert.assertEquals("0.005", or.getANDExprList().get(0).getAtomicExprList().get(0).getValue());
+ Assert.assertEquals("<", or.getANDExprList().get(0).getAtomicExprList().get(0).getOp().toString());
+ Assert.assertEquals("(((a + b) / c) + d<0.005)", or.toString());
+ }
+
+ @Test
+ public void testComplexExpressionWithAndCondition() {
+ String query = "(EXP{@a + @b} > 3) AND (@b >10)";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ ANDExpression and = or.getANDExprList().get(0);
+ Assert.assertEquals(2, and.getAtomicExprList().size());
+ Assert.assertEquals("a + b>3", and.getAtomicExprList().get(0).toString());
+ Assert.assertEquals("@b>10", and.getAtomicExprList().get(1).toString());
+
+ AtomicExpression leftExpression = and.getAtomicExprList().get(0);
+ Assert.assertEquals("a + b", leftExpression.getKey());
+ Assert.assertEquals(TokenType.EXP, leftExpression.getKeyType());
+ Assert.assertEquals(">", leftExpression.getOp().toString());
+ Assert.assertEquals("3", leftExpression.getValue());
+ Assert.assertEquals(TokenType.NUMBER, leftExpression.getValueType());
+ AtomicExpression rightExpression = and.getAtomicExprList().get(1);
+ Assert.assertEquals("@b", rightExpression.getKey());
+ Assert.assertEquals(TokenType.ID, rightExpression.getKeyType());
+ Assert.assertEquals(">", rightExpression.getOp().toString());
+ Assert.assertEquals("10",rightExpression.getValue());
+ Assert.assertEquals(TokenType.NUMBER, rightExpression.getValueType());
+ }
+
+ @Test
+ public void testComplexExpressionWithConditionAndNestedBrace() {
+ String query = "(EXP{(@a + @b) / ((@c + @d)*(@e)/(@d))} > EXP{@c + @d}) AND (EXP{@e + @f} > EXP{@h + @i})";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ ORExpression or = null;
+ try {
+ or = parser.parse();
+ } catch (EagleQueryParseException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ Assert.assertTrue(or.getANDExprList().size() == 1);
+ ANDExpression and = or.getANDExprList().get(0);
+ Assert.assertEquals(2, and.getAtomicExprList().size());
+ Assert.assertEquals("(a + b) / ((c + d)*(e)/(d))>c + d", and.getAtomicExprList().get(0).toString());
+ Assert.assertEquals("e + f>h + i", and.getAtomicExprList().get(1).toString());
+
+ AtomicExpression leftExpression = and.getAtomicExprList().get(0);
+ Assert.assertEquals("(a + b) / ((c + d)*(e)/(d))", leftExpression.getKey());
+ Assert.assertEquals(">", leftExpression.getOp().toString());
+ Assert.assertEquals("c + d", leftExpression.getValue());
+
+ AtomicExpression rightExpression = and.getAtomicExprList().get(1);
+ Assert.assertEquals("e + f", rightExpression.getKey());
+ Assert.assertEquals(">", rightExpression.getOp().toString());
+ Assert.assertEquals("h + i",rightExpression.getValue());
+ }
+
+ @Test
+ public void testNegativeExpressionCase() {
+ String query = "(EXP{(@a + @b) / ((@c + @d)*(@e)/(@d))}} > EXP{@c + @d}) AND (EXP{@e + @f} > EXP{@h + @i})";
+ EagleQueryParser parser = new EagleQueryParser(query);
+ boolean parseFail = true;
+ try {
+ parser.parse();
+ } catch (EagleQueryParseException ex) {
+ parseFail = false;
+ }
+ Assert.assertFalse(parseFail);
+
+ query = "(EXP{{(@a + @b) / ((@c + @d)*(@e)/(@d))}} > EXP{@c + @d}) AND (EXP{@e + @f} > EXP{@h + @i})";
+ parser = new EagleQueryParser(query);
+ parseFail = true;
+ try {
+ parser.parse();
+ } catch (EagleQueryParseException ex) {
+ parseFail = false;
+ }
+ Assert.assertFalse(parseFail);
+
+ query = "(EXP{(@a + @b) / ((@c + @d)*(@e)/(@d))} > EXP{@c + @d}) AND EXP{})";
+ parser = new EagleQueryParser(query);
+ parseFail = true;
+ try {
+ parser.parse();
+ } catch (EagleQueryParseException ex) {
+ parseFail = false;
+ }
+ Assert.assertFalse(parseFail);
+
+ }
+
+ @Test
+ public void testIsExpression() {
+ Assert.assertTrue(TokenConstant.isExpression("EXP{ count }"));
+ Assert.assertFalse(TokenConstant.isExpression("count"));
+ }
}
diff --git a/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestValueType.java b/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestValueType.java
index 9627b78..66d465c 100755
--- a/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestValueType.java
+++ b/eagle-core/eagle-query/eagle-antlr/src/test/java/org/apache/eagle/query/parser/test/TestValueType.java
@@ -22,52 +22,52 @@
import org.junit.Test;
public class TestValueType {
- @Test
- public void testLocateValueType(){
- Assert.assertEquals(TokenType.EXP, TokenType.locate("EXP{ 1+1 = 2 }"));
- Assert.assertEquals(TokenType.EXP, TokenType.locate("EXP{ sum(a + b) > 1 }"));
+ @Test
+ public void testLocateValueType() {
+ Assert.assertEquals(TokenType.EXP, TokenType.locate("EXP{ 1+1 = 2 }"));
+ Assert.assertEquals(TokenType.EXP, TokenType.locate("EXP{ sum(a + b) > 1 }"));
- Assert.assertEquals(TokenType.STRING, TokenType.locate("\"\""));
- Assert.assertEquals(TokenType.STRING, TokenType.locate("\"abc\""));
+ Assert.assertEquals(TokenType.STRING, TokenType.locate("\"\""));
+ Assert.assertEquals(TokenType.STRING, TokenType.locate("\"abc\""));
- Assert.assertEquals(TokenType.LIST, TokenType.locate("(1,\"ab\")"));
- Assert.assertEquals(TokenType.LIST, TokenType.locate("(\"\",\"ab\")"));
+ Assert.assertEquals(TokenType.LIST, TokenType.locate("(1,\"ab\")"));
+ Assert.assertEquals(TokenType.LIST, TokenType.locate("(\"\",\"ab\")"));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate("1"));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate("1.234"));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate("-1.234"));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate("+1.234"));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate("- 1.234"));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate("+ 1.234"));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate(" + 1.234 "));
- Assert.assertEquals(TokenType.NUMBER, TokenType.locate(" + 1.234 "));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate("1"));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate("1.234"));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate("-1.234"));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate("+1.234"));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate("- 1.234"));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate("+ 1.234"));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate(" + 1.234 "));
+ Assert.assertEquals(TokenType.NUMBER, TokenType.locate(" + 1.234 "));
- Assert.assertEquals(TokenType.NULL, TokenType.locate("null"));
- Assert.assertEquals(TokenType.NULL, TokenType.locate("NULL"));
+ Assert.assertEquals(TokenType.NULL, TokenType.locate("null"));
+ Assert.assertEquals(TokenType.NULL, TokenType.locate("NULL"));
- Assert.assertEquals(TokenType.STRING,TokenType.locate("\"SELECT start.hr AS hr,\n" +
- " ...details.inst_type(Stage-10)\""));
+ Assert.assertEquals(TokenType.STRING,TokenType.locate("\"SELECT start.hr AS hr,\n" +
+ " ...details.inst_type(Stage-10)\""));
- // Bad format
- boolean gotEx = false;
- try{
- TokenType.locate("+ 1.234.567");
- }catch (IllegalArgumentException ex){
- gotEx = true;
- }
- Assert.assertTrue(gotEx);
- }
+ // Bad format
+ boolean gotEx = false;
+ try {
+ TokenType.locate("+ 1.234.567");
+ } catch (IllegalArgumentException ex) {
+ gotEx = true;
+ }
+ Assert.assertTrue(gotEx);
+ }
- @Test
- public void testParseExpressionContent(){
- String expression = "EXP{ @fieldName /2 } AS a";
- Assert.assertEquals(" @fieldName /2 ", TokenConstant.parseExpressionContent(expression));
+ @Test
+ public void testParseExpressionContent() {
+ String expression = "EXP{ @fieldName /2 } AS a";
+ Assert.assertEquals(" @fieldName /2 ", TokenConstant.parseExpressionContent(expression));
- expression = "EXP{ @fieldName /2 } a";
- Assert.assertEquals(" @fieldName /2 ", TokenConstant.parseExpressionContent(expression));
+ expression = "EXP{ @fieldName /2 } a";
+ Assert.assertEquals(" @fieldName /2 ", TokenConstant.parseExpressionContent(expression));
- expression = "EXP{ @fieldName /2 }";
- Assert.assertEquals(" @fieldName /2 ", TokenConstant.parseExpressionContent(expression));
- }
+ expression = "EXP{ @fieldName /2 }";
+ Assert.assertEquals(" @fieldName /2 ", TokenConstant.parseExpressionContent(expression));
+ }
}
\ No newline at end of file