Search in sources :

Example 1 with AMutableInt32

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

the class Literal method createAbsTime.

/* Creates an absolute time literal, from the string timestr,
     *parsing it as the regular expression:
     D* dddd [D* dd [D* dd [D* dd [D* dd [D* dd D*]]]]] [-dd:dd | +dd:dd | z | Z]
     D => non-digit, d=> digit
     Ex - 2003-01-25T09:00:00-06:00
    */
public static Literal createAbsTime(AMutableCharArrayString timeStr, ClassAdObjectPool objectPool) throws HyracksDataException {
    Value val = objectPool.valuePool.get();
    // to check if the argument conatins a timezone offset parameter
    boolean offset = false;
    // corresponds to 1st "dd" in -|+dd:dd
    AMutableInt32 tzhr = objectPool.int32Pool.get();
    // corresponds to 2nd "dd" in -|+dd:dd
    AMutableInt32 tzmin = objectPool.int32Pool.get();
    int len = timeStr.getLength();
    AMutableInt32 index = objectPool.int32Pool.get();
    index.setValue(len - 1);
    prevNonSpaceChar(timeStr, index);
    AMutableInt32 i = objectPool.int32Pool.get();
    i.setValue(index.getIntegerValue());
    if ((timeStr.charAt(i.getIntegerValue()) == 'z') || (timeStr.charAt(i.getIntegerValue()) == 'Z')) {
        // z|Z corresponds to a timezone offset of 0
        offset = true;
        // remove the offset section from the string
        timeStr.erase(i.getIntegerValue());
    } else if (timeStr.charAt(len - 5) == '+' || timeStr.charAt(len - 5) == '-') {
        offset = extractTimeZone(timeStr, tzhr, tzmin);
    } else if ((timeStr.charAt(len - 6) == '+' || timeStr.charAt(len - 6) == '-') && timeStr.charAt(len - 3) == ':') {
        timeStr.erase(len - 3, 1);
        offset = extractTimeZone(timeStr, tzhr, tzmin);
    }
    i.setValue(0);
    len = timeStr.getLength();
    nextDigitChar(timeStr, i);
    if (i.getIntegerValue() > len - 4) {
        // string has to contain dddd (year)
        val.setErrorValue();
        return (createLiteral(val, objectPool));
    }
    int tm_year, tm_mon = 0, tm_mday = 0, tm_hour = 0, tm_min = 0, tm_sec = 0;
    // - 1900;
    tm_year = Integer.parseInt((timeStr.substr(i.getIntegerValue(), 4)));
    i.setValue(i.getIntegerValue() + 4);
    nextDigitChar(timeStr, i);
    if (i.getIntegerValue() <= len - 2) {
        tm_mon = Integer.parseInt(timeStr.substr(i.getIntegerValue(), 2)) - 1;
        i.setValue(i.getIntegerValue() + 2);
    }
    nextDigitChar(timeStr, i);
    if (i.getIntegerValue() <= len - 2) {
        tm_mday = Integer.parseInt(timeStr.substr(i.getIntegerValue(), 2));
        i.setValue(i.getIntegerValue() + 2);
    }
    nextDigitChar(timeStr, i);
    if (i.getIntegerValue() <= len - 2) {
        tm_hour = Integer.parseInt(timeStr.substr(i.getIntegerValue(), 2));
        i.setValue(i.getIntegerValue() + 2);
    }
    nextDigitChar(timeStr, i);
    if (i.getIntegerValue() <= len - 2) {
        tm_min = Integer.parseInt(timeStr.substr(i.getIntegerValue(), 2));
        i.setValue(i.getIntegerValue() + 2);
    }
    nextDigitChar(timeStr, i);
    if (i.getIntegerValue() <= len - 2) {
        tm_sec = Integer.parseInt(timeStr.substr(i.getIntegerValue(), 2));
        i.setValue(i.getIntegerValue() + 2);
    }
    nextDigitChar(timeStr, i);
    if ((i.getIntegerValue() <= len - 1) && (Character.isDigit(timeStr.charAt(i.getIntegerValue())))) {
        // there should be no more digit characters once the required
        // parameteres are parsed
        val.setErrorValue();
        return (createLiteral(val, objectPool));
    }
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.clear();
    cal.set(tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec);
    ClassAdTime time = objectPool.classAdTimePool.get();
    time.setValue(cal.getTimeInMillis());
    if (offset) {
        time.setTimeZone((tzhr.getIntegerValue() * 3600000) + (tzmin.getIntegerValue() * 60000));
    } else {
        // if offset is not specified, the offset of the current locality is taken
        time.setDefaultTimeZone();
    }
    val.setAbsoluteTimeValue(time);
    return (createLiteral(val, objectPool));
}
Also used : Calendar(java.util.Calendar) AMutableInt32(org.apache.asterix.om.base.AMutableInt32)

