Search in sources :

Example 11 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class FunctionCall method privateEvaluate.

@Override
public boolean privateEvaluate(EvalState state, Value value, ExprTreeHolder tree) throws HyracksDataException {
    FunctionCall tmpSig = objectPool.funcPool.get();
    Value tmpVal = objectPool.valuePool.get();
    ExprTreeHolder argSig = objectPool.mutableExprPool.get();
    MutableBoolean rval = objectPool.boolPool.get();
    if (!privateEvaluate(state, value)) {
        return false;
    }
    tmpSig.functionName.set(functionName.get());
    rval.setValue(true);
    for (ExprTree i : arguments.getExprList()) {
        rval.setValue(i.publicEvaluate(state, tmpVal, argSig));
        if (rval.booleanValue()) {
            tmpSig.arguments.add(argSig.getInnerTree());
        }
    }
    tree.setInnerTree(tmpSig);
    return rval.booleanValue();
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 12 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class Operation method coerceToNumber.

// This function performs type promotions so that both v1 and v2 are of the
// same numerical type: (v1 and v2 are not ERROR or UNDEFINED)
//  + if both v1 and v2 are Numbers and of the same type, return type
//  + if v1 is an int and v2 is a real, convert v1 to real; return REAL_VALUE
//  + if v1 is a real and v2 is an int, convert v2 to real; return REAL_VALUE
public static ValueType coerceToNumber(Value v1, Value v2, ClassAdObjectPool objectPool) {
    AMutableInt64 i = objectPool.int64Pool.get();
    AMutableDouble r = objectPool.doublePool.get();
    MutableBoolean b = objectPool.boolPool.get();
    // either of v1, v2 not numerical?
    if (v1.isClassAdValue() || v2.isClassAdValue()) {
        return ValueType.CLASSAD_VALUE;
    }
    if (v1.isListValue() || v2.isListValue()) {
        return ValueType.LIST_VALUE;
    }
    if (v1.isStringValue() || v2.isStringValue()) {
        return ValueType.STRING_VALUE;
    }
    if (v1.isUndefinedValue() || v2.isUndefinedValue()) {
        return ValueType.UNDEFINED_VALUE;
    }
    if (v1.isErrorValue() || v2.isErrorValue()) {
        return ValueType.ERROR_VALUE;
    }
    if (v1.isAbsoluteTimeValue() || v2.isAbsoluteTimeValue()) {
        return ValueType.ABSOLUTE_TIME_VALUE;
    }
    if (v1.isRelativeTimeValue() || v2.isRelativeTimeValue()) {
        return ValueType.RELATIVE_TIME_VALUE;
    }
    // promote booleans to integers
    if (v1.isBooleanValue(b)) {
        if (b.booleanValue()) {
            v1.setIntegerValue(1);
        } else {
            v1.setIntegerValue(0);
        }
    }
    if (v2.isBooleanValue(b)) {
        if (b.booleanValue()) {
            v2.setIntegerValue(1);
        } else {
            v2.setIntegerValue(0);
        }
    }
    // both v1 and v2 of same numerical type
    if (v1.isIntegerValue(i) && v2.isIntegerValue(i)) {
        return ValueType.INTEGER_VALUE;
    }
    if (v1.isRealValue(r) && v2.isRealValue(r)) {
        return ValueType.REAL_VALUE;
    }
    // type promotions required
    if (v1.isIntegerValue(i) && v2.isRealValue(r)) {
        v1.setRealValue(i.getLongValue());
    } else if (v1.isRealValue(r) && v2.isIntegerValue(i)) {
        v2.setRealValue(i.getLongValue());
    }
    return ValueType.REAL_VALUE;
}
Also used : AMutableDouble(org.apache.asterix.om.base.AMutableDouble) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) AMutableInt64(org.apache.asterix.om.base.AMutableInt64)

Example 13 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class AttributeReference method privateEvaluate.

