Search in sources :

Example 11 with AMutableInt32

use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.

the class RangeMapBuilder method parseLiteralToBytes.

@SuppressWarnings("unchecked")
private static void parseLiteralToBytes(Expression item, DataOutput out) throws CompilationException {
    AMutableDouble aDouble = new AMutableDouble(0);
    AMutableFloat aFloat = new AMutableFloat(0);
    AMutableInt64 aInt64 = new AMutableInt64(0);
    AMutableInt32 aInt32 = new AMutableInt32(0);
    AMutableString aString = new AMutableString("");
    @SuppressWarnings("rawtypes") ISerializerDeserializer serde;
    Literal l = ((LiteralExpr) item).getValue();
    try {
        switch(l.getLiteralType()) {
            case DOUBLE:
                DoubleLiteral dl = (DoubleLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
                aDouble.setValue(dl.getValue());
                serde.serialize(aDouble, out);
                break;
            case FLOAT:
                FloatLiteral fl = (FloatLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
                aFloat.setValue(fl.getValue());
                serde.serialize(aFloat, out);
                break;
            case INTEGER:
                IntegerLiteral il = (IntegerLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
                aInt32.setValue(il.getValue());
                serde.serialize(aInt32, out);
                break;
            case LONG:
                LongIntegerLiteral lil = (LongIntegerLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
                aInt64.setValue(lil.getValue());
                serde.serialize(aInt64, out);
                break;
            case STRING:
                StringLiteral sl = (StringLiteral) l;
                serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
                aString.setValue(sl.getValue());
                serde.serialize(aString, out);
                break;
            default:
                throw new NotImplementedException("The range map builder has not been implemented for " + item.getKind() + " type of expressions.");
        }
    } catch (HyracksDataException e) {
        throw new CompilationException(e.getMessage());
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) FloatLiteral(org.apache.asterix.lang.common.literal.FloatLiteral) NotImplementedException(org.apache.hyracks.algebricks.common.exceptions.NotImplementedException) AMutableString(org.apache.asterix.om.base.AMutableString) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) LongIntegerLiteral(org.apache.asterix.lang.common.literal.LongIntegerLiteral) AMutableDouble(org.apache.asterix.om.base.AMutableDouble) Literal(org.apache.asterix.lang.common.base.Literal) StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) IntegerLiteral(org.apache.asterix.lang.common.literal.IntegerLiteral) FloatLiteral(org.apache.asterix.lang.common.literal.FloatLiteral) DoubleLiteral(org.apache.asterix.lang.common.literal.DoubleLiteral) LongIntegerLiteral(org.apache.asterix.lang.common.literal.LongIntegerLiteral) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) DoubleLiteral(org.apache.asterix.lang.common.literal.DoubleLiteral) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) AMutableInt32(org.apache.asterix.om.base.AMutableInt32) AMutableFloat(org.apache.asterix.om.base.AMutableFloat) IntegerLiteral(org.apache.asterix.lang.common.literal.IntegerLiteral) LongIntegerLiteral(org.apache.asterix.lang.common.literal.LongIntegerLiteral)

Example 12 with AMutableInt32

use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.

the class Operation method privateEvaluate.

@Override
public boolean privateEvaluate(EvalState state, Value result, ExprTreeHolder tree) throws HyracksDataException {
    int sig;
    Value val1 = objectPool.valuePool.get();
    Value val2 = objectPool.valuePool.get();
    Value val3 = objectPool.valuePool.get();
    ExprTreeHolder t1 = objectPool.mutableExprPool.get();
    ExprTreeHolder t2 = objectPool.mutableExprPool.get();
    ExprTreeHolder t3 = objectPool.mutableExprPool.get();
    boolean valid1 = false, valid2 = false, valid3 = false;
    AMutableInt32 opKind = objectPool.int32Pool.get();
    ExprTreeHolder child1 = objectPool.mutableExprPool.get();
    ExprTreeHolder child2 = objectPool.mutableExprPool.get();
    ExprTreeHolder child3 = objectPool.mutableExprPool.get();
    getComponents(opKind, child1, child2, child3);
    // Evaluate all valid children
    tree = objectPool.mutableExprPool.get();
    if (child1.getInnerTree() != null) {
        if (!child1.publicEvaluate(state, val1, t1)) {
            result.setErrorValue();
            return (false);
        }
        valid1 = true;
    }
    if (child2.getInnerTree() != null) {
        if (!child2.publicEvaluate(state, val2, t2)) {
            result.setErrorValue();
            return (false);
        }
        valid2 = true;
    }
    if (child3.getInnerTree() != null) {
        if (!child3.publicEvaluate(state, val3, t3)) {
            result.setErrorValue();
            return (false);
        }
        valid3 = true;
    }
    // do evaluation
    sig = privateDoOperation(opKind.getIntegerValue(), val1, val2, val3, valid1, valid2, valid3, result, state, objectPool);
    // delete trees which were not significant
    if (valid1 && 0 != (sig & SigValues.SIG_CHLD1.ordinal())) {
        t1 = null;
    }
    if (valid2 && 0 != (sig & SigValues.SIG_CHLD2.ordinal())) {
        t2 = null;
    }
    if (valid3 && 0 != (sig & SigValues.SIG_CHLD3.ordinal())) {
        t3 = null;
    }
    if (sig == SigValues.SIG_NONE.ordinal()) {
        result.setErrorValue();
        tree.setInnerTree(null);
        ;
        return (false);
    }
    // corresponding value is UNDEFINED or ERROR, propagate only that tree
    if (isStrictOperator(opKind.getIntegerValue())) {
        // strict unary operators:  unary -, unary +, !, ~, ()
        if (opKind.getIntegerValue() == OpKind_UNARY_MINUS_OP || opKind.getIntegerValue() == OpKind_UNARY_PLUS_OP || opKind.getIntegerValue() == OpKind_LOGICAL_NOT_OP || opKind.getIntegerValue() == OpKind_BITWISE_NOT_OP || opKind.getIntegerValue() == OpKind_PARENTHESES_OP) {
            if (val1.isExceptional()) {
                // the operator is only propagating the value;  only the
                // subexpression is significant
                tree.setInnerTree(t1);
            } else {
                // the node operated on the value; the operator is also
                // significant
                tree.setInnerTree(createOperation(opKind.getIntegerValue(), t1, objectPool));
            }
            return (true);
        } else {
            // strict binary operators
            if (val1.isExceptional() || val2.isExceptional()) {
                // exceptional values are only being propagated
                if (0 != (SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD1.ordinal())) {
                    tree.setInnerTree(t1);
                    return (true);
                } else if (0 != (SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD2.ordinal())) {
                    tree.setInnerTree(t2);
                    return (true);
                }
                throw new HyracksDataException("Should not reach here");
            } else {
                // the node is also significant
                tree.setInnerTree(createOperation(opKind.getIntegerValue(), t1, t2, objectPool));
                return (true);
            }
        }
    } else {
        // non-strict operators
        if (opKind.getIntegerValue() == OpKind_IS_OP || opKind.getIntegerValue() == OpKind_ISNT_OP) {
            // the operation is *always* significant for IS and ISNT
            tree.setInnerTree(createOperation(opKind.getIntegerValue(), t1, t2, objectPool));
            return (true);
        }
        // other non-strict binary operators
        if (opKind.getIntegerValue() == OpKind_LOGICAL_AND_OP || opKind.getIntegerValue() == OpKind_LOGICAL_OR_OP) {
            if ((SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD1.ordinal()) != 0 && (SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD2.ordinal()) != 0) {
                tree.setInnerTree(createOperation(opKind.getIntegerValue(), t1, t2, objectPool));
                return (true);
            } else if ((SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD1.ordinal()) != 0) {
                tree.setInnerTree(t1);
                return (true);
            } else if ((SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD2.ordinal()) != 0) {
                tree.setInnerTree(t2);
                return (true);
            } else {
                throw new HyracksDataException("Shouldn't reach here");
            }
        }
        // selector is always significant (???)
        if (opKind.getIntegerValue() == OpKind_TERNARY_OP) {
            Value tmpVal = objectPool.valuePool.get();
            tmpVal.setUndefinedValue();
            tree.setInnerTree(Literal.createLiteral(tmpVal, objectPool));
            // "true" consequent taken
            if ((SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD2.ordinal()) != 0) {
                tree.setInnerTree(t2);
                return (true);
            } else if ((SigValues.values()[sig].ordinal() & SigValues.SIG_CHLD3.ordinal()) != 0) {
                tree.setInnerTree(t3);
                return (true);
            }
            // neither consequent; selector was exceptional; return ( s )
            tree.setInnerTree(t1);
            return (true);
        }
    }
    throw new HyracksDataException("Should not reach here");
}
Also used : AMutableInt32(org.apache.asterix.om.base.AMutableInt32) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 13 with AMutableInt32

use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.

the class Operation method privateEvaluate.

@Override
public boolean privateEvaluate(EvalState state, Value result) throws HyracksDataException {
    Value val1 = objectPool.valuePool.get();
    Value val2 = objectPool.valuePool.get();
    Value val3 = objectPool.valuePool.get();
    boolean valid1, valid2, valid3;
    int rval = 0;
    valid1 = false;
    valid2 = false;
    valid3 = false;
    AMutableInt32 operationKind = objectPool.int32Pool.get();
    ExprTreeHolder child1 = objectPool.mutableExprPool.get();
    ExprTreeHolder child2 = objectPool.mutableExprPool.get();
    ExprTreeHolder child3 = objectPool.mutableExprPool.get();
    getComponents(operationKind, child1, child2, child3);
    // Evaluate all valid children
    if (child1.getInnerTree() != null) {
        if (!child1.publicEvaluate(state, val1)) {
            result.setErrorValue();
            return (false);
        }
        valid1 = true;
        if (shortCircuit(state, val1, result)) {
            return true;
        }
    }
    if (child2.getInnerTree() != null) {
        if (!child2.publicEvaluate(state, val2)) {
            result.setErrorValue();
            return (false);
        }
        valid2 = true;
    }
    if (child3.getInnerTree() != null) {
        if (!child3.publicEvaluate(state, val3)) {
            result.setErrorValue();
            return (false);
        }
        valid3 = true;
    }
    rval = privateDoOperation(opKind, val1, val2, val3, valid1, valid2, valid3, result, state, objectPool);
    return (rval != SigValues.SIG_NONE.ordinal());
}
Also used : AMutableInt32(org.apache.asterix.om.base.AMutableInt32)

Example 14 with AMutableInt32

use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.

the class PrettyPrint method unparseAux.

@Override
public void unparseAux(AMutableCharArrayString buffer, int op, ExprTreeHolder op1, ExprTreeHolder op2, ExprTreeHolder op3) throws HyracksDataException {
    if (!minimalParens) {
        super.unparseAux(buffer, op, op1, op2, op3);
        return;
    }
    // case 0: parentheses op
    if (op == Operation.OpKind_PARENTHESES_OP) {
        unparse(buffer, op1);
        return;
    }
    // case 1: check for unary ops
    if (op == Operation.OpKind_UNARY_PLUS_OP || op == Operation.OpKind_UNARY_MINUS_OP || op == Operation.OpKind_LOGICAL_NOT_OP || op == Operation.OpKind_BITWISE_NOT_OP) {
        buffer.appendString(opString[op]);
        unparse(buffer, op1);
        return;
    }
    // case 2: check for ternary op
    if (op == Operation.OpKind_TERNARY_OP) {
        unparse(buffer, op1);
        buffer.appendString(" ? ");
        unparse(buffer, op2);
        buffer.appendString(" : ");
        unparse(buffer, op3);
        return;
    }
    // case 3: check for subscript op
    if (op == Operation.OpKind_SUBSCRIPT_OP) {
        unparse(buffer, op1);
        buffer.appendChar('[');
        unparse(buffer, op2);
        buffer.appendChar(']');
        return;
    }
    // all others are binary ops
    AMutableInt32 top = objectPool.int32Pool.get();
    ExprTreeHolder t1 = objectPool.mutableExprPool.get(), t2 = objectPool.mutableExprPool.get(), t3 = objectPool.mutableExprPool.get();
    if (op1.getKind() == NodeKind.OP_NODE) {
        ((Operation) op1.getInnerTree()).getComponents(top, t1, t2, t3);
        if (Operation.precedenceLevel(top.getIntegerValue()) < Operation.precedenceLevel(op)) {
            buffer.appendString(" ( ");
            unparseAux(buffer, top.getIntegerValue(), t1, t2, t3);
            buffer.appendString(" ) ");
        }
    } else {
        unparse(buffer, op1);
    }
    buffer.appendString(opString[op]);
    if (op2.getKind() == NodeKind.OP_NODE) {
        ((Operation) op2.getInnerTree()).getComponents(top, t1, t2, t3);
        if (Operation.precedenceLevel(top.getIntegerValue()) < Operation.precedenceLevel(op)) {
            buffer.appendString(" ( ");
            unparseAux(buffer, top.getIntegerValue(), t1, t2, t3);
            buffer.appendString(" ) ");
        }
    } else {
        unparse(buffer, op2);
    }
}
Also used : AMutableInt32(org.apache.asterix.om.base.AMutableInt32)

Example 15 with AMutableInt32

use of org.apache.asterix.om.base.AMutableInt32 in project asterixdb by apache.

the class Operation method privateFlatten.

@Override
public boolean privateFlatten(EvalState state, Value val, ExprTreeHolder tree, AMutableInt32 opPtr) throws HyracksDataException {
    AMutableInt32 childOp1 = objectPool.int32Pool.get();
    childOp1.setValue(OpKind_NO_OP);
    AMutableInt32 childOp2 = objectPool.int32Pool.get();
    childOp2.setValue(OpKind_NO_OP);
    ExprTreeHolder fChild1 = objectPool.mutableExprPool.get();
    ExprTreeHolder fChild2 = objectPool.mutableExprPool.get();
    ;
    Value val1 = objectPool.valuePool.get();
    Value val2 = objectPool.valuePool.get();
    Value val3 = objectPool.valuePool.get();
    AMutableInt32 newOp = objectPool.int32Pool.get();
    newOp.setValue(opKind);
    int op = opKind;
    // Just to be safe...  wenger 2003-12-11.
    tree.setInnerTree(null);
    // Just to be safe...  wenger 2003-12-11.
    ;
    // if op is binary, but not associative or commutative, disallow splitting
    if ((op >= OpKind_COMPARISON_START && op <= OpKind_COMPARISON_END) || op == OpKind_SUBTRACTION_OP || op == OpKind_DIVISION_OP || op == OpKind_MODULUS_OP || op == OpKind_LEFT_SHIFT_OP || op == OpKind_RIGHT_SHIFT_OP || op == OpKind_URIGHT_SHIFT_OP) {
        if (opPtr != null) {
            opPtr.setValue(OpKind_NO_OP);
        }
        if (child1.publicFlatten(state, val1, fChild1) && child2.publicFlatten(state, val2, fChild2)) {
            if (fChild1.getInnerTree() == null && fChild2.getInnerTree() == null) {
                privateDoOperation(op, val1, val2, val3, true, true, false, val, objectPool);
                tree.setInnerTree(null);
                return true;
            } else if (fChild1.getInnerTree() != null && fChild2.getInnerTree() != null) {
                tree.setInnerTree(Operation.createOperation(op, fChild1, fChild2, objectPool));
                return true;
            } else if (fChild1.getInnerTree() != null) {
                tree.setInnerTree(Operation.createOperation(op, fChild1, val2, objectPool));
                return true;
            } else if (fChild2.getInnerTree() != null) {
                tree.setInnerTree(Operation.createOperation(op, val1, fChild2, objectPool));
                return true;
            }
        } else {
            tree.setInnerTree(null);
            return false;
        }
    } else // now catch all non-binary operators
    if (op == OpKind_TERNARY_OP || op == OpKind_SUBSCRIPT_OP || op == OpKind_UNARY_PLUS_OP || op == OpKind_UNARY_MINUS_OP || op == OpKind_PARENTHESES_OP || op == OpKind_LOGICAL_NOT_OP || op == OpKind_BITWISE_NOT_OP) {
        return flattenSpecials(state, val, tree);
    }
    // Flatten sub expressions
    if ((child1.getInnerTree() != null && !child1.publicFlatten(state, val1, fChild1, childOp1)) || (child2.getInnerTree() != null && !child2.publicFlatten(state, val2, fChild2, childOp2))) {
        tree.setInnerTree(null);
        return false;
    }
    // included in tree
    if (!combine(newOp, val, tree, childOp1, val1, fChild1, childOp2, val2, fChild2)) {
        tree.setInnerTree(null);
        if (opPtr != null) {
            opPtr.setValue(OpKind_NO_OP);
        }
        return false;
    }
    // if splitting is disallowed, fold the value and tree into a tree
    if (opPtr == null && newOp.getIntegerValue() != OpKind_NO_OP) {
        tree.setInnerTree(Operation.createOperation(newOp.getIntegerValue(), val, tree, objectPool));
        if (tree.getInnerTree() == null) {
            return false;
        }
        return true;
    } else if (opPtr != null) {
        opPtr.setValue(newOp.getIntegerValue());
    }
    return true;
}
Also used : AMutableInt32(org.apache.asterix.om.base.AMutableInt32)

Aggregations

AMutableInt32 (org.apache.asterix.om.base.AMutableInt32)18 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)9 DataOutput (java.io.DataOutput)8 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)8 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)8 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)8 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)8 IPointable (org.apache.hyracks.data.std.api.IPointable)8 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)8 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)8 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)8 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)7 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)7 AMutableFloat (org.apache.asterix.om.base.AMutableFloat)6 AMutableInt16 (org.apache.asterix.om.base.AMutableInt16)5 AMutableInt8 (org.apache.asterix.om.base.AMutableInt8)5 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 IOException (java.io.IOException)3 AMutableString (org.apache.asterix.om.base.AMutableString)2 ATypeTag (org.apache.asterix.om.types.ATypeTag)2