Search in sources :

Example 6 with AMutablePoint

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

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

                private final IPointable inputArg1 = new VoidPointable();

                private final IPointable inputArg2 = new VoidPointable();

                private final IPointable inputArg3 = new VoidPointable();

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

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

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

                private final IScalarEvaluator eval3 = args[3].createScalarEvaluator(ctx);

                private final AMutableRectangle aRectangle = new AMutableRectangle(null, null);

                private final AMutablePoint[] aPoint = { new AMutablePoint(0, 0), new AMutablePoint(0, 0) };

                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<ARectangle> rectangleSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ARECTANGLE);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval0.evaluate(tuple, inputArg0);
                    eval1.evaluate(tuple, inputArg1);
                    eval2.evaluate(tuple, inputArg2);
                    eval3.evaluate(tuple, inputArg3);
                    byte[] bytes0 = inputArg0.getByteArray();
                    byte[] bytes1 = inputArg1.getByteArray();
                    byte[] bytes2 = inputArg2.getByteArray();
                    byte[] bytes3 = inputArg3.getByteArray();
                    int offset0 = inputArg0.getStartOffset();
                    int offset1 = inputArg1.getStartOffset();
                    int offset2 = inputArg2.getStartOffset();
                    int offset3 = inputArg3.getStartOffset();
                    try {
                        byte tag0 = bytes0[offset0];
                        byte tag1 = bytes1[offset1];
                        byte tag2 = bytes2[offset2];
                        byte tag3 = bytes3[offset3];
                        if (tag0 == ATypeTag.SERIALIZED_POINT_TYPE_TAG && tag1 == ATypeTag.SERIALIZED_POINT_TYPE_TAG && tag2 == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG && tag3 == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                            double xLoc = ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                            double yLoc = ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
                            double xOrigin = ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                            double yOrigin = ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
                            double xInc = ADoubleSerializerDeserializer.getDouble(bytes2, offset2 + 1);
                            double yInc = ADoubleSerializerDeserializer.getDouble(bytes3, offset3 + 1);
                            double x = xOrigin + (Math.floor((xLoc - xOrigin) / xInc)) * xInc;
                            double y = yOrigin + (Math.floor((yLoc - yOrigin) / yInc)) * yInc;
                            aPoint[0].setValue(x, y);
                            aPoint[1].setValue(x + xInc, y + yInc);
                            aRectangle.setValue(aPoint[0], aPoint[1]);
                            rectangleSerde.serialize(aRectangle, out);
                        } else {
                            if (tag0 != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
                                throw new TypeMismatchException(getIdentifier(), 0, tag0, ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                            }
                            if (tag1 != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
                                throw new TypeMismatchException(getIdentifier(), 1, tag1, ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                            }
                            if (tag2 != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                                throw new TypeMismatchException(getIdentifier(), 2, tag2, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                            }
                            if (tag3 != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                                throw new TypeMismatchException(getIdentifier(), 3, tag3, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                            }
                        }
                        result.set(resultStorage);
                    } catch (IOException e1) {
                        throw new HyracksDataException(e1);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) AMutableRectangle(org.apache.asterix.om.base.AMutableRectangle) 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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint) 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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint)

Example 7 with AMutablePoint

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

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

                private IPointable inputArg1 = new VoidPointable();

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

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

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

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

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    eval0.evaluate(tuple, inputArg0);
                    eval1.evaluate(tuple, inputArg1);
                    byte[] bytes0 = inputArg0.getByteArray();
                    int offset0 = inputArg0.getStartOffset();
                    byte[] bytes1 = inputArg1.getByteArray();
                    int offset1 = inputArg1.getStartOffset();
                    // type-check: (double, double)
                    if (bytes0[offset0] != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                    }
                    if (bytes1[offset1] != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                    }
                    resultStorage.reset();
                    try {
                        aPoint.setValue(ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + 1), ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + 1));
                        pointSerde.serialize(aPoint, out);
                    } catch (IOException e1) {
                        throw new HyracksDataException(e1);
                    }
                    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) 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) 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 8 with AMutablePoint

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

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

                private IPointable inputArg1 = new VoidPointable();

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

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

                private AMutableRectangle aRectangle = new AMutableRectangle(null, null);

                private AMutablePoint[] aPoint = { new AMutablePoint(0, 0), new AMutablePoint(0, 0) };

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ARectangle> rectangle2DSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ARECTANGLE);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    eval0.evaluate(tuple, inputArg0);
                    eval1.evaluate(tuple, inputArg1);
                    byte[] bytes0 = inputArg0.getByteArray();
                    int offset0 = inputArg0.getStartOffset();
                    byte[] bytes1 = inputArg1.getByteArray();
                    int offset1 = inputArg1.getStartOffset();
                    resultStorage.reset();
                    if (bytes0[offset0] != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                    }
                    if (bytes1[offset1] != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                    }
                    try {
                        aPoint[0].setValue(ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X)), ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y)));
                        aPoint[1].setValue(ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X)), ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y)));
                        if (aPoint[0].getX() > aPoint[1].getX() && aPoint[0].getY() > aPoint[1].getY()) {
                            aRectangle.setValue(aPoint[1], aPoint[0]);
                        } else if (aPoint[0].getX() < aPoint[1].getX() && aPoint[0].getY() < aPoint[1].getY()) {
                            aRectangle.setValue(aPoint[0], aPoint[1]);
                        } else {
                            throw new IllegalArgumentException("Rectangle arugment must be either (bottom left point, top right point) or (top right point, bottom left point)");
                        }
                        rectangle2DSerde.serialize(aRectangle, out);
                        result.set(resultStorage);
                    } catch (IOException e1) {
                        throw new HyracksDataException(e1);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) AMutableRectangle(org.apache.asterix.om.base.AMutableRectangle) 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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint) 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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint)

Example 9 with AMutablePoint

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

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

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

                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 {
                        double cX;
                        double cY;
                        if (bytes[startOffset] == ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG) {
                            cX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
                            cY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
                            aPoint.setValue(cX, cY);
                            pointSerde.serialize(aPoint, out);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG);
                        }
                    } 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) 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) 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 10 with AMutablePoint

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

the class APointConstructorDescriptor 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 AMutablePoint aPoint = new AMutablePoint(0, 0);

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

                private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        eval.evaluate(tuple, inputArg);
                        byte[] serString = inputArg.getByteArray();
                        int offset = inputArg.getStartOffset();
                        int len = inputArg.getLength();
                        if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            utf8Ptr.set(serString, offset + 1, len - 1);
                            String s = utf8Ptr.toString();
                            aPoint.setValue(Double.parseDouble(s.substring(0, s.indexOf(','))), Double.parseDouble(s.substring(s.indexOf(',') + 1, s.length())));
                            pointSerde.serialize(aPoint, out);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        result.set(resultStorage);
                    } catch (IOException e) {
                        throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) 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) APoint(org.apache.asterix.om.base.APoint) AMutablePoint(org.apache.asterix.om.base.AMutablePoint) 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)

Aggregations

DataOutput (java.io.DataOutput)11 IOException (java.io.IOException)11 AMutablePoint (org.apache.asterix.om.base.AMutablePoint)11 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)11 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)11 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)11 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)11 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)11 IPointable (org.apache.hyracks.data.std.api.IPointable)11 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)11 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)11 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)11 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)5 APoint (org.apache.asterix.om.base.APoint)4 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)4 AMutableRectangle (org.apache.asterix.om.base.AMutableRectangle)3 AMutableCircle (org.apache.asterix.om.base.AMutableCircle)2 AMutableLine (org.apache.asterix.om.base.AMutableLine)2 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)1