Search in sources :

Example 1 with AMutableInt64

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

the class TidRunningAggregateDescriptor method createRunningAggregateEvaluatorFactory.

@Override
public IRunningAggregateEvaluatorFactory createRunningAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args) {
    return new IRunningAggregateEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IRunningAggregateEvaluator() {

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final ISerializerDeserializer<AInt64> serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private final AMutableInt64 m = new AMutableInt64(0);

                private int cnt;

                @Override
                public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    m.setValue(cnt);
                    serde.serialize(m, resultStorage.getDataOutput());
                    result.set(resultStorage);
                    ++cnt;
                }

                @Override
                public void init() throws HyracksDataException {
                    cnt = 1;
                }
            };
        }
    };
}
Also used : IRunningAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IRunningAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Example 2 with AMutableInt64

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

the class RangeDescriptor method createUnnestingEvaluatorFactory.

@Override
public IUnnestingEvaluatorFactory createUnnestingEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IUnnestingEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IUnnestingEvaluator createUnnestingEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IUnnestingEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                @SuppressWarnings("rawtypes")
                private ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private IPointable inputVal = new VoidPointable();

                private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);

                private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);

                private AMutableInt64 aInt64 = new AMutableInt64(0);

                private long current;

                private long max;

                @Override
                public void init(IFrameTupleReference tuple) throws HyracksDataException {
                    eval0.evaluate(tuple, inputVal);
                    current = ATypeHierarchy.getLongValue(getIdentifier().getName(), 0, inputVal.getByteArray(), inputVal.getStartOffset());
                    eval1.evaluate(tuple, inputVal);
                    max = ATypeHierarchy.getLongValue(getIdentifier().getName(), 1, inputVal.getByteArray(), inputVal.getStartOffset());
                }

                @SuppressWarnings("unchecked")
                @Override
                public boolean step(IPointable result) throws HyracksDataException {
                    if (current > max) {
                        return false;
                    }
                    aInt64.setValue(current);
                    resultStorage.reset();
                    serde.serialize(aInt64, resultStorage.getDataOutput());
                    result.set(resultStorage);
                    current++;
                    return true;
                }
            };
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IUnnestingEvaluator(org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluator) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) IUnnestingEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluatorFactory) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Example 3 with AMutableInt64

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

the class Operation method doBitwise.

public static int doBitwise(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
    AMutableInt64 i1 = objectPool.int64Pool.get();
    AMutableInt64 i2 = objectPool.int64Pool.get();
    // bitwise operations are defined only on integers
    if (op == OpKind_BITWISE_NOT_OP) {
        if (!v1.isIntegerValue(i1)) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        }
    } else if (!v1.isIntegerValue(i1) || !v2.isIntegerValue(i2)) {
        result.setErrorValue();
        return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
    }
    switch(op) {
        case OpKind_BITWISE_NOT_OP:
            result.setIntegerValue(~(i1.getLongValue()));
            break;
        case OpKind_BITWISE_OR_OP:
            result.setIntegerValue(i1.getLongValue() | i2.getLongValue());
            break;
        case OpKind_BITWISE_AND_OP:
            result.setIntegerValue(i1.getLongValue() & i2.getLongValue());
            break;
        case OpKind_BITWISE_XOR_OP:
            result.setIntegerValue(i1.getLongValue() ^ i2.getLongValue());
            break;
        case OpKind_LEFT_SHIFT_OP:
            result.setIntegerValue(i1.getLongValue() << i2.getLongValue());
            break;
        case OpKind_URIGHT_SHIFT_OP:
            //               if (i1 >= 0) {
            // Could probably just use >>>
            // sign bit is not on;  >> will work fine
            result.setIntegerValue(i1.getLongValue() >>> i2.getLongValue());
            break;
        case OpKind_RIGHT_SHIFT_OP:
            // sign bit is off;  >> will work fine
            result.setIntegerValue(i1.getLongValue() >> i2.getLongValue());
            break;
        default:
            // should not get here
            throw new HyracksDataException("Should not get here");
    }
    if (op == OpKind_BITWISE_NOT_OP) {
        return SigValues.SIG_CHLD1.ordinal();
    }
    return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
Also used : AMutableInt64(org.apache.asterix.om.base.AMutableInt64) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 4 with AMutableInt64

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

the class Operation method doTimeArithmetic.

