Search in sources :

Example 11 with AMutableInt64

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

the class ClassAdUnitTester method testValue.

/*********************************************************************
     * Function: test_value
     * Purpose: Test the Value class.
     *
     * @throws HyracksDataException
     *********************************************************************/
public static void testValue(Parameters parameters, Results results, ClassAdObjectPool objectPool) throws HyracksDataException {
    Value v = new Value(objectPool);
    boolean isExpectedType;
    System.out.println("Testing the Value class...");
    test("New value is undefined", (v.isUndefinedValue()), "test_value 1", results);
    test("New value isn't boolean", !(v.isBooleanValue()), "test_value 2", results);
    test("GetType gives UNDEFINED_VALUE", (v.getType() == ValueType.UNDEFINED_VALUE), "test_value 3", results);
    v.setErrorValue();
    test("Is error value", (v.isErrorValue()), "test_value 4", results);
    test("GetType gives ERROR_VALUE", (v.getType() == ValueType.ERROR_VALUE), "test_value 5", results);
    MutableBoolean b = new MutableBoolean();
    v.setBooleanValue(true);
    isExpectedType = v.isBooleanValue(b);
    test("Value is not undefined", !(v.isUndefinedValue()), "Value is not undefined", results);
    test("Value is boolean", (v.isBooleanValue()), "Value is boolean", results);
    test("Try 2: New value is boolean", (isExpectedType == true), "Try 2: New value is boolean", results);
    test("Boolean is true", (b.booleanValue() == true), "Boolean is true", results);
    test("GetType gives BOOLEAN_VALUE", (v.getType() == ValueType.BOOLEAN_VALUE), "GetType gives BOOLEAN_VALUE", results);
    AMutableDouble r = new AMutableDouble(0.0);
    v.setRealValue(1.0);
    isExpectedType = v.isRealValue(r);
    test("Value is real", isExpectedType, results);
    test("Real is 1.0", (r.getDoubleValue() == 1.0), results);
    test("GetType gives REAL_VALUE", (v.getType() == ValueType.REAL_VALUE), results);
    test("Real is a number", v.isNumber(), results);
    AMutableInt64 i = new AMutableInt64(0);
    v.setIntegerValue(1);
    isExpectedType = v.isIntegerValue(i);
    test("Value is integer", isExpectedType, results);
    test("Integer is 1", (i.getLongValue() == 1), results);
    test("GetType gives INTEGER_VALUE", (v.getType() == ValueType.INTEGER_VALUE), results);
    test("Integer is a number", v.isNumber(), results);
    AMutableCharArrayString s = new AMutableCharArrayString();
    v.setStringValue("Robert-Houdin");
    isExpectedType = v.isStringValue(s);
    test("Value is String", isExpectedType, results);
    test("String is 'Robert-Houdin'", (0 == s.compareTo("Robert-Houdin")), results);
    test("GetType gives STRING_VALUE", (v.getType() == ValueType.STRING_VALUE), results);
    ClassAdTime at = new ClassAdTime(10, 36000000);
    v.setAbsoluteTimeValue(at);
    at.setValue(0);
    at.setTimeZone(0);
    isExpectedType = v.isAbsoluteTimeValue(at);
    test("Value is absolute time", isExpectedType, results);
    test("Absolute time is 10, 0", (10 == at.getTime() && 36000000 == at.getOffset()), results);
    test("GetType gives ABSOLUTE_TIME_VALUE", (v.getType() == ValueType.ABSOLUTE_TIME_VALUE), results);
    ClassAdTime rt = new ClassAdTime(10, false);
    v.setRelativeTimeValue(10);
    isExpectedType = v.isRelativeTimeValue(rt);
    test("Value is relative time", isExpectedType, results);
    test("Relative time is 10", (10 == rt.getRelativeTime()), results);
    test("GetType gives RELATIVE_TIME_VALUE", (v.getType() == ValueType.RELATIVE_TIME_VALUE), results);
    ExprList l = new ExprList(objectPool);
    ExprList ll = new ExprList(objectPool);
    v.setListValue(l);
    isExpectedType = v.isListValue(ll);
    test("Value is list value", isExpectedType, results);
    test("List value is correct", l.equals(ll), results);
    test("GetType gives LIST_VALUE", (v.getType() == ValueType.LIST_VALUE), results);
    ExprList sl = new ExprList(true, objectPool);
    ll = new ExprList(true, objectPool);
    v.setListValue(sl);
    isExpectedType = v.isListValue(ll);
    test("Value is list value", isExpectedType, results);
    test("List value is correct", sl.equals(ll), results);
    test("GetType gives SLIST_VALUE", (v.getType() == ValueType.SLIST_VALUE), results);
    ClassAd c = new ClassAd(objectPool);
    c.insertAttr("test_int", 10);
    ClassAd cc = new ClassAd(objectPool);
    v.setClassAdValue(c);
    isExpectedType = v.isClassAdValue(cc);
    test("Value is ClassAd value", isExpectedType, results);
    test("ClassAd value is correct", c.equals(cc), results);
    test("GetType gives CLASSAD_VALUE", (v.getType() == ValueType.CLASSAD_VALUE), results);
    return;
}
Also used : ClassAd(org.apache.asterix.external.classad.ClassAd) ClassAdTime(org.apache.asterix.external.classad.ClassAdTime) ExprList(org.apache.asterix.external.classad.ExprList) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) AMutableDouble(org.apache.asterix.om.base.AMutableDouble) Value(org.apache.asterix.external.classad.Value) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) AMutableCharArrayString(org.apache.asterix.external.classad.AMutableCharArrayString)

