Search in sources :

Example 1 with Operator

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator 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;
}
Also used : Operator(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList) TimelineCompareOp(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareOp) TimelinePrefixFilter(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelinePrefixFilter)

Example 2 with Operator

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator in project hadoop by apache.

the class TimelineParserForCompareExpr method parseOp.

private void parseOp(boolean closingBracket) throws TimelineParseException {
    Operator operator = null;
    if (exprInLowerCase.startsWith("or ", offset)) {
        operator = Operator.OR;
        offset = offset + 3;
    } else if (exprInLowerCase.startsWith("and ", offset)) {
        operator = Operator.AND;
        offset = offset + 4;
    }
    if (operator == null) {
        throw new TimelineParseException("Operator cannot be parsed for " + exprName + ".");
    }
    if (filterList == null) {
        filterList = new TimelineFilterList(operator);
    }
    if (currentFilter != null) {
        filterList.addFilter(currentFilter);
    }
    if (closingBracket || filterList.getOperator() != operator) {
        filterList = new TimelineFilterList(operator, filterList);
    }
    currentFilter = null;
    kvStartOffset = offset;
    currentParseState = ParseState.PARSING_KEY;
}
Also used : Operator(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList)

Example 3 with Operator

use of org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator in project hadoop by apache.

the class TimelineParserForEqualityExpr method parseOp.

private void parseOp(boolean closingBracket) throws TimelineParseException {
    Operator operator = null;
    if (exprInLowerCase.startsWith("or ", offset)) {
        operator = Operator.OR;
        offset = offset + 3;
    } else if (exprInLowerCase.startsWith("and ", offset)) {
        operator = Operator.AND;
        offset = offset + 4;
    }
    if (operator == null) {
        throw new TimelineParseException("Operator cannot be parsed for " + exprName + ".");
    }
    if (filterList == null) {
        filterList = new TimelineFilterList(operator);
    }
    if (currentFilter != null) {
        filterList.addFilter(currentFilter);
    }
    if (closingBracket || filterList.getOperator() != operator) {
        filterList = new TimelineFilterList(operator, filterList);
    }
    currentFilter = null;
    startOffset = offset;
    currentParseState = ParseState.PARSING_COMPAREOP;
}
Also used : Operator(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator) TimelineFilterList(org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList)

Aggregations

TimelineFilterList (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList)3 Operator (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineFilterList.Operator)3 TimelineCompareOp (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineCompareOp)1 TimelinePrefixFilter (org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelinePrefixFilter)1