use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareOp in project hadoop by apache.
the class TimelineParserForCompareExpr method parseCompareOp.
private void parseCompareOp() throws TimelineParseException {
if (offset + 2 >= exprLength) {
throw new TimelineParseException("Compare op cannot be parsed for " + exprName + ".");
}
TimelineCompareOp compareOp = null;
boolean keyExistFlag = true;
if (expr.charAt(offset + 2) == TimelineParseConstants.SPACE_CHAR) {
if (exprInLowerCase.startsWith("eq", offset)) {
compareOp = TimelineCompareOp.EQUAL;
} else if (exprInLowerCase.startsWith("ne", offset)) {
compareOp = TimelineCompareOp.NOT_EQUAL;
keyExistFlag = false;
} else if (exprInLowerCase.startsWith("lt", offset)) {
compareOp = TimelineCompareOp.LESS_THAN;
} else if (exprInLowerCase.startsWith("le", offset)) {
compareOp = TimelineCompareOp.LESS_OR_EQUAL;
} else if (exprInLowerCase.startsWith("gt", offset)) {
compareOp = TimelineCompareOp.GREATER_THAN;
} else if (exprInLowerCase.startsWith("ge", offset)) {
compareOp = TimelineCompareOp.GREATER_OR_EQUAL;
}
offset = offset + 3;
} else if (exprInLowerCase.startsWith("ene ", offset)) {
// Not equal but key should be present.
compareOp = TimelineCompareOp.NOT_EQUAL;
offset = offset + 4;
}
if (compareOp == null) {
throw new TimelineParseException("Compare op cannot be parsed for " + exprName + ".");
}
setCompareOpToCurrentFilter(compareOp, keyExistFlag);
kvStartOffset = offset;
currentParseState = ParseState.PARSING_VALUE;
}
use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareOp in project hadoop by apache.
the class TimelineParserForDataToRetrieve method parse.
@Override
public TimelineFilterList parse() throws TimelineParseException {
if (expr == null || exprLength == 0) {
return null;
}
TimelineCompareOp compareOp = null;
int openingBracketIndex = expr.indexOf(TimelineParseConstants.OPENING_BRACKET_CHAR);
if (expr.charAt(0) == TimelineParseConstants.NOT_CHAR) {
if (openingBracketIndex == -1) {
throw new TimelineParseException("Invalid config/metric to retrieve " + "expression");
}
if (openingBracketIndex != 1 && expr.substring(1, openingBracketIndex + 1).trim().length() != 1) {
throw new TimelineParseException("Invalid config/metric to retrieve " + "expression");
}
compareOp = TimelineCompareOp.NOT_EQUAL;
} else if (openingBracketIndex <= 0) {
compareOp = TimelineCompareOp.EQUAL;
}
char lastChar = expr.charAt(exprLength - 1);
if (compareOp == TimelineCompareOp.NOT_EQUAL && lastChar != TimelineParseConstants.CLOSING_BRACKET_CHAR) {
throw new TimelineParseException("Invalid config/metric to retrieve " + "expression");
}
if (openingBracketIndex != -1 && expr.charAt(exprLength - 1) == TimelineParseConstants.CLOSING_BRACKET_CHAR) {
expr = expr.substring(openingBracketIndex + 1, exprLength - 1).trim();
}
if (expr.isEmpty()) {
return null;
}
Operator op = (compareOp == TimelineCompareOp.NOT_EQUAL) ? Operator.AND : Operator.OR;
TimelineFilterList list = new TimelineFilterList(op);
String[] splits = expr.split(TimelineParseConstants.COMMA_DELIMITER);
for (String split : splits) {
list.addFilter(new TimelinePrefixFilter(compareOp, split.trim()));
}
return list;
}
Aggregations