Example 12 with AMutableInt64

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

the class Operation method privateDoOperation.

public static int privateDoOperation(int op, Value val1, Value val2, Value val3, boolean valid1, boolean valid2, boolean valid3, Value result, EvalState es, ClassAdObjectPool objectPool) throws HyracksDataException {
    ValueType vt1;
    ValueType vt2;
    ValueType vt3;
    // get the types of the values
    vt1 = val1.getType();
    vt2 = val2.getType();
    vt3 = val3.getType();
    // take care of the easy cases
    if (op == OpKind_NO_OP || op == OpKind_PARENTHESES_OP) {
        result.setValue(val1);
        return SigValues.SIG_CHLD1.ordinal();
    } else if (op == OpKind_UNARY_PLUS_OP) {
        if (vt1 == ValueType.BOOLEAN_VALUE || vt1 == ValueType.STRING_VALUE || val1.isListValue() || vt1 == ValueType.CLASSAD_VALUE || vt1 == ValueType.ABSOLUTE_TIME_VALUE) {
            result.setErrorValue();
        } else {
            // applies for ERROR, UNDEFINED and Numbers
            result.setValue(val1);
        }
        return SigValues.SIG_CHLD1.ordinal();
    }
    // test for cases when evaluation is strict
    if (isStrictOperator(op)) {
        // check for error values
        if (vt1 == ValueType.ERROR_VALUE) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        }
        if (valid2 && vt2 == ValueType.ERROR_VALUE) {
            result.setErrorValue();
            return SigValues.SIG_CHLD2.ordinal();
        }
        if (valid3 && vt3 == ValueType.ERROR_VALUE) {
            result.setErrorValue();
            return SigValues.SIG_CHLD3.ordinal();
        }
        // tree exists, because these values would be undefined" anyway then.
        if (valid1 && vt1 == ValueType.UNDEFINED_VALUE) {
            result.setUndefinedValue();
            return SigValues.SIG_CHLD1.ordinal();
        }
        if (valid2 && vt2 == ValueType.UNDEFINED_VALUE) {
            result.setUndefinedValue();
            return SigValues.SIG_CHLD2.ordinal();
        }
        if (valid3 && vt3 == ValueType.UNDEFINED_VALUE) {
            result.setUndefinedValue();
            return SigValues.SIG_CHLD3.ordinal();
        }
    }
    // comparison operations (binary, one unary)
    if (op >= OpKind_COMPARISON_START && op <= OpKind_COMPARISON_END) {
        return (doComparison(op, val1, val2, result, objectPool));
    }
    // arithmetic operations (binary)
    if (op >= OpKind_ARITHMETIC_START && op <= OpKind_ARITHMETIC_END) {
        return (doArithmetic(op, val1, val2, result, objectPool));
    }
    // logical operators (binary, one unary)
    if (op >= OpKind_LOGIC_START && op <= OpKind_LOGIC_END) {
        return (doLogical(op, val1, val2, result, objectPool));
    }
    // bitwise operators (binary, one unary)
    if (op >= OpKind_BITWISE_START && op <= OpKind_BITWISE_END) {
        return (doBitwise(op, val1, val2, result, objectPool));
    }
    // misc.
    if (op == OpKind_TERNARY_OP) {
        // ternary (if-operator)
        MutableBoolean b = objectPool.boolPool.get();
        // if the selector is UNDEFINED, the result is undefined
        if (vt1 == ValueType.UNDEFINED_VALUE) {
            result.setUndefinedValue();
            return SigValues.SIG_CHLD1.ordinal();
        }
        if (!val1.isBooleanValueEquiv(b)) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        } else if (b.booleanValue()) {
            result.setValue(val2);
            return (SigValues.SIG_CHLD2.ordinal());
        } else {
            result.setValue(val3);
            return (SigValues.SIG_CHLD3.ordinal());
        }
    } else if (op == OpKind_SUBSCRIPT_OP) {
        if (vt1 == ValueType.CLASSAD_VALUE && vt2 == ValueType.STRING_VALUE) {
            ClassAd classad = objectPool.classAdPool.get();
            AMutableCharArrayString index = objectPool.strPool.get();
            val1.isClassAdValue(classad);
            val2.isStringValue(index);
            if (classad.lookup(index.toString()) == null) {
                result.setErrorValue();
                return SigValues.SIG_CHLD2.ordinal();
            }
            if (!classad.evaluateAttr(index.toString(), result)) {
                result.setErrorValue();
                return SigValues.SIG_CHLD2.ordinal();
            }
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        } else if (val1.isListValue() && vt2 == ValueType.INTEGER_VALUE) {
            AMutableInt64 index = objectPool.int64Pool.get();
            ExprList elist = objectPool.exprListPool.get();
            val1.isListValue(elist);
            val2.isIntegerValue(index);
            // check bounds
            if (index.getLongValue() < 0 || index.getLongValue() >= elist.getExprList().size()) {
                result.setErrorValue();
                return SigValues.SIG_CHLD2.ordinal();
            }
            // get value
            elist.getValue(result, elist.get((int) index.getLongValue()), es);
            return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
        }
        // should not reach here
        throw new HyracksDataException("Should not get here");
    }
    return -1;
}
Also used : ValueType(org.apache.asterix.external.classad.Value.ValueType) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 13 with AMutableInt64

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