Example 2 with AMutableInt32

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

the class PrefixLenDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                private final IPointable inputVal = new VoidPointable();

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

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

                private final IScalarEvaluator evalThreshold = args[2].createScalarEvaluator(ctx);

                private final SimilarityFiltersCache similarityFiltersCache = new SimilarityFiltersCache();

                // result
                private final AMutableInt32 res = new AMutableInt32(0);

                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<AInt32> int32Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    // length
                    evalLen.evaluate(tuple, inputVal);
                    byte[] data = inputVal.getByteArray();
                    int offset = inputVal.getStartOffset();
                    if (data[offset] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                    }
                    int length = IntegerPointable.getInteger(data, offset + 1);
                    // similarity threshold
                    evalThreshold.evaluate(tuple, inputVal);
                    data = inputVal.getByteArray();
                    offset = inputVal.getStartOffset();
                    if (data[offset] != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, data[offset], ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                    }
                    float similarityThreshold = (float) ADoubleSerializerDeserializer.getDouble(data, offset + 1);
                    // similarity name
                    evalSimilarity.evaluate(tuple, inputVal);
                    data = inputVal.getByteArray();
                    offset = inputVal.getStartOffset();
                    int len = inputVal.getLength();
                    if (data[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 2, data[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                    }
                    SimilarityFilters similarityFilters = similarityFiltersCache.get(similarityThreshold, data, offset, len);
                    int prefixLength = similarityFilters.getPrefixLength(length);
                    res.setValue(prefixLength);
                    try {
                        int32Serde.serialize(res, out);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) SimilarityFiltersCache(org.apache.asterix.runtime.evaluators.common.SimilarityFiltersCache) SimilarityFilters(org.apache.asterix.fuzzyjoin.similarity.SimilarityFilters) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) 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) AMutableInt32(org.apache.asterix.om.base.AMutableInt32)

Example 3 with AMutableInt32

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

the class PrefixLenJaccardDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                private final IPointable lenPtr = new VoidPointable();

                private final IPointable thresholdPtr = new VoidPointable();

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

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

                private float similarityThresholdCache;

                private SimilarityFiltersJaccard similarityFilters;

                // result
                private final AMutableInt32 res = new AMutableInt32(0);

                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<AInt32> int32Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    evalLen.evaluate(tuple, lenPtr);
                    evalThreshold.evaluate(tuple, thresholdPtr);
                    // length
                    int length = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, lenPtr.getByteArray(), lenPtr.getStartOffset());
                    // similarity threshold
                    byte[] data = thresholdPtr.getByteArray();
                    int offset = thresholdPtr.getStartOffset();
                    if (data[offset] != ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, data[offset], ATypeTag.SERIALIZED_FLOAT_TYPE_TAG);
                    }
                    float similarityThreshold = AFloatSerializerDeserializer.getFloat(data, offset + 1);
                    if (similarityThreshold != similarityThresholdCache || similarityFilters == null) {
                        similarityFilters = new SimilarityFiltersJaccard(similarityThreshold);
                    }
                    int prefixLength = similarityFilters.getPrefixLength(length);
                    res.setValue(prefixLength);
                    try {
                        int32Serde.serialize(res, out);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) SimilarityFiltersJaccard(org.apache.asterix.fuzzyjoin.similarity.SimilarityFiltersJaccard) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutableInt32(org.apache.asterix.om.base.AMutableInt32)

Example 4 with AMutableInt32

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

