Search in sources :

Example 1 with AMutableLine

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

the class ALineConstructorDescriptor 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 AMutableLine aLine = new AMutableLine(null, null);

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

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ALine> lineSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ALINE);

                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();
                            int commaIndex = s.indexOf(',');
                            int spaceIndex = s.indexOf(' ', commaIndex + 1);
                            aPoint[0].setValue(Double.parseDouble(s.substring(0, commaIndex)), Double.parseDouble(s.substring(commaIndex + 1, spaceIndex)));
                            commaIndex = s.indexOf(',', spaceIndex + 1);
                            aPoint[1].setValue(Double.parseDouble(s.substring(spaceIndex + 1, commaIndex)), Double.parseDouble(s.substring(commaIndex + 1, s.length())));
                            aLine.setValue(aPoint[0], aPoint[1]);
                            lineSerde.serialize(aLine, 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_INTERVAL_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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) AMutableLine(org.apache.asterix.om.base.AMutableLine) 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 2 with AMutableLine

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

the class CreateLineDescriptor 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 AMutableLine aLine = new AMutableLine(null, null);

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

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ALine> lineSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ALINE);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    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: (point, point)
                    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)));
                        aLine.setValue(aPoint[0], aPoint[1]);
                        lineSerde.serialize(aLine, 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) AMutablePoint(org.apache.asterix.om.base.AMutablePoint) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) AMutableLine(org.apache.asterix.om.base.AMutableLine) 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)2 IOException (java.io.IOException)2 AMutableLine (org.apache.asterix.om.base.AMutableLine)2 AMutablePoint (org.apache.asterix.om.base.AMutablePoint)2 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)2 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)2 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)2 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)2 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)2 IPointable (org.apache.hyracks.data.std.api.IPointable)2 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)2 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)2 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)2 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)1