public static int doTimeArithmetic(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) {
    ClassAdTime asecs1 = objectPool.classAdTimePool.get();
    ClassAdTime asecs2 = objectPool.classAdTimePool.get();
    ValueType vt1 = v1.getType();
    ValueType vt2 = v2.getType();
    // addition
    if (op == OpKind_ADDITION_OP) {
        if (vt1 == ValueType.ABSOLUTE_TIME_VALUE && vt2 == ValueType.RELATIVE_TIME_VALUE) {
            v1.isAbsoluteTimeValue(asecs1);
            v2.isRelativeTimeValue(asecs2);
            asecs1.setValue(asecs1.getTimeInMillis() + asecs2.getTimeInMillis());
            result.setAbsoluteTimeValue(asecs1);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        if (vt1 == ValueType.RELATIVE_TIME_VALUE && vt2 == ValueType.ABSOLUTE_TIME_VALUE) {
            v1.isRelativeTimeValue(asecs1);
            v2.isAbsoluteTimeValue(asecs2);
            asecs2.setValue(asecs1.getTimeInMillis() + asecs2.getTimeInMillis());
            result.setAbsoluteTimeValue(asecs2);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        if (vt1 == ValueType.RELATIVE_TIME_VALUE && vt2 == ValueType.RELATIVE_TIME_VALUE) {
            v1.isRelativeTimeValue(asecs1);
            v2.isRelativeTimeValue(asecs2);
            result.setRelativeTimeValue(asecs1.plus(asecs2.getRelativeTime(), false));
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
    }
    if (op == OpKind_SUBTRACTION_OP) {
        if (vt1 == ValueType.ABSOLUTE_TIME_VALUE && vt2 == ValueType.ABSOLUTE_TIME_VALUE) {
            v1.isAbsoluteTimeValue(asecs1);
            v2.isAbsoluteTimeValue(asecs2);
            result.setRelativeTimeValue(asecs1.subtract(asecs2, false));
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        if (vt1 == ValueType.ABSOLUTE_TIME_VALUE && vt2 == ValueType.RELATIVE_TIME_VALUE) {
            v1.isAbsoluteTimeValue(asecs1);
            v2.isRelativeTimeValue(asecs2);
            asecs1.setValue(asecs1.getTimeInMillis() - asecs2.getRelativeTime());
            result.setAbsoluteTimeValue(asecs1);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        if (vt1 == ValueType.RELATIVE_TIME_VALUE && vt2 == ValueType.RELATIVE_TIME_VALUE) {
            v1.isRelativeTimeValue(asecs1);
            v2.isRelativeTimeValue(asecs2);
            result.setRelativeTimeValue(asecs1.subtract(asecs2));
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
    }
    if (op == OpKind_MULTIPLICATION_OP || op == OpKind_DIVISION_OP) {
        if (vt1 == ValueType.RELATIVE_TIME_VALUE && vt2 == ValueType.INTEGER_VALUE) {
            AMutableInt64 num = objectPool.int64Pool.get();
            ClassAdTime msecs = objectPool.classAdTimePool.get();
            v1.isRelativeTimeValue(asecs1);
            v2.isIntegerValue(num);
            if (op == OpKind_MULTIPLICATION_OP) {
                msecs.setValue(asecs1.multiply(num.getLongValue(), false));
            } else {
                msecs.setValue(asecs1.divide(num.getLongValue(), false));
            }
            result.setRelativeTimeValue(msecs);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        if (vt1 == ValueType.RELATIVE_TIME_VALUE && vt2 == ValueType.REAL_VALUE) {
            AMutableDouble num = objectPool.doublePool.get();
            AMutableDouble msecs = objectPool.doublePool.get();
            v1.isRelativeTimeValue(asecs1);
            v2.isRealValue(num);
            if (op == OpKind_MULTIPLICATION_OP) {
                msecs.setValue(asecs1.getRelativeTime() * num.getDoubleValue());
            } else {
                msecs.setValue(asecs1.getRelativeTime() * num.getDoubleValue());
            }
            ClassAdTime time = objectPool.classAdTimePool.get();
            time.setRelativeTime(1000L * ((long) msecs.getDoubleValue()));
            result.setRelativeTimeValue(time);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        if (vt1 == ValueType.INTEGER_VALUE && vt2 == ValueType.RELATIVE_TIME_VALUE && op == OpKind_MULTIPLICATION_OP) {
            AMutableInt64 num = objectPool.int64Pool.get();
            v1.isIntegerValue(num);
            v2.isRelativeTimeValue(asecs1);
            ClassAdTime time = objectPool.classAdTimePool.get();
            time.setRelativeTime(num.getLongValue() * asecs1.getRelativeTime());
            result.setRelativeTimeValue(time);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        if (vt2 == ValueType.RELATIVE_TIME_VALUE && vt1 == ValueType.REAL_VALUE && op == OpKind_MULTIPLICATION_OP) {
            AMutableDouble num = objectPool.doublePool.get();
            v1.isRelativeTimeValue(asecs1);
            v2.isRealValue(num);
            ClassAdTime time = objectPool.classAdTimePool.get();
            time.setRelativeTime((long) (asecs1.getRelativeTime() * num.getDoubleValue()));
            result.setRelativeTimeValue(time);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
    }
    // no other operations are supported on times
    result.setErrorValue();
    return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
Also used : ValueType(org.apache.asterix.external.classad.Value.ValueType) AMutableDouble(org.apache.asterix.om.base.AMutableDouble) AMutableInt64(org.apache.asterix.om.base.AMutableInt64)

Example 5 with AMutableInt64

use of org.apache.asterix.om.base.AMutableInt64 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)

Aggregations

AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)41 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)27 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)26 IPointable (org.apache.hyracks.data.std.api.IPointable)26 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)26 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)25 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)24 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)24 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)24 DataOutput (java.io.DataOutput)23 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)22 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)17 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)16 IOException (java.io.IOException)11 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)8 AMutableInt32 (org.apache.asterix.om.base.AMutableInt32)7 GregorianCalendarSystem (org.apache.asterix.om.base.temporal.GregorianCalendarSystem)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