the class NumericRoundHalfToEven2Descriptor 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 argValue = new VoidPointable();

                private IPointable argPrecision = new VoidPointable();

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

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

                private AMutableDouble aDouble = new AMutableDouble(0);

                private AMutableFloat aFloat = new AMutableFloat(0);

                private AMutableInt64 aInt64 = new AMutableInt64(0);

                private AMutableInt32 aInt32 = new AMutableInt32(0);

                private AMutableInt16 aInt16 = new AMutableInt16((short) 0);

                private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);

                @SuppressWarnings("rawtypes")
                private ISerializerDeserializer serde;

                private int getPrecision() throws HyracksDataException {
                    byte[] bytes = argPrecision.getByteArray();
                    int offset = argPrecision.getStartOffset();
                    if (bytes[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                        return AInt8SerializerDeserializer.getByte(bytes, offset + 1);
                    } else if (bytes[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
                        return AInt16SerializerDeserializer.getShort(bytes, offset + 1);
                    } else if (bytes[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
                        return AInt32SerializerDeserializer.getInt(bytes, offset + 1);
                    } else if (bytes[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
                        return (int) AInt64SerializerDeserializer.getLong(bytes, offset + 1);
                    } else {
                        throw new TypeMismatchException(getIdentifier(), 1, bytes[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
                    }
                }

                @SuppressWarnings("unchecked")
                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argValue);
                    precision.evaluate(tuple, argPrecision);
                    byte[] data = argValue.getByteArray();
                    int offset = argValue.getStartOffset();
                    if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                        serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
                        byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
                        aInt8.setValue(val);
                        serde.serialize(aInt8, out);
                    } else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
                        serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
                        short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
                        aInt16.setValue(val);
                        serde.serialize(aInt16, out);
                    } else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
                        serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
                        int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
                        aInt32.setValue(val);
                        serde.serialize(aInt32, out);
                    } else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
                        serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
                        long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
                        aInt64.setValue(val);
                        serde.serialize(aInt64, out);
                    } else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
                        serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
                        float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
                        if (Float.isNaN(val) || Float.isInfinite(val) || Float.compare(val, -0.0F) == 0 || Float.compare(val, 0.0F) == 0) {
                            aFloat.setValue(val);
                            serde.serialize(aFloat, out);
                        } else {
                            BigDecimal r = new BigDecimal(Float.toString(val));
                            aFloat.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_HALF_EVEN).floatValue());
                            serde.serialize(aFloat, out);
                        }
                    } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                        serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
                        double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
                        if (Double.isNaN(val) || Double.isInfinite(val) || Double.compare(val, -0.0D) == 0 || Double.compare(val, 0.0D) == 0) {
                            aDouble.setValue(val);
                            serde.serialize(aDouble, out);
                        } else {
                            BigDecimal r = new BigDecimal(Double.toString(val));
                            aDouble.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_HALF_EVEN).doubleValue());
                            serde.serialize(aDouble, out);
                        }
                    } else {
                        throw new TypeMismatchException(getIdentifier(), 0, data[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG, ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) AMutableInt8(org.apache.asterix.om.base.AMutableInt8) 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) BigDecimal(java.math.BigDecimal) 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) AMutableDouble(org.apache.asterix.om.base.AMutableDouble) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutableInt16(org.apache.asterix.om.base.AMutableInt16) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) AMutableInt32(org.apache.asterix.om.base.AMutableInt32) AMutableFloat(org.apache.asterix.om.base.AMutableFloat)

Example 5 with AMutableInt32

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

the class ClassAdUnitTester method testClassad.

/*********************************************************************
     * Function: test_classad
     * Purpose: Test the ClassAd class.
     * @param objectPool
     *
     * @throws IOException
     *********************************************************************/