the class MillisecondsFromDayTimeDurationDescriptor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable argPtr0 = new VoidPointable();

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

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                AMutableInt64 aInt64 = new AMutableInt64(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval0.evaluate(tuple, argPtr0);
                    byte[] bytes = argPtr0.getByteArray();
                    int offset = argPtr0.getStartOffset();
                    if (bytes[offset] != ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG);
                    }
                    aInt64.setValue(ADayTimeDurationSerializerDeserializer.getDayTime(bytes, offset + 1));
                    int64Serde.serialize(aInt64, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutableInt64(org.apache.asterix.om.base.AMutableInt64)

Example 14 with AMutableInt64

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

the class UnixTimeFromDateInDaysDescriptor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable argPtr = new VoidPointable();

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

                // possible returning types
                private AMutableInt64 aInt64 = new AMutableInt64(0);

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int offset = argPtr.getStartOffset();
                    if (bytes[offset] != ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATE_TYPE_TAG);
                    }
                    long dateChronon = ADateSerializerDeserializer.getChronon(bytes, offset + 1);
                    aInt64.setValue(dateChronon);
                    int64Serde.serialize(aInt64, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutableInt64(org.apache.asterix.om.base.AMutableInt64)

Example 15 with AMutableInt64

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

the class UnixTimeFromDatetimeInMsDescriptor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable argPtr = new VoidPointable();

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

                // possible returning types
                private AMutableInt64 aInt64 = new AMutableInt64(0);

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int offset = argPtr.getStartOffset();
                    if (bytes[offset] != ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
                    }
                    long datetimeChronon = ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1);
                    aInt64.setValue(datetimeChronon);
                    int64Serde.serialize(aInt64, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) 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