Search in sources :

Example 11 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)

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