Search in sources :

Example 16 with AMutableDouble

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

the class Operation method compareReals.

public static void compareReals(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
    AMutableDouble r1 = objectPool.doublePool.get();
    AMutableDouble r2 = objectPool.doublePool.get();
    boolean compResult = false;
    v1.isRealValue(r1);
    v2.isRealValue(r2);
    switch(op) {
        case OpKind_LESS_THAN_OP:
            compResult = (r1.getDoubleValue() < r2.getDoubleValue());
            break;
        case OpKind_LESS_OR_EQUAL_OP:
            compResult = (r1.getDoubleValue() <= r2.getDoubleValue());
            break;
        case OpKind_EQUAL_OP:
            compResult = (r1.getDoubleValue() == r2.getDoubleValue());
            break;
        case OpKind_META_EQUAL_OP:
            compResult = (r1.getDoubleValue() == r2.getDoubleValue());
            break;
        case OpKind_NOT_EQUAL_OP:
            compResult = (r1.getDoubleValue() != r2.getDoubleValue());
            break;
        case OpKind_META_NOT_EQUAL_OP:
            compResult = (r1.getDoubleValue() != r2.getDoubleValue());
            break;
        case OpKind_GREATER_THAN_OP:
            compResult = (r1.getDoubleValue() > r2.getDoubleValue());
            break;
        case OpKind_GREATER_OR_EQUAL_OP:
            compResult = (r1.getDoubleValue() >= r2.getDoubleValue());
            break;
        default:
            // should not get here
            throw new HyracksDataException("Should not get here");
    }
    result.setBooleanValue(compResult);
}
Also used : AMutableDouble(org.apache.asterix.om.base.AMutableDouble) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 17 with AMutableDouble

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

the class Operation method doRealArithmetic.