public static void testClassad(Parameters parameters, Results results, ClassAdObjectPool objectPool) throws IOException {
    ClassAdParser parser = new ClassAdParser(objectPool);
    boolean haveAttribute;
    boolean success;
    System.out.println("Testing the ClassAd class...");
    String input_basic = "[ A = 3; B = 4.0; C = \"babyzilla\"; D = true; E = {1}; F = [ AA = 3; ]; G =\"deleteme\";]";
    ClassAd basic = new ClassAd(objectPool);
    AMutableInt64 i = new AMutableInt64(0);
    MutableBoolean b = new MutableBoolean();
    AMutableDouble r = new AMutableDouble(0);
    AMutableCharArrayString s = new AMutableCharArrayString();
    ClassAd c = new ClassAd(objectPool);
    // ExprList *l;
    basic = parser.parseClassAd(input_basic);
    /* ----- Test EvaluateAttr* ----- */
    haveAttribute = basic.evaluateAttrInt("A", i);
    test("Have attribute A", (haveAttribute == true), "test_classad 1", results);
    test("A is 3", (i.getLongValue() == 3), "test_classad 2", results);
    haveAttribute = basic.evaluateAttrReal("B", r);
    test("Have attribute B", (haveAttribute == true), "test_classad 3", results);
    test("B is 4.0", (r.getDoubleValue() == 4.0), "test_classad 4", results);
    haveAttribute = basic.evaluateAttrString("C", s);
    test("Have attribute C", (haveAttribute == true), "test_classad 5", results);
    test("C is 'babyzilla'", (s.compareTo("babyzilla") == 0), "test_classad 6", results);
    haveAttribute = basic.evaluateAttrBool("D", b);
    test("Have attribute D", (haveAttribute == true), "test_classad 7", results);
    test("D is true", (b.booleanValue() == true), "test_classad 8", results);
    /* ----- Test basic insert and delete ----- */
    success = basic.insertAttr("new", 4);
    test("InsertAttr claims to have worked", (success == true), "test_classad 9", results);
    haveAttribute = basic.evaluateAttrInt("new", i);
    test("Have new attribute", (haveAttribute == true), "test_classad 10", results);
    test("new attribute is 4", i.getLongValue() == 4, "test_classad 11", results);
    success = basic.delete("new");
    test("Delete claims to have worked", (success == true), "test_classad 12", results);
    haveAttribute = basic.evaluateAttrInt("new", i);
    test("New attribute was deleted", (haveAttribute == false), "test_classad 13", results);
    success = basic.delete("G");
    test("DELETE claims to have worked", (success == true), "test_classad 14", results);
    haveAttribute = basic.evaluateAttrString("G", s);
    test("Attribute G was deleted", (haveAttribute == false), "test_classad 15", results);
    basic = null;
    /* ----- Test GetExternalReferences ----- */
    String inputRef = "[ Rank=Member(\"LCG-2_1_0\",other.Environment) ? other.Time/seconds : other.Time/minutes; minutes=60; ]";
    TreeSet<String> refs = new TreeSet<String>();
    ExprTree rank;
    c = parser.parseClassAd(inputRef);
    test("Made classad_ref", (c != null), "Test GetExternalReferences 1", results);
    if (c != null) {
        rank = c.lookup("Rank");
        test("Rank exists", (rank != null), "Test GetExternalReferences 2", results);
        if (rank != null) {
            boolean haveReferences;
            if ((haveReferences = c.getExternalReferences(rank, refs, true))) {
                test("have_references", (haveReferences == true), "Test GetExternalReferences 3", results);
                if (haveReferences) {
                    boolean haveEnvironment;
                    boolean haveTime;
                    boolean haveSeconds;
                    boolean haveOther;
                    haveEnvironment = false;
                    haveTime = false;
                    haveSeconds = false;
                    haveOther = false;
                    for (String entry : refs) {
                        if (entry.compareTo("other.Environment") == 0) {
                            haveEnvironment = true;
                        } else if (entry.compareTo("other.Time") == 0) {
                            haveTime = true;
                        } else if (entry.compareTo("seconds") == 0) {
                            haveSeconds = true;
                        } else {
                            haveOther = true;
                        }
                    }
                    test("Have external reference to Environment", (haveEnvironment == true), "Test GetExternalReferences 4", results);
                    test("Have external reference to Time", (haveTime == true), "Test GetExternalReferences 5", results);
                    test("Have external reference to seconds", (haveSeconds == true), "Test GetExternalReferences 6", results);
                    test("Have no other external references", (haveOther != true), "Test GetExternalReferences 7", results);
                }
            }
        }
        c = null;
    }
    // This ClassAd may cause problems. Perhaps a memory leak.
    // This test is only useful when run under valgrind.
    String memoryProblemClassad = "[ Updates = [status = \"request_completed\"; timestamp = absTime(\"2004-12-16T18:10:59-0600]\")] ]";
    c = parser.parseClassAd(memoryProblemClassad);
    /* ----- Test Parsing multiple ClassAds ----- */
    String twoClassads = "[ a = 3; ][ b = 4; ]";
    ClassAd classad1 = new ClassAd(objectPool);
    ClassAd classad2 = new ClassAd(objectPool);
    AMutableInt32 offset = new AMutableInt32(0);
    parser.parseClassAd(twoClassads, classad1, offset);
    test("Have good offset #1", offset.getIntegerValue() == 10, "Test Parsing multiple ClassAds 1", results);
    parser.parseClassAd(twoClassads, classad2, offset);
    test("Have good offset #2", offset.getIntegerValue() == 20, "Test Parsing multiple ClassAds 2", results);
    /* ----- Test chained ClassAds ----- */
    // classad1 and classad2 from above test are used.
    ClassAd classad3 = new ClassAd(objectPool);
    classad1.chainToAd(classad2);
    test("classad1's parent is classad2", classad1.getChainedParentAd().equals(classad2), "Test chained ClassAds 1", results);
    haveAttribute = classad1.evaluateAttrInt("b", i);
    test("chain has attribute b from parent", (haveAttribute == true), "Test chained ClassAds 2", results);
    test("chain attribute b from parent is 4", (i.getLongValue() == 4), "Test chained ClassAds 3", results);
    haveAttribute = classad1.evaluateAttrInt("a", i);
    test("chain has attribute a from self", (haveAttribute == true), "Test chained ClassAds 4", results);
    test("chain attribute a is 3", (i.getLongValue() == 3), "Test chained ClassAds 5", results);
    // Now we modify classad2 (parent) to contain "a".
    success = classad2.insertAttr("a", 7);
    test("insert a into parent", (success == true), "Test chained ClassAds 6", results);
    haveAttribute = classad1.evaluateAttrInt("a", i);
    test("chain has attribute a from self (overriding parent)", (haveAttribute == true), "Test chained ClassAds 7", results);
    test("chain attribute a is 3 (overriding parent)", (i.getLongValue() == 3), "Test chained ClassAds 8", results);
    haveAttribute = classad2.evaluateAttrInt("a", i);
    test("chain parent has attribute a", (haveAttribute == true), "Test chained ClassAds 9", results);
    test("chain parent attribute a is 7", (i.getLongValue() == 7), "Test chained ClassAds 10", results);
    success = classad3.copyFromChain(classad1);
    test("copy from chain succeeded", (success == true), "Test chained ClassAds 11", results);
    haveAttribute = classad3.evaluateAttrInt("b", i);
    test("copy of chain has attribute b", (haveAttribute == true), "Test chained ClassAds 12", results);
    test("copy of chain has attribute b==4", (i.getLongValue() == 4), "Test chained ClassAds 13", results);
    success = classad3.insertAttr("c", 6);
    test("insert into copy of chain succeeded", (success == true), "Test chained ClassAds 14", results);
    classad3.copyFromChain(classad1);
    haveAttribute = classad3.evaluateAttrInt("c", i);
    test("copy of chain is clean", (haveAttribute == false), "Test chained ClassAds 15", results);
    classad3.insertAttr("c", 6);
    success = classad3.updateFromChain(classad1);
    test("update from chain succeeded", (success == true), "Test chained ClassAds 16", results);
    haveAttribute = classad3.evaluateAttrInt("c", i);
    test("update from chain is merged", (haveAttribute == true), "Test chained ClassAds 17", results);
    test("update from chain has attribute c==6", (i.getLongValue() == 6), "Test chained ClassAds 18", results);
}
Also used : ClassAdParser(org.apache.asterix.external.library.ClassAdParser) ClassAd(org.apache.asterix.external.classad.ClassAd) TreeSet(java.util.TreeSet) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) AMutableDouble(org.apache.asterix.om.base.AMutableDouble) ExprTree(org.apache.asterix.external.classad.ExprTree) AMutableString(org.apache.asterix.om.base.AMutableString) AMutableCharArrayString(org.apache.asterix.external.classad.AMutableCharArrayString) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) AMutableInt32(org.apache.asterix.om.base.AMutableInt32) AMutableCharArrayString(org.apache.asterix.external.classad.AMutableCharArrayString)

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