Search in sources :

Example 96 with ArrayBackedValueStorage

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

the class IntegerAddEvalFactory method createScalarEvaluator.

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

        private IPointable p = VoidPointable.FACTORY.createPointable();

        private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();

        private IScalarEvaluator evalLeft = evalLeftFactory.createScalarEvaluator(ctx);

        private IScalarEvaluator evalRight = evalRightFactory.createScalarEvaluator(ctx);

        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            evalLeft.evaluate(tuple, p);
            int v1 = IntegerPointable.getInteger(p.getByteArray(), p.getStartOffset());
            evalRight.evaluate(tuple, p);
            int v2 = IntegerPointable.getInteger(p.getByteArray(), p.getStartOffset());
            try {
                argOut.reset();
                argOut.getDataOutput().writeInt(v1 + v2);
                result.set(argOut);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) 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)

Example 97 with ArrayBackedValueStorage

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

the class TupleCountAggregateFunctionFactory method createAggregateEvaluator.

@Override
public IAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
    final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    return new IAggregateEvaluator() {

        int cnt;

        @Override
        public void step(IFrameTupleReference tuple) throws HyracksDataException {
            ++cnt;
        }

        @Override
        public void init() throws HyracksDataException {
            cnt = 0;
        }

        @Override
        public void finish(IPointable result) throws HyracksDataException {
            try {
                abvs.reset();
                abvs.getDataOutput().writeInt(cnt);
                result.set(abvs);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void finishPartial(IPointable result) throws HyracksDataException {
            finish(result);
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 98 with ArrayBackedValueStorage

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

the class TupleCountRunningAggregateFunctionFactory method createRunningAggregateEvaluator.

@Override
public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
    final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    return new IRunningAggregateEvaluator() {

        int cnt;

        @Override
        public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            try {
                ++cnt;
                abvs.reset();
                abvs.getDataOutput().writeInt(cnt);
                result.set(abvs);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void init() throws HyracksDataException {
            cnt = 0;
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IRunningAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 99 with ArrayBackedValueStorage

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

the class SpatialAreaDescriptor 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);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argPtr);
                    try {
                        byte[] bytes = argPtr.getByteArray();
                        int offset = argPtr.getStartOffset();
                        ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
                        double area = 0.0;
                        switch(tag) {
                            case POLYGON:
                                int numOfPoints = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
                                if (numOfPoints < 3) {
                                    throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                                }
                                area = Math.abs(SpatialUtils.polygonArea(bytes, offset, numOfPoints));
                                out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                                out.writeDouble(area);
                                break;
                            case CIRCLE:
                                double radius = ADoubleSerializerDeserializer.getDouble(bytes, offset + ACircleSerializerDeserializer.getRadiusOffset());
                                area = SpatialUtils.pi() * radius * radius;
                                out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                                out.writeDouble(area);
                                break;
                            case RECTANGLE:
                                double x1 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
                                double y1 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
                                double x2 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
                                double y2 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
                                area = (x2 - x1) * (y2 - y1);
                                out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                                out.writeDouble(area);
                                break;
                            default:
                                throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_POLYGON_TYPE_TAG, ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG, ATypeTag.SERIALIZED_RECTANGLE_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) 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) 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 100 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage 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)

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