Search in sources :

Example 56 with VoidPointable

use of org.apache.hyracks.data.std.primitive.VoidPointable in project asterixdb by apache.

the class ABooleanConstructorDescriptor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

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

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable inputArg = new VoidPointable();

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

                private final byte[] TRUE = UTF8StringUtil.writeStringToBytes("true");

                private final byte[] FALSE = UTF8StringUtil.writeStringToBytes("false");

                IBinaryComparator utf8BinaryComparator = BinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE.createBinaryComparator();

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ABoolean> booleanSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        eval.evaluate(tuple, inputArg);
                        byte[] serString = inputArg.getByteArray();
                        int startOffset = inputArg.getStartOffset();
                        int len = inputArg.getLength();
                        if (serString[startOffset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            if (utf8BinaryComparator.compare(serString, startOffset + 1, len - 1, TRUE, 0, TRUE.length) == 0) {
                                booleanSerde.serialize(ABoolean.TRUE, out);
                                result.set(resultStorage);
                                return;
                            } else if (utf8BinaryComparator.compare(serString, startOffset + 1, len - 1, FALSE, 0, FALSE.length) == 0) {
                                booleanSerde.serialize(ABoolean.FALSE, out);
                                result.set(resultStorage);
                                return;
                            } else {
                                throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG);
                            }
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, serString[startOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                    } catch (IOException e) {
                        throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator) 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) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) 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)

Example 57 with VoidPointable

use of org.apache.hyracks.data.std.primitive.VoidPointable in project asterixdb by apache.

the class TemporalYearAccessor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

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

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                private final IPointable argPtr = new VoidPointable();

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

                private final GregorianCalendarSystem calSystem = GregorianCalendarSystem.getInstance();

                private final UTF8StringPointable strExprPtr = new UTF8StringPointable();

                private final UTF8StringCharacterIterator strIter = new UTF8StringCharacterIterator();

                // for output: type integer
                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int startOffset = argPtr.getStartOffset();
                    int len = argPtr.getLength();
                    resultStorage.reset();
                    try {
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                            aMutableInt64.setValue(calSystem.getDurationYear(ADurationSerializerDeserializer.getYearMonth(bytes, startOffset + 1)));
                            intSerde.serialize(aMutableInt64, out);
                            result.set(resultStorage);
                            return;
                        }
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_YEAR_MONTH_DURATION_TYPE_TAG) {
                            aMutableInt64.setValue(calSystem.getDurationYear(AYearMonthDurationSerializerDeserializer.getYearMonth(bytes, startOffset + 1)));
                            intSerde.serialize(aMutableInt64, out);
                            result.set(resultStorage);
                            return;
                        }
                        long chrononTimeInMs = 0;
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
                            chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1) * GregorianCalendarSystem.CHRONON_OF_DAY;
                        } else if (bytes[startOffset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
                            chrononTimeInMs = AInt64SerializerDeserializer.getLong(bytes, startOffset + 1);
                        } else if (bytes[startOffset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            int year;
                            strExprPtr.set(bytes, startOffset + 1, len - 1);
                            strIter.reset(strExprPtr);
                            char firstChar = strIter.next();
                            if (firstChar == '-') {
                                // in case of a negative year
                                year = -1 * ((strIter.next() - '0') * 1000 + (strIter.next() - '0') * 100 + (strIter.next() - '0') * 10 + (strIter.next() - '0'));
                            } else {
                                year = (firstChar - '0') * 1000 + (strIter.next() - '0') * 100 + (strIter.next() - '0') * 10 + (strIter.next() - '0');
                            }
                            aMutableInt64.setValue(year);
                            intSerde.serialize(aMutableInt64, out);
                            result.set(resultStorage);
                            return;
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_YEAR_MONTH_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DATE_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG, ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        int year = calSystem.getYear(chrononTimeInMs);
                        aMutableInt64.setValue(year);
                        intSerde.serialize(aMutableInt64, out);
                        result.set(resultStorage);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) GregorianCalendarSystem(org.apache.asterix.om.base.temporal.GregorianCalendarSystem) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) 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) UTF8StringCharacterIterator(org.apache.hyracks.data.std.util.UTF8StringCharacterIterator) 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 58 with VoidPointable

