Search in sources :

Example 11 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseExpression.

/**
     * Parse an expression
     *
     * @param buffer
     *            Buffer containing the string representation of the expression.
     * @param full
     *            If this parameter is true, the parse is considered to succeed
     *            only if the expression was parsed successfully and no other
     *            tokens are left.
     * @return pointer to the expression object if successful, or null otherwise
     */
public ExprTree parseExpression(String buffer, boolean full) throws IOException {
    stringLexerSource.setNewSource(buffer);
    ExprTreeHolder mutableExpr = objectPool.mutableExprPool.get();
    if (lexer.initialize(stringLexerSource)) {
        parseExpression(mutableExpr, full);
    }
    return mutableExpr.getInnerTree();
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder)

Example 12 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseInclusiveORExpression.

// InclusiveORExpression .= ExclusiveORExpression
// | InclusiveORExpression '|' ExclusiveORExpression
public boolean parseInclusiveORExpression(ExprTreeHolder tree) throws IOException {
    if (!parseExclusiveORExpression(tree)) {
        return false;
    }
    while ((lexer.peekToken()) == TokenType.LEX_BITWISE_OR) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        lexer.consumeToken();
        parseExclusiveORExpression(treeR);
        if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(Operation.OpKind_BITWISE_OR_OP, treeL, treeR, null, newTree);
            tree.setInnerTree(newTree);
        } else {
            tree.setInnerTree(null);
            return false;
        }
    }
    return true;
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Operation(org.apache.asterix.external.classad.Operation)

Example 13 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseArgumentList.

// ArgumentList .= '(' ListOfArguments ')'
// ListOfArguments .= (epsilon)
// | ListOfArguments ',' Expression
public boolean parseArgumentList(ExprList argList) throws IOException {
    TokenType tt;
    argList.clear();
    if ((tt = lexer.consumeToken()) != TokenType.LEX_OPEN_PAREN) {
        throw new HyracksDataException("expected LEX_OPEN_PAREN but got " + String.valueOf(Lexer.strLexToken(tt)));
    // return false;
    }
    tt = lexer.peekToken();
    ExprTreeHolder tree = objectPool.mutableExprPool.get();
    while (tt != TokenType.LEX_CLOSE_PAREN) {
        // parse the expression
        tree.reset();
        parseExpression(tree);
        if (tree.getInnerTree() == null) {
            argList.clear();
            return false;
        }
        // insert the expression into the argument list
        argList.add(tree.getInnerTree());
        // the next token must be a ',' or a ')'
        // or it can be a ';' if using old ClassAd semantics
        tt = lexer.peekToken();
        if (tt == TokenType.LEX_COMMA || (tt == TokenType.LEX_SEMICOLON && false)) {
            lexer.consumeToken();
        } else if (tt != TokenType.LEX_CLOSE_PAREN) {
            argList.clear();
            throw new HyracksDataException("expected LEX_COMMA or LEX_CLOSE_PAREN but got " + String.valueOf(Lexer.strLexToken(tt)));
        // return false;
        }
    }
    lexer.consumeToken();
    return true;
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 14 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method evaluateFunction.

public ExprTree evaluateFunction(String functionName, ExprList argList) throws HyracksDataException {
    Value val = objectPool.valuePool.get();
    AMutableNumberFactor factor = objectPool.numFactorPool.get();
    ExprTreeHolder tree = objectPool.mutableExprPool.get();
    ((Literal) argList.get(0)).getComponents(val, factor);
    AMutableCharArrayString string_value = objectPool.strPool.get();
    if (val.isStringValue(string_value)) {
        if (functionName.equalsIgnoreCase("absTime")) {
            tree.setInnerTree(Literal.createAbsTime(string_value, objectPool));
        } else if (functionName.equalsIgnoreCase("relTime")) {
            tree.setInnerTree(Literal.createRelTime(string_value, objectPool));
        } else {
            tree.setInnerTree(FunctionCall.createFunctionCall(functionName, argList, objectPool));
        }
    } else {
        tree.setInnerTree(FunctionCall.createFunctionCall(functionName, argList, objectPool));
    }
    return tree;
}
Also used : ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Literal(org.apache.asterix.external.classad.Literal) TokenValue(org.apache.asterix.external.classad.TokenValue) Value(org.apache.asterix.external.classad.Value) AMutableNumberFactor(org.apache.asterix.external.classad.AMutableNumberFactor) AMutableCharArrayString(org.apache.asterix.external.classad.AMutableCharArrayString)

Example 15 with ExprTreeHolder

use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.

the class ClassAdParser method parseMultiplicativeExpression.

// MultiplicativeExpression .= UnaryExpression
// | MultiplicativeExpression '*' UnaryExpression
// | MultiplicativeExpression '/' UnaryExpression
// | MultiplicativeExpression '%' UnaryExpression
private boolean parseMultiplicativeExpression(ExprTreeHolder tree) throws IOException {
    if (!parseUnaryExpression(tree)) {
        return false;
    }
    TokenType tt = lexer.peekToken();
    while (tt == TokenType.LEX_MULTIPLY || tt == TokenType.LEX_DIVIDE || tt == TokenType.LEX_MODULUS) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        int op;
        lexer.consumeToken();
        parseUnaryExpression(treeR);
        switch(tt) {
            case LEX_MULTIPLY:
                op = Operation.OpKind_MULTIPLICATION_OP;
                break;
            case LEX_DIVIDE:
                op = Operation.OpKind_DIVISION_OP;
                break;
            case LEX_MODULUS:
                op = Operation.OpKind_MODULUS_OP;
                break;
            default:
                // Make gcc's -wuninitalized happy
                op = Operation.OpKind_NO_OP;
                throw new HyracksDataException("ClassAd:  Should not reach here");
        }
        if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
            Operation newTree = objectPool.operationPool.get();
            Operation.createOperation(op, treeL, treeR, null, newTree);
            tree.setInnerTree(newTree);
        } else {
            tree.setInnerTree(null);
            return false;
        }
        tt = lexer.peekToken();
    }
    return true;
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) Operation(org.apache.asterix.external.classad.Operation) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

ExprTreeHolder (org.apache.asterix.external.classad.ExprTreeHolder)25 TokenType (org.apache.asterix.external.classad.Lexer.TokenType)13 Operation (org.apache.asterix.external.classad.Operation)13 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)13 TokenValue (org.apache.asterix.external.classad.TokenValue)5 Value (org.apache.asterix.external.classad.Value)5 ExprList (org.apache.asterix.external.classad.ExprList)2 Literal (org.apache.asterix.external.classad.Literal)2 IOException (java.io.IOException)1 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)1 AMutableNumberFactor (org.apache.asterix.external.classad.AMutableNumberFactor)1 AttributeReference (org.apache.asterix.external.classad.AttributeReference)1 ClassAd (org.apache.asterix.external.classad.ClassAd)1 ExprTree (org.apache.asterix.external.classad.ExprTree)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1