@Override
public boolean privateEvaluate(EvalState state, Value val, ExprTreeHolder sig) throws HyracksDataException {
    ExprTreeHolder tree = objectPool.mutableExprPool.get();
    ExprTreeHolder exprSig = objectPool.mutableExprPool.get();
    ClassAd curAd = objectPool.classAdPool.get();
    curAd.copyFrom(state.getCurAd());
    MutableBoolean rval = objectPool.boolPool.get();
    rval.setValue(true);
    switch(findExpr(state, tree, exprSig, true)) {
        case EVAL_FAIL:
            rval.setValue(false);
            break;
        case EVAL_ERROR:
            val.setErrorValue();
            break;
        case EVAL_UNDEF:
            val.setUndefinedValue();
            break;
        case EVAL_OK:
            {
                if (state.getDepthRemaining() <= 0) {
                    val.setErrorValue();
                    state.getCurAd().setValue(curAd);
                    return false;
                }
                state.decrementDepth();
                rval.setValue(tree.publicEvaluate(state, val));
                state.incrementDepth();
                break;
            }
        default:
            throw new HyracksDataException("ClassAd:  Should not reach here");
    }
    AttributeReference newAttrRef = objectPool.attrRefPool.get();
    newAttrRef.setValue(exprSig, attributeStr, absolute);
    sig.setInnerTree(newAttrRef);
    state.getCurAd().setValue(curAd);
    return rval.booleanValue();
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 14 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class ClassAdParser method parsePrimaryExpression.

// PrimaryExpression .= Identifier
// | FunctionCall
// | '.' Identifier
// | '(' Expression ')'
// | Literal
// FunctionCall .= Identifier ArgumentList
// ( Constant may be
// boolean,undefined,error,string,integer,real,classad,list )
// ( ArgumentList non-terminal includes parentheses )
private boolean parsePrimaryExpression(ExprTreeHolder tree) throws IOException {
    ExprTreeHolder treeL;
    TokenValue tv = objectPool.tokenValuePool.get();
    TokenType tt;
    tree.setInnerTree(null);
    switch((tt = lexer.peekToken(tv))) {
        // identifiers
        case LEX_IDENTIFIER:
            isExpr = true;
            lexer.consumeToken();
            // check for funcion call
            if ((tt = lexer.peekToken()) == TokenType.LEX_OPEN_PAREN) {
                ExprList argList = objectPool.exprListPool.get();
                if (!parseArgumentList(argList)) {
                    tree.setInnerTree(null);
                    return false;
                }
                ;
                // string literal
                if (shouldEvaluateAtParseTime(tv.getStrValue().toString(), argList)) {
                    tree.setInnerTree(evaluateFunction(tv.getStrValue().toString(), argList));
                } else {
                    tree.setInnerTree(FunctionCall.createFunctionCall(tv.getStrValue().toString(), argList, objectPool));
                }
            } else {
                // I don't think this is ever hit
                tree.setInnerTree(AttributeReference.createAttributeReference(null, tv.getStrValue(), false, objectPool));
            }
            return (tree.getInnerTree() != null);
        case LEX_SELECTION:
            isExpr = true;
            lexer.consumeToken();
            if ((tt = lexer.consumeToken(tv)) == TokenType.LEX_IDENTIFIER) {
                // the boolean final arg signifies that reference is absolute
                tree.setInnerTree(AttributeReference.createAttributeReference(null, tv.getStrValue(), true, objectPool));
                return (tree.size() != 0);
            }
            // not an identifier following the '.'
            throw new HyracksDataException("need identifier in selection expression (got" + Lexer.strLexToken(tt) + ")");
        // parenthesized expression
        case LEX_OPEN_PAREN:
            {
                isExpr = true;
                lexer.consumeToken();
                treeL = objectPool.mutableExprPool.get();
                parseExpression(treeL);
                if (treeL.getInnerTree() == null) {
                    tree.resetExprTree(null);
                    return false;
                }
                if ((tt = lexer.consumeToken()) != TokenType.LEX_CLOSE_PAREN) {
                    throw new HyracksDataException("exptected LEX_CLOSE_PAREN, but got " + Lexer.strLexToken(tt));
                // tree.resetExprTree(null);
                // return false;
                }
                // assume make operation will return a new tree
                tree.setInnerTree(Operation.createOperation(Operation.OpKind_PARENTHESES_OP, treeL, objectPool));
                return (tree.size() != 0);
            }
        // constants
        case LEX_OPEN_BOX:
            {
                isExpr = true;
                ClassAd newAd = objectPool.classAdPool.get();
                if (!parseClassAd(newAd)) {
                    tree.resetExprTree(null);
                    return false;
                }
                tree.setInnerTree(newAd);
            }
            return true;
        case LEX_OPEN_BRACE:
            {
                isExpr = true;
                ExprList newList = objectPool.exprListPool.get();
                if (!parseExprList(newList)) {
                    tree.setInnerTree(null);
                    return false;
                }
                tree.setInnerTree(newList);
            }
            return true;
        case LEX_UNDEFINED_VALUE:
            {
                Value val = objectPool.valuePool.get();
                lexer.consumeToken();
                val.setUndefinedValue();
                tree.setInnerTree(Literal.createLiteral(val, objectPool));
                return (tree.getInnerTree() != null);
            }
        case LEX_ERROR_VALUE:
            {
                Value val = objectPool.valuePool.get();
                lexer.consumeToken();
                val.setErrorValue();
                tree.setInnerTree(Literal.createLiteral(val, objectPool));
                return (tree.getInnerTree() != null);
            }
        case LEX_BOOLEAN_VALUE:
            {
                Value val = objectPool.valuePool.get();
                MutableBoolean b = new MutableBoolean();
                tv.getBoolValue(b);
                lexer.consumeToken();
                val.setBooleanValue(b);
                tree.setInnerTree(Literal.createLiteral(val, objectPool));
                return (tree.getInnerTree() != null);
            }
        case LEX_INTEGER_VALUE:
            {
                Value val = objectPool.valuePool.get();
                lexer.consumeToken();
                val.setIntegerValue(tv.getIntValue());
                tree.setInnerTree(Literal.createLiteral(val, tv.getFactor(), objectPool));
                return (tree.getInnerTree() != null);
            }
        case LEX_REAL_VALUE:
            {
                Value val = objectPool.valuePool.get();
                lexer.consumeToken();
                val.setRealValue(tv.getRealValue());
                tree.setInnerTree(Literal.createLiteral(val, tv.getFactor(), objectPool));
                return (tree.getInnerTree() != null);
            }
        case LEX_STRING_VALUE:
            {
                Value val = objectPool.valuePool.get();
                lexer.consumeToken();
                val.setStringValue(tv.getStrValue());
                tree.setInnerTree(Literal.createLiteral(val, objectPool));
                return (tree.getInnerTree() != null);
            }
        case LEX_ABSOLUTE_TIME_VALUE:
            {
                Value val = objectPool.valuePool.get();
                lexer.consumeToken();
                val.setAbsoluteTimeValue(tv.getTimeValue());
                tree.setInnerTree(Literal.createLiteral(val, objectPool));
                return (tree.getInnerTree() != null);
            }
        case LEX_RELATIVE_TIME_VALUE:
            {
                Value val = objectPool.valuePool.get();
                lexer.consumeToken();
                val.setRelativeTimeValue(tv.getTimeValue().getRelativeTime());
                tree.setInnerTree(Literal.createLiteral(val, objectPool));
                return (tree.getInnerTree() != null);
            }
        default:
            tree.setInnerTree(null);
            return false;
    }
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ClassAd(org.apache.asterix.external.classad.ClassAd) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) ExprList(org.apache.asterix.external.classad.ExprList) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) TokenValue(org.apache.asterix.external.classad.TokenValue) Value(org.apache.asterix.external.classad.Value) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) TokenValue(org.apache.asterix.external.classad.TokenValue)