use of org.apache.hyracks.data.std.primitive.VoidPointable in project asterixdb by apache.

the class CreateMBREvalFactory method createScalarEvaluator.

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

        private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

        private final DataOutput out = resultStorage.getDataOutput();

        private final IPointable inputArg0 = new VoidPointable();

        private final IPointable inputArg1 = new VoidPointable();

        private final IPointable inputArg2 = new VoidPointable();

        private IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);

        private IScalarEvaluator eval1 = dimensionEvalFactory.createScalarEvaluator(ctx);

        private IScalarEvaluator eval2 = coordinateEvalFactory.createScalarEvaluator(ctx);

        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            eval0.evaluate(tuple, inputArg0);
            eval1.evaluate(tuple, inputArg1);
            eval2.evaluate(tuple, inputArg2);
            byte[] data0 = inputArg0.getByteArray();
            byte[] data1 = inputArg1.getByteArray();
            byte[] data2 = inputArg2.getByteArray();
            int startOffset0 = inputArg0.getStartOffset();
            int startOffset1 = inputArg1.getStartOffset();
            int startOffset2 = inputArg2.getStartOffset();
            try {
                if (data0[startOffset0] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || data1[startOffset1] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || data2[startOffset2] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
                    out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
                    result.set(resultStorage);
                    return;
                }
                if (data0[startOffset0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG || data1[startOffset1] == ATypeTag.SERIALIZED_NULL_TYPE_TAG || data2[startOffset2] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                    out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
                    result.set(resultStorage);
                    return;
                }
                resultStorage.reset();
                if (data1[startOffset1] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
                    throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 1, data1[startOffset1], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                }
                int dimension = AInt32SerializerDeserializer.getInt(data1, startOffset1 + 1);
                if (data2[startOffset2] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
                    throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 2, data2[startOffset2], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                }
                int coordinate = AInt32SerializerDeserializer.getInt(data2, startOffset2 + 1);
                double value;
                if (dimension == 2) {
                    ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data0[startOffset0]);
                    switch(tag) {
                        case POINT:
                            switch(coordinate) {
                                // 0 is for min x, 1 is for min y, 2
                                case 0:
                                // max x, and 3 for max y
                                case 2:
                                    {
                                        double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                                        value = x;
                                    }
                                    break;
                                case 1:
                                case 3:
                                    {
                                        double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
                                        value = y;
                                    }
                                    break;
                                default:
                                    {
                                        throw new NotImplementedException(coordinate + " is not a valid coordinate option");
                                    }
                            }
                            break;
                        case LINE:
                            value = Double.MAX_VALUE;
                            switch(coordinate) {
                                case 0:
                                    {
                                        value = Double.MAX_VALUE;
                                        double startX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
                                        double endX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
                                        value = Math.min(Math.min(startX, endX), value);
                                    }
                                    break;
                                case 1:
                                    {
                                        value = Double.MAX_VALUE;
                                        double startY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
                                        double endY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
                                        value = Math.min(Math.min(startY, endY), value);
                                    }
                                    break;
                                case 2:
                                    {
                                        value = Double.MIN_VALUE;
                                        double startX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
                                        double endX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
                                        value = Math.max(Math.min(startX, endX), value);
                                    }
                                    break;
                                case 3:
                                    {
                                        value = Double.MIN_VALUE;
                                        double startY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
                                        double endY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
                                        value = Math.max(Math.min(startY, endY), value);
                                    }
                                    break;
                                default:
                                    {
                                        throw new NotImplementedException(coordinate + " is not a valid coordinate option");
                                    }
                            }
                            break;
                        case POLYGON:
                            int numOfPoints = AInt16SerializerDeserializer.getShort(data0, startOffset0 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
                            switch(coordinate) {
                                case 0:
                                    {
                                        value = Double.MAX_VALUE;
                                        for (int i = 0; i < numOfPoints; i++) {
                                            double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
                                            value = Math.min(x, value);
                                        }
                                    }
                                    break;
                                case 1:
                                    {
                                        value = Double.MAX_VALUE;
                                        for (int i = 0; i < numOfPoints; i++) {
                                            double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
                                            value = Math.min(y, value);
                                        }
                                    }
                                    break;
                                case 2:
                                    {
                                        value = Double.MIN_VALUE;
                                        for (int i = 0; i < numOfPoints; i++) {
                                            double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
                                            value = Math.max(x, value);
                                        }
                                    }
                                    break;
                                case 3:
                                    {
                                        value = Double.MIN_VALUE;
                                        for (int i = 0; i < numOfPoints; i++) {
                                            double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
                                            value = Math.max(y, value);
                                        }
                                    }
                                    break;
                                default:
                                    {
                                        throw new NotImplementedException(coordinate + " is not a valid coordinate option");
                                    }
                            }
                            break;
                        case CIRCLE:
                            switch(coordinate) {
                                case 0:
                                    {
                                        double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
                                        double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
                                        value = x - radius;
                                    }
                                    break;
                                case 1:
                                    {
                                        double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
                                        double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
                                        value = y - radius;
                                    }
                                    break;
                                case 2:
                                    {
                                        double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
                                        double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
                                        value = x + radius;
                                    }
                                    break;
                                case 3:
                                    {
                                        double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
                                        double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
                                        value = y + radius;
                                    }
                                    break;
                                default:
                                    {
                                        throw new NotImplementedException(coordinate + " is not a valid coordinate option");
                                    }
                            }
                            break;
                        case RECTANGLE:
                            switch(coordinate) {
                                case 0:
                                    {
                                        value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
                                    }
                                    break;
                                case 1:
                                    {
                                        value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
                                    }
                                    break;
                                case 2:
                                    {
                                        value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
                                    }
                                    break;
                                case 3:
                                    {
                                        value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
                                    }
                                    break;
                                default:
                                    {
                                        throw new NotImplementedException(coordinate + " is not a valid coordinate option");
                                    }
                            }
                            break;
                        default:
                            throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 0, data0[startOffset0], ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG, ATypeTag.SERIALIZED_POLYGON_TYPE_TAG, ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG, ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
                    }
                } else {
                    throw new NotImplementedException(dimension + "D is not supported");
                }
                out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                out.writeDouble(value);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
            result.set(resultStorage);
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) NotImplementedException(org.apache.hyracks.algebricks.common.exceptions.NotImplementedException) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ATypeTag(org.apache.asterix.om.types.ATypeTag) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)

