Search in sources :

Example 61 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class DurationFromMonthsDescriptor 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<ADuration> durationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);

                AMutableDuration aDuration = new AMutableDuration(0, 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();
                    aDuration.setValue(ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, bytes, offset), 0);
                    durationSerde.serialize(aDuration, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AMutableDuration(org.apache.asterix.om.base.AMutableDuration) 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) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 62 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class AObjectAscBinaryComparatorFactory method createBinaryComparator.

@Override
public IBinaryComparator createBinaryComparator() {
    return new ABinaryComparator() {

        // a storage to promote a value
        private ArrayBackedValueStorage castBuffer = new ArrayBackedValueStorage();

        private ITypeConvertComputer promoteComputer;

        // BOOLEAN
        final IBinaryComparator ascBoolComp = BooleanBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // TINYINT
        final IBinaryComparator ascByteComp = new PointableBinaryComparatorFactory(BytePointable.FACTORY).createBinaryComparator();

        // SMALLINT
        final IBinaryComparator ascShortComp = new PointableBinaryComparatorFactory(ShortPointable.FACTORY).createBinaryComparator();

        // INTEGER
        final IBinaryComparator ascIntComp = new PointableBinaryComparatorFactory(IntegerPointable.FACTORY).createBinaryComparator();

        // BIGINT
        final IBinaryComparator ascLongComp = LongBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // STRING
        final IBinaryComparator ascStrComp = new PointableBinaryComparatorFactory(UTF8StringPointable.FACTORY).createBinaryComparator();

        // BINARY
        final IBinaryComparator ascByteArrayComp = new PointableBinaryComparatorFactory(ByteArrayPointable.FACTORY).createBinaryComparator();

        // FLOAT
        final IBinaryComparator ascFloatComp = new PointableBinaryComparatorFactory(FloatPointable.FACTORY).createBinaryComparator();

        // DOUBLE
        final IBinaryComparator ascDoubleComp = new PointableBinaryComparatorFactory(DoublePointable.FACTORY).createBinaryComparator();

        // RECTANGLE
        final IBinaryComparator ascRectangleComp = ARectanglePartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // CIRCLE
        final IBinaryComparator ascCircleComp = ACirclePartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // DURATION
        final IBinaryComparator ascDurationComp = ADurationPartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // INTERVAL
        final IBinaryComparator ascIntervalComp = AIntervalAscPartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // LINE
        final IBinaryComparator ascLineComp = ALinePartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // POINT
        final IBinaryComparator ascPointComp = APointPartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // POINT3D
        final IBinaryComparator ascPoint3DComp = APoint3DPartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // POLYGON
        final IBinaryComparator ascPolygonComp = APolygonPartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // UUID
        final IBinaryComparator ascUUIDComp = AUUIDPartialBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        // RAW
        final IBinaryComparator rawComp = RawBinaryComparatorFactory.INSTANCE.createBinaryComparator();

        @Override
        public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) throws HyracksDataException {
            // Therefore, inside this method, we return an order between two values even if one value is MISSING.
            if (b1[s1] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
                return b2[s2] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG ? 0 : -1;
            } else {
                if (b2[s2] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
                    return 1;
                }
            }
            // Therefore, inside this method, we return an order between two values even if one value is NULL.
            if (b1[s1] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                return b2[s2] == ATypeTag.SERIALIZED_NULL_TYPE_TAG ? 0 : -1;
            } else {
                if (b2[s2] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                    return 1;
                }
            }
            ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(b1[s1]);
            ATypeTag tag2 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(b2[s2]);
            // And, we don't need to continue. We just compare raw byte by byte.
            if (tag1 == null || tag2 == null) {
                return rawComp.compare(b1, s1, l1, b2, s2, l2);
            }
            // If two type does not match, we identify the source and the target and
            // promote the source to the target type if they are compatible.
            ATypeTag sourceTypeTag = null;
            ATypeTag targetTypeTag = null;
            boolean areTwoTagsEqual = false;
            boolean typePromotionApplied = false;
            boolean leftValueChanged = false;
            if (tag1 != tag2) {
                // tag1 can be promoted to tag2 (e.g. tag1: SMALLINT, tag2: INTEGER)
                if (ATypeHierarchy.canPromote(tag1, tag2)) {
                    sourceTypeTag = tag1;
                    targetTypeTag = tag2;
                    typePromotionApplied = true;
                    leftValueChanged = true;
                // or tag2 can be promoted to tag1 (e.g. tag2: INTEGER, tag1: DOUBLE)
                } else if (ATypeHierarchy.canPromote(tag2, tag1)) {
                    sourceTypeTag = tag2;
                    targetTypeTag = tag1;
                    typePromotionApplied = true;
                }
                // we promote the source to the target by using a promoteComputer
                if (typePromotionApplied) {
                    castBuffer.reset();
                    promoteComputer = ATypeHierarchy.getTypePromoteComputer(sourceTypeTag, targetTypeTag);
                    if (promoteComputer != null) {
                        try {
                            if (leftValueChanged) {
                                // left side is the source
                                promoteComputer.convertType(b1, s1 + 1, l1 - 1, castBuffer.getDataOutput());
                            } else {
                                // right side is the source
                                promoteComputer.convertType(b2, s2 + 1, l2 - 1, castBuffer.getDataOutput());
                            }
                        } catch (IOException e) {
                            throw new HyracksDataException("ComparatorFactory - failed to promote the type:" + sourceTypeTag + " to the type:" + targetTypeTag);
                        }
                    } else {
                        // No appropriate typePromoteComputer.
                        throw new HyracksDataException("No appropriate typePromoteComputer exists for " + sourceTypeTag + " to the " + targetTypeTag + " type. Please check the code.");
                    }
                }
            } else {
                // tag1 == tag2.
                sourceTypeTag = tag1;
                targetTypeTag = tag1;
                areTwoTagsEqual = true;
            }
            // This is especially useful when we need to generate some order between any two types.
            if ((!areTwoTagsEqual && !typePromotionApplied)) {
                return rawComp.compare(b1, s1, l1, b2, s2, l2);
            }
            // Conduct actual compare()
            switch(targetTypeTag) {
                case UUID:
                    return ascUUIDComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                case BOOLEAN:
                    {
                        return ascBoolComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case TINYINT:
                    {
                        // No type promotion from another type to the TINYINT can happen
                        return ascByteComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case SMALLINT:
                    {
                        if (!typePromotionApplied) {
                            // No type promotion case
                            return ascShortComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                        } else if (leftValueChanged) {
                            // Type promotion happened. Left side was the source
                            return ascShortComp.compare(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, b2, s2 + 1, l2 - 1);
                        } else {
                            // Type promotion happened. Right side was the source
                            return ascShortComp.compare(b1, s1 + 1, l1 - 1, castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1);
                        }
                    }
                case TIME:
                case DATE:
                case YEARMONTHDURATION:
                case INTEGER:
                    {
                        if (!typePromotionApplied) {
                            // No type promotion case
                            return ascIntComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                        } else if (leftValueChanged) {
                            // Type promotion happened. Left side was the source
                            return ascIntComp.compare(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, b2, s2 + 1, l2 - 1);
                        } else {
                            // Type promotion happened. Right side was the source
                            return ascIntComp.compare(b1, s1 + 1, l1 - 1, castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1);
                        }
                    }
                case DATETIME:
                case DAYTIMEDURATION:
                case BIGINT:
                    {
                        if (!typePromotionApplied) {
                            // No type promotion case
                            return ascLongComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                        } else if (leftValueChanged) {
                            // Type promotion happened. Left side was the source
                            return ascLongComp.compare(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, b2, s2 + 1, l2 - 1);
                        } else {
                            // Type promotion happened. Right side was the source
                            return ascLongComp.compare(b1, s1 + 1, l1 - 1, castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1);
                        }
                    }
                case FLOAT:
                    {
                        if (!typePromotionApplied) {
                            // No type promotion case
                            return ascFloatComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                        } else if (leftValueChanged) {
                            // Type promotion happened. Left side was the source
                            return ascFloatComp.compare(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, b2, s2 + 1, l2 - 1);
                        } else {
                            // Type promotion happened. Right side was the source
                            return ascFloatComp.compare(b1, s1 + 1, l1 - 1, castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1);
                        }
                    }
                case DOUBLE:
                    {
                        if (!typePromotionApplied) {
                            // No type promotion case
                            return ascDoubleComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                        } else if (leftValueChanged) {
                            // Type promotion happened. Left side was the source
                            return ascDoubleComp.compare(castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1, b2, s2 + 1, l2 - 1);
                        } else {
                            // Type promotion happened. Right side was the source
                            return ascDoubleComp.compare(b1, s1 + 1, l1 - 1, castBuffer.getByteArray(), castBuffer.getStartOffset() + 1, castBuffer.getLength() - 1);
                        }
                    }
                case STRING:
                    {
                        return ascStrComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case RECTANGLE:
                    {
                        return ascRectangleComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case CIRCLE:
                    {
                        return ascCircleComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case POINT:
                    {
                        return ascPointComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case POINT3D:
                    {
                        return ascPoint3DComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case LINE:
                    {
                        return ascLineComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case POLYGON:
                    {
                        return ascPolygonComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case DURATION:
                    {
                        return ascDurationComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case INTERVAL:
                    {
                        return ascIntervalComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                case BINARY:
                    {
                        return ascByteArrayComp.compare(b1, s1 + 1, l1 - 1, b2, s2 + 1, l2 - 1);
                    }
                default:
                    {
                        // We include typeTag in comparison to compare between two type to enforce some ordering
                        return rawComp.compare(b1, s1, l1, b2, s2, l2);
                    }
            }
        }
    };
}
Also used : ITypeConvertComputer(org.apache.asterix.om.types.hierachy.ITypeConvertComputer) PointableBinaryComparatorFactory(org.apache.hyracks.data.std.accessors.PointableBinaryComparatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ATypeTag(org.apache.asterix.om.types.ATypeTag) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 63 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class AMurmurHash3BinaryHashFunctionFamily method createBinaryHashFunction.

// This hash function family is used to promote a numeric type to a DOUBLE numeric type
// to return same hash value for the original numeric value, regardless of the numeric type.
// (e.g., h( int64("1") )  =  h( double("1.0") )
@Override
public IBinaryHashFunction createBinaryHashFunction(final int seed) {
    return new IBinaryHashFunction() {

        private ArrayBackedValueStorage fieldValueBuffer = new ArrayBackedValueStorage();

        private DataOutput fieldValueBufferOutput = fieldValueBuffer.getDataOutput();

        private ATypeTag sourceTag = null;

        private boolean numericTypePromotionApplied = false;

        @Override
        public int hash(byte[] bytes, int offset, int length) throws HyracksDataException {
            // If a numeric type is encountered, then we promote each numeric type to the DOUBLE type.
            fieldValueBuffer.reset();
            sourceTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
            switch(sourceTag) {
                case TINYINT:
                case SMALLINT:
                case INTEGER:
                case BIGINT:
                    try {
                        IntegerToDoubleTypeConvertComputer.getInstance().convertType(bytes, offset + 1, length - 1, fieldValueBufferOutput);
                    } catch (IOException e) {
                        throw new HyracksDataException("A numeric type promotion error has occurred before doing hash(). Can't continue process. Detailed Error message:" + e.getMessage());
                    }
                    numericTypePromotionApplied = true;
                    break;
                case FLOAT:
                    try {
                        FloatToDoubleTypeConvertComputer.getInstance().convertType(bytes, offset + 1, length - 1, fieldValueBufferOutput);
                    } catch (IOException e) {
                        throw new HyracksDataException("A numeric type promotion error has occurred before doing hash(). Can't continue process. Detailed Error message:" + e.getMessage());
                    }
                    numericTypePromotionApplied = true;
                    break;
                default:
                    numericTypePromotionApplied = false;
                    break;
            }
            // If a numeric type promotion happened
            if (numericTypePromotionApplied) {
                return MurmurHash3BinaryHash.hash(fieldValueBuffer.getByteArray(), fieldValueBuffer.getStartOffset(), fieldValueBuffer.getLength(), seed);
            } else {
                // Usual case for non numeric types and the DOBULE numeric type
                return MurmurHash3BinaryHash.hash(bytes, offset, length, seed);
            }
        }
    };
}
Also used : DataOutput(java.io.DataOutput) IBinaryHashFunction(org.apache.hyracks.api.dataflow.value.IBinaryHashFunction) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ATypeTag(org.apache.asterix.om.types.ATypeTag) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 64 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class DatetimeFromUnixTimeInSecsDescriptor method createEvaluatorFactory.

/* (non-Javadoc)
     * @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
     */
@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 output types
                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ADateTime> datetimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);

                private AMutableDateTime aDatetime = new AMutableDateTime(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int offset = argPtr.getStartOffset();
                    ATypeTag argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
                    switch(argPtrTypeTag) {
                        case TINYINT:
                            aDatetime.setValue(AInt8SerializerDeserializer.getByte(bytes, offset + 1) * 1000l);
                            break;
                        case SMALLINT:
                            aDatetime.setValue(AInt16SerializerDeserializer.getShort(bytes, offset + 1) * 1000l);
                            break;
                        case INTEGER:
                            aDatetime.setValue(AInt32SerializerDeserializer.getInt(bytes, offset + 1) * 1000l);
                            break;
                        case BIGINT:
                            aDatetime.setValue(AInt64SerializerDeserializer.getLong(bytes, offset + 1) * 1000l);
                            break;
                        default:
                            throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG, ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
                    }
                    datetimeSerde.serialize(aDatetime, 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) AMutableDateTime(org.apache.asterix.om.base.AMutableDateTime) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ATypeTag(org.apache.asterix.om.types.ATypeTag) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)

Example 65 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class DayOfWeekDescriptor 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
                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private AMutableInt64 aInt64 = new AMutableInt64(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int offset = argPtr.getStartOffset();
                    int daysSinceAnchor;
                    int reminder = 0;
                    if (bytes[offset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
                        daysSinceAnchor = (int) (ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1) / GregorianCalendarSystem.CHRONON_OF_DAY);
                        reminder = (int) (ADateTimeSerializerDeserializer.getChronon(bytes, offset + 1) % GregorianCalendarSystem.CHRONON_OF_DAY);
                    } else if (bytes[offset] == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
                        daysSinceAnchor = ADateSerializerDeserializer.getChronon(bytes, offset + 1);
                    } else {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_DATETIME_TYPE_TAG, ATypeTag.SERIALIZED_DATE_TYPE_TAG);
                    }
                    // adjust the day before 1970-01-01
                    if (daysSinceAnchor < 0 && reminder != 0) {
                        daysSinceAnchor -= 1;
                    }
                    // compute the weekday (0-based, and 0 = Sunday). Adjustment is needed as
                    // the anchor day is Thursday.
                    int weekday = (daysSinceAnchor + ANCHOR_WEEKDAY) % 7;
                    // handle the negative weekday
                    if (weekday < 0) {
                        weekday += 7;
                    }
                    // convert from 0-based to 1-based (so 7 = Sunday)
                    if (weekday == 0) {
                        weekday = 7;
                    }
                    aInt64.setValue(weekday);
                    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

ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)190 IPointable (org.apache.hyracks.data.std.api.IPointable)144 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)144 DataOutput (java.io.DataOutput)140 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)138 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)131 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)129 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)129 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)116 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)110 IOException (java.io.IOException)90 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)78 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)25 ATypeTag (org.apache.asterix.om.types.ATypeTag)23 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)18 RecordBuilder (org.apache.asterix.builders.RecordBuilder)18 AString (org.apache.asterix.om.base.AString)18 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)17