Example 15 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project sling by apache.

the class PollingTest method testCallableOnce.

//
// Tests with Callable
//
@Test
public void testCallableOnce() throws Exception {
    final MutableInt callCount = new MutableInt(0);
    final MutableBoolean called = new MutableBoolean(false);
    Polling p = new Polling(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            callCount.increment();
            return true;
        }
    });
    p.poll(500, 10);
    assertEquals(1, callCount.intValue());
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)28 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 Test (org.junit.Test)7 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)6 IOException (java.io.IOException)4 ClassAd (org.apache.asterix.external.classad.ClassAd)4 MutableInt (org.apache.commons.lang3.mutable.MutableInt)4 CompilationException (org.apache.asterix.common.exceptions.CompilationException)3 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)3 ExprList (org.apache.asterix.external.classad.ExprList)3 Value (org.apache.asterix.external.classad.Value)3 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 TimeoutException (java.util.concurrent.TimeoutException)2 ResultHandle (org.apache.asterix.app.result.ResultHandle)2 ACIDException (org.apache.asterix.common.exceptions.ACIDException)2 AsterixException (org.apache.asterix.common.exceptions.AsterixException)2 IDataset (org.apache.asterix.common.metadata.IDataset)2 ExprTree (org.apache.asterix.external.classad.ExprTree)2