Example 59 with VoidPointable

use of org.apache.hyracks.data.std.primitive.VoidPointable in project asterixdb by apache.

the class LineRectanglePolygonAccessor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

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

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                private final IPointable argPtr = new VoidPointable();

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

                private final OrderedListBuilder listBuilder = new OrderedListBuilder();

                private final ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();

                private final AOrderedListType pointListType = new AOrderedListType(BuiltinType.APOINT, null);

                private final AMutablePoint aPoint = new AMutablePoint(0, 0);

                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<APoint> pointSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.APOINT);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int startOffset = argPtr.getStartOffset();
                    resultStorage.reset();
                    try {
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_LINE_TYPE_TAG) {
                            listBuilder.reset(pointListType);
                            inputVal.reset();
                            double startX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
                            double startY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
                            aPoint.setValue(startX, startY);
                            pointSerde.serialize(aPoint, inputVal.getDataOutput());
                            listBuilder.addItem(inputVal);
                            inputVal.reset();
                            double endX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
                            double endY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
                            aPoint.setValue(endX, endY);
                            pointSerde.serialize(aPoint, inputVal.getDataOutput());
                            listBuilder.addItem(inputVal);
                            listBuilder.write(out, true);
                        } else if (bytes[startOffset] == ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG) {
                            listBuilder.reset(pointListType);
                            inputVal.reset();
                            double x1 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
                            double y1 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
                            aPoint.setValue(x1, y1);
                            pointSerde.serialize(aPoint, inputVal.getDataOutput());
                            listBuilder.addItem(inputVal);
                            inputVal.reset();
                            double x2 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
                            double y2 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
                            aPoint.setValue(x2, y2);
                            pointSerde.serialize(aPoint, inputVal.getDataOutput());
                            listBuilder.addItem(inputVal);
                            listBuilder.write(out, true);
                        } else if (bytes[startOffset] == ATypeTag.SERIALIZED_POLYGON_TYPE_TAG) {
                            int numOfPoints = AInt16SerializerDeserializer.getShort(bytes, startOffset + APolygonSerializerDeserializer.getNumberOfPointsOffset());
                            if (numOfPoints < 3) {
                                throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                            }
                            listBuilder.reset(pointListType);
                            for (int i = 0; i < numOfPoints; ++i) {
                                inputVal.reset();
                                double x = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
                                double y = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
                                aPoint.setValue(x, y);
                                pointSerde.serialize(aPoint, inputVal.getDataOutput());
                                listBuilder.addItem(inputVal);
                            }
                            listBuilder.write(out, true);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_LINE_TYPE_TAG, ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG, ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                        }
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) 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) APoint(org.apache.asterix.om.base.APoint) AMutablePoint(org.apache.asterix.om.base.AMutablePoint) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) 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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint)

