Search in sources :

Example 66 with VoidPointable

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

the class ExceptionIT method testFunction.

private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
    AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) funcFactory.createFunctionDescriptor();
    int inputArity = funcDesc.getIdentifier().getArity();
    Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
    while (argEvalFactoryIterator.hasNext()) {
        IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(argEvalFactoryIterator.next());
        IHyracksTaskContext ctx = mock(IHyracksTaskContext.class);
        IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx);
        IPointable resultPointable = new VoidPointable();
        try {
            evaluator.evaluate(null, resultPointable);
        } catch (Throwable e) {
            String msg = e.getMessage();
            if (msg == null) {
                continue;
            }
            if (msg.startsWith("ASX")) {
                // Verifies the error code.
                int errorCode = Integer.parseInt(msg.substring(3, 7));
                Assert.assertTrue(errorCode >= 0 && errorCode < 1000);
                continue;
            } else {
                // Any root-level data exceptions thrown from runtime functions should have an error code.
                Assert.assertTrue(!(e instanceof HyracksDataException) || (e.getCause() != null));
            }
        }
    }
}
Also used : IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) AbstractScalarFunctionDynamicDescriptor(org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 67 with VoidPointable

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

the class NullMissingTest method testFunction.

private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
    IFunctionDescriptor functionDescriptor = funcFactory.createFunctionDescriptor();
    if (!(functionDescriptor instanceof AbstractScalarFunctionDynamicDescriptor)) {
        return;
    }
    AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) functionDescriptor;
    int inputArity = funcDesc.getIdentifier().getArity();
    Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
    int index = 0;
    while (argEvalFactoryIterator.hasNext()) {
        IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(argEvalFactoryIterator.next());
        IHyracksTaskContext ctx = mock(IHyracksTaskContext.class);
        IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx);
        IPointable resultPointable = new VoidPointable();
        evaluator.evaluate(null, resultPointable);
        if (index != 0) {
            Assert.assertTrue(resultPointable.getByteArray()[resultPointable.getStartOffset()] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
        } else {
            Assert.assertTrue(resultPointable.getByteArray()[resultPointable.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG);
        }
        ++index;
    }
}
Also used : IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) AbstractScalarFunctionDynamicDescriptor(org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 68 with VoidPointable

use of org.apache.hyracks.data.std.primitive.VoidPointable 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 69 with VoidPointable

use of org.apache.hyracks.data.std.primitive.VoidPointable 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 70 with VoidPointable

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

the class SpatialDistanceDescriptor 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 IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);

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

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval0.evaluate(tuple, inputArg0);
                    eval1.evaluate(tuple, inputArg1);
                    try {
                        byte[] bytes0 = inputArg0.getByteArray();
                        byte[] bytes1 = inputArg1.getByteArray();
                        int offset0 = inputArg0.getStartOffset();
                        int offset1 = inputArg1.getStartOffset();
                        byte tag0 = bytes0[offset0];
                        byte tag1 = bytes1[offset1];
                        double distance;
                        if (tag0 == ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
                            if (tag1 == ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
                                double x1 = ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                                double y1 = ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
                                double x2 = ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                                double y2 = ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
                                distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
                            } else {
                                throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                            }
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                        }
                        out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                        out.writeDouble(distance);
                    } 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) 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)

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