public static int doRealArithmetic(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
    AMutableDouble r1 = objectPool.doublePool.get();
    AMutableDouble r2 = objectPool.doublePool.get();
    double comp = 0;
    // we want to prevent FPE and set the ERROR value on the result; on Unix
    // trap sigfpe and set the ClassAdExprFPE flag to true; on NT check the
    // result against HUGE_VAL.  check errno for EDOM and ERANGE for kicks.
    v1.isRealValue(r1);
    v2.isRealValue(r2);
    int errno = 0;
    switch(op) {
        case OpKind_ADDITION_OP:
            comp = r1.getDoubleValue() + r2.getDoubleValue();
            break;
        case OpKind_SUBTRACTION_OP:
            comp = r1.getDoubleValue() - r2.getDoubleValue();
            break;
        case OpKind_MULTIPLICATION_OP:
            comp = r1.getDoubleValue() * r2.getDoubleValue();
            break;
        case OpKind_DIVISION_OP:
            comp = r1.getDoubleValue() / r2.getDoubleValue();
            break;
        case OpKind_MODULUS_OP:
            errno = EDOM;
            break;
        default:
            // should not reach here
            throw new HyracksDataException("Should not get here");
    }
    // check if anything bad happened
    if (errno == EDOM) {
        result.setErrorValue();
    } else {
        result.setRealValue(comp);
    }
    return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
Also used : AMutableDouble(org.apache.asterix.om.base.AMutableDouble) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 18 with AMutableDouble

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

the class Value method convertValueToIntegerValue.

public static boolean convertValueToIntegerValue(Value value, Value integerValue, ClassAdObjectPool objectPool) throws HyracksDataException {
    boolean could_convert;
    AMutableCharArrayString buf = objectPool.strPool.get();
    char end;
    AMutableInt64 ivalue = objectPool.int64Pool.get();
    AMutableDouble rtvalue = objectPool.doublePool.get();
    ClassAdTime atvalue = objectPool.classAdTimePool.get();
    MutableBoolean bvalue = objectPool.boolPool.get();
    NumberFactor nf;
    switch(value.getType()) {
        case UNDEFINED_VALUE:
            integerValue.setUndefinedValue();
            could_convert = false;
            break;
        case ERROR_VALUE:
        case CLASSAD_VALUE:
        case LIST_VALUE:
        case SLIST_VALUE:
            integerValue.setErrorValue();
            could_convert = false;
            break;
        case STRING_VALUE:
            could_convert = true;
            value.isStringValue(buf);
            int endIndex = buf.firstNonDigitChar();
            if (endIndex < 0) {
                // no non digit
                ivalue.setValue(Long.parseLong(buf.toString()));
                nf = NumberFactor.NO_FACTOR;
                break;
            } else {
                ivalue.setValue(Long.parseLong(buf.substr(0, endIndex)));
                end = buf.charAt(endIndex);
                switch(Character.toUpperCase(end)) {
                    case 'B':
                        nf = NumberFactor.B_FACTOR;
                        break;
                    case 'K':
                        nf = NumberFactor.K_FACTOR;
                        break;
                    case 'M':
                        nf = NumberFactor.M_FACTOR;
                        break;
                    case 'G':
                        nf = NumberFactor.G_FACTOR;
                        break;
                    case 'T':
                        nf = NumberFactor.T_FACTOR;
                        break;
                    case '\0':
                        nf = NumberFactor.NO_FACTOR;
                        break;
                    default:
                        nf = NumberFactor.NO_FACTOR;
                        break;
                }
                if (could_convert) {
                    integerValue.setIntegerValue((long) ((ivalue.getLongValue() * Value.ScaleFactor[nf.ordinal()])));
                }
            }
            break;
        case BOOLEAN_VALUE:
            value.isBooleanValue(bvalue);
            integerValue.setIntegerValue(bvalue.booleanValue() ? 1 : 0);
            could_convert = true;
            break;
        case INTEGER_VALUE:
            integerValue.setValue(value);
            could_convert = true;
            break;
        case REAL_VALUE:
            value.isRealValue(rtvalue);
            integerValue.setIntegerValue((long) rtvalue.getDoubleValue());
            could_convert = true;
            break;
        case ABSOLUTE_TIME_VALUE:
            value.isAbsoluteTimeValue(atvalue);
            integerValue.setIntegerValue(atvalue.getTimeInMillis() / 1000L);
            could_convert = true;
            break;
        case RELATIVE_TIME_VALUE:
            value.isRelativeTimeValue(atvalue);
            integerValue.setIntegerValue((atvalue.getTime() / 1000L));
            could_convert = true;
            break;
        default:
            // Make gcc's -Wuninitalized happy
            could_convert = false;
            throw new HyracksDataException("Should not reach here");
    }
    return could_convert;
}
Also used : AMutableDouble(org.apache.asterix.om.base.AMutableDouble) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 19 with AMutableDouble

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

the class Literal method privateEvaluate.

@Override
public boolean privateEvaluate(EvalState eval, Value val) throws HyracksDataException {
    AMutableInt64 i = objectPool.int64Pool.get();
    AMutableDouble r = objectPool.doublePool.get();
    val.setValue(value);
    // if integer or real, multiply by the factor
    if (val.isIntegerValue(i)) {
        if (factor != NumberFactor.NO_FACTOR) {
            val.setRealValue((i.getLongValue()) * Value.ScaleFactor[factor.ordinal()]);
        } else {
            val.setIntegerValue(i.getLongValue());
        }
    } else if (val.isRealValue(r)) {
        val.setRealValue(r.getDoubleValue() * Value.ScaleFactor[factor.ordinal()]);
    }
    return true;
}
Also used : AMutableDouble(org.apache.asterix.om.base.AMutableDouble) AMutableInt64(org.apache.asterix.om.base.AMutableInt64)

Example 20 with AMutableDouble

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

the class Literal method GetValue.

public void GetValue(Value val) throws HyracksDataException {
    AMutableInt64 i = objectPool.int64Pool.get();
    AMutableDouble r = objectPool.doublePool.get();
    val.setValue(value);
    // if integer or real, multiply by the factor
    if (val.isIntegerValue(i)) {
        if (factor != NumberFactor.NO_FACTOR) {
            val.setRealValue((i.getLongValue()) * Value.ScaleFactor[factor.ordinal()]);
        }
    } else if (val.isRealValue(r)) {
        if (factor != NumberFactor.NO_FACTOR) {
            val.setRealValue(r.getDoubleValue() * Value.ScaleFactor[factor.ordinal()]);
        }
    }
}
Also used : AMutableDouble(org.apache.asterix.om.base.AMutableDouble) AMutableInt64(org.apache.asterix.om.base.AMutableInt64)

Aggregations

AMutableDouble (org.apache.asterix.om.base.AMutableDouble)24 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)16 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)12 DataOutput (java.io.DataOutput)11 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)11 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)11 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)11 IPointable (org.apache.hyracks.data.std.api.IPointable)11 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)11 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)11 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)11 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)10 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)9 AMutableInt32 (org.apache.asterix.om.base.AMutableInt32)7 AMutableFloat (org.apache.asterix.om.base.AMutableFloat)6 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)6 IOException (java.io.IOException)5 AMutableInt16 (org.apache.asterix.om.base.AMutableInt16)5 AMutableInt8 (org.apache.asterix.om.base.AMutableInt8)5 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)2