Example 60 with VoidPointable

use of org.apache.hyracks.data.std.primitive.VoidPointable in project asterixdb by apache.

the class TemporalHourAccessor method createEvaluatorFactory.

/* (non-Javadoc)
     * @see org.apache.asterix.om.function.IFunctionDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory[])
     */
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

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

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                private final IPointable argPtr = new VoidPointable();

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

                private final GregorianCalendarSystem calSystem = GregorianCalendarSystem.getInstance();

                // for output: type integer
                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int startOffset = argPtr.getStartOffset();
                    resultStorage.reset();
                    try {
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                            aMutableInt64.setValue(calSystem.getDurationHour(ADurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
                            intSerde.serialize(aMutableInt64, out);
                            result.set(resultStorage);
                            return;
                        }
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
                            aMutableInt64.setValue(calSystem.getDurationHour(ADayTimeDurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
                            intSerde.serialize(aMutableInt64, out);
                            result.set(resultStorage);
                            return;
                        }
                        long chrononTimeInMs = 0;
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
                            chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1);
                        } else if (bytes[startOffset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
                            chrononTimeInMs = AInt64SerializerDeserializer.getLong(bytes, startOffset + 1);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_TIME_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
                        }
                        int hour = calSystem.getHourOfDay(chrononTimeInMs);
                        aMutableInt64.setValue(hour);
                        intSerde.serialize(aMutableInt64, out);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) GregorianCalendarSystem(org.apache.asterix.om.base.temporal.GregorianCalendarSystem) 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) 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

IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)136 IPointable (org.apache.hyracks.data.std.api.IPointable)136 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)136 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)134 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)129 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)126 DataOutput (java.io.DataOutput)125 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)124 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)114 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)98 IOException (java.io.IOException)84 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)64 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)24 ATypeTag (org.apache.asterix.om.types.ATypeTag)21 AsterixException (org.apache.asterix.common.exceptions.AsterixException)14 GregorianCalendarSystem (org.apache.asterix.om.base.temporal.GregorianCalendarSystem)13 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)11 AMutablePoint (org.apache.asterix.om.base.AMutablePoint)11