asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [09/22] asterixdb git commit: Unify runtime type exceptions by using error code and message template.
Date Tue, 01 Nov 2016 03:08:18 GMT
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
index 03ec9a6..e4704f2 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
@@ -40,8 +40,8 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.common.DoubleArray;
 import org.apache.asterix.runtime.evaluators.common.SpatialUtils;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
+import org.apache.asterix.runtime.exceptions.InvalidDataFormatException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
@@ -65,13 +65,12 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
 
                     private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@@ -123,8 +122,7 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                                 offset1 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
 
                         if (numOfPoints1 < 3) {
-                            throw new HyracksDataException(AsterixBuiltinFunctions.SPATIAL_INTERSECT.getName()
-                                    + ": polygon must have at least 3 points.");
+                            throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                         }
 
                         int counter = 0;
@@ -233,8 +231,7 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                                 offset1 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
 
                         if (numOfPoints1 < 3) {
-                            throw new HyracksDataException(AsterixBuiltinFunctions.SPATIAL_INTERSECT.getName()
-                                    + ": polygon must have at least 3 points.");
+                            throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                         }
                         for (int i = 0; i < numOfPoints1; i++) {
                             double startX2 = ADoubleSerializerDeserializer.getDouble(bytes1,
@@ -386,8 +383,8 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                         int v = middleVertex;
                         while (!foundEar) {
                             if (0 >= (nonSimplePolygonDetection--)) {
-                                throw new HyracksDataException(AsterixBuiltinFunctions.SPATIAL_INTERSECT.getName()
-                                        + ": non-simple polygons are not supported.");
+                                throw new InvalidDataFormatException(getIdentifier(),
+                                        ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                             }
                             int u = v;
                             if (numOfPoints <= u) {
@@ -674,13 +671,12 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                     }
 
                     private boolean rectanglePolygonIntersection(byte[] bytes0, int offset0, byte[] bytes1, int offset1)
-                            throws HyracksDataException, AlgebricksException {
+                            throws HyracksDataException {
                         int numOfPoints1 = AInt16SerializerDeserializer.getShort(bytes1,
                                 offset1 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
 
                         if (numOfPoints1 < 3) {
-                            throw new HyracksDataException(AsterixBuiltinFunctions.SPATIAL_INTERSECT.getName()
-                                    + ": polygon must have at least 3 points.");
+                            throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                         }
 
                         getCounterClockWisePolygon(bytes1, offset1, pointsOffsets1, numOfPoints1);
@@ -727,13 +723,12 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                     }
 
                     private boolean polygonCircleIntersection(byte[] bytes0, int offset0, byte[] bytes1, int offset1)
-                            throws HyracksDataException, AlgebricksException {
+                            throws HyracksDataException {
                         int numOfPoints = AInt16SerializerDeserializer.getShort(bytes0,
                                 offset0 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
 
                         if (numOfPoints < 3) {
-                            throw new HyracksDataException(AsterixBuiltinFunctions.SPATIAL_INTERSECT.getName()
-                                    + ": polygon must have at least 3 points.");
+                            throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                         }
 
                         getCounterClockWisePolygon(bytes0, offset0, pointsOffsets0, numOfPoints);
@@ -765,7 +760,7 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                     }
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, inputArg0);
                         eval1.evaluate(tuple, inputArg1);
@@ -775,305 +770,313 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                         int offset0 = inputArg0.getStartOffset();
                         int offset1 = inputArg1.getStartOffset();
 
-                        try {
-                            boolean res = false;
-                            ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]);
-                            ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]);
-
-                            switch (tag0) {
-                                case POINT:
-                                    switch (tag1) {
-                                        case POINT:
+                        boolean res = false;
+                        ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]);
+                        ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]);
+
+                        switch (tag0) {
+                            case POINT:
+                                switch (tag1) {
+                                    case POINT:
+                                        if (ascDoubleComp.compare(bytes0,
+                                                offset0 + APointSerializerDeserializer
+                                                        .getCoordinateOffset(Coordinate.X),
+                                                8, bytes1, offset1 + APointSerializerDeserializer
+                                                        .getCoordinateOffset(Coordinate.X),
+                                                8) == 0) {
                                             if (ascDoubleComp.compare(bytes0,
                                                     offset0 + APointSerializerDeserializer
-                                                            .getCoordinateOffset(Coordinate.X),
+                                                            .getCoordinateOffset(Coordinate.Y),
                                                     8, bytes1, offset1 + APointSerializerDeserializer
-                                                            .getCoordinateOffset(Coordinate.X),
+                                                            .getCoordinateOffset(Coordinate.Y),
                                                     8) == 0) {
-                                                if (ascDoubleComp.compare(bytes0,
-                                                        offset0 + APointSerializerDeserializer
-                                                                .getCoordinateOffset(Coordinate.Y),
-                                                        8, bytes1, offset1 + APointSerializerDeserializer
-                                                                .getCoordinateOffset(Coordinate.Y),
-                                                        8) == 0) {
-                                                    res = true;
-                                                }
-                                            }
-                                            break;
-                                        case LINE:
-                                            double pX = ADoubleSerializerDeserializer.getDouble(bytes0, offset0
-                                                    + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
-                                            double pY = ADoubleSerializerDeserializer.getDouble(bytes0, offset0
-                                                    + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
-
-                                            double startX = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.X));
-                                            double startY = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.Y));
-                                            double endX = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.X));
-                                            double endY = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.Y));
-
-                                            res = pointOnLine(pX, pY, startX, startY, endX, endY);
-                                            break;
-                                        case POLYGON:
-                                            res = pointInPolygon(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case CIRCLE:
-                                            res = pointInCircle(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case RECTANGLE:
-                                            res = pointInRectangle(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        default:
-                                            throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
-                                                    .getName() + ": does not support the type: " + tag1
-                                                    + "; it is only implemented for POINT, ALINE, POLYGON, and CIRCLE.");
-                                    }
-                                    break;
-                                case LINE:
-                                    switch (tag1) {
-                                        case POINT:
-                                            double pX = ADoubleSerializerDeserializer.getDouble(bytes1, offset1
-                                                    + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
-                                            double pY = ADoubleSerializerDeserializer.getDouble(bytes1, offset1
-                                                    + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
-
-                                            double startX = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.X));
-                                            double startY = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.Y));
-                                            double endX = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.X));
-                                            double endY = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.Y));
-
-                                            res = pointOnLine(pX, pY, startX, startY, endX, endY);
-                                            break;
-                                        case LINE:
-                                            double startX1 = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.X));
-                                            double startY1 = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.Y));
-                                            double endX1 = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.X));
-                                            double endY1 = ADoubleSerializerDeserializer.getDouble(bytes0,
-                                                    offset0 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.Y));
-
-                                            double startX2 = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.X));
-                                            double startY2 = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getStartPointCoordinateOffset(Coordinate.Y));
-                                            double endX2 = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.X));
-                                            double endY2 = ADoubleSerializerDeserializer.getDouble(bytes1,
-                                                    offset1 + ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.Y));
-                                            res = lineLineIntersection(startX1, startY1, endX1, endY1, startX2, startY2,
-                                                    endX2, endY2);
-                                            break;
-                                        case POLYGON:
-                                            res = linePolygonIntersection(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case CIRCLE:
-                                            res = lineCircleIntersection(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case RECTANGLE:
-                                            res = lineRectangleIntersection(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        default:
-                                            throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
-                                                    .getName() + ": does not support the type: " + tag1
-                                                    + "; it is only implemented for POINT, ALINE, POLYGON, and CIRCLE.");
-                                    }
-                                    break;
-                                case POLYGON:
-                                    switch (tag1) {
-                                        case POINT:
-                                            res = pointInPolygon(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        case LINE:
-                                            res = linePolygonIntersection(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        case POLYGON:
-                                            int numOfPoints0 = AInt16SerializerDeserializer.getShort(bytes0,
-                                                    offset0 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
-                                            int numOfPoints1 = AInt16SerializerDeserializer.getShort(bytes1,
-                                                    offset1 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
-
-                                            if (numOfPoints0 < 3 || numOfPoints1 < 3) {
-                                                throw new AlgebricksException("Polygon must have at least 3 points.");
+                                                res = true;
                                             }
+                                        }
+                                        break;
+                                    case LINE:
+                                        double pX = ADoubleSerializerDeserializer.getDouble(bytes0, offset0
+                                                + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
+                                        double pY = ADoubleSerializerDeserializer.getDouble(bytes0, offset0
+                                                + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
+
+                                        double startX = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.X));
+                                        double startY = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.Y));
+                                        double endX = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.X));
+                                        double endY = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.Y));
+
+                                        res = pointOnLine(pX, pY, startX, startY, endX, endY);
+                                        break;
+                                    case POLYGON:
+                                        res = pointInPolygon(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case CIRCLE:
+                                        res = pointInCircle(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case RECTANGLE:
+                                        res = pointInRectangle(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    default:
+                                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                                ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_POLYGON_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
+                                }
+                                break;
+                            case LINE:
+                                switch (tag1) {
+                                    case POINT:
+                                        double pX = ADoubleSerializerDeserializer.getDouble(bytes1, offset1
+                                                + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
+                                        double pY = ADoubleSerializerDeserializer.getDouble(bytes1, offset1
+                                                + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
+
+                                        double startX = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.X));
+                                        double startY = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.Y));
+                                        double endX = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.X));
+                                        double endY = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.Y));
+
+                                        res = pointOnLine(pX, pY, startX, startY, endX, endY);
+                                        break;
+                                    case LINE:
+                                        double startX1 = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.X));
+                                        double startY1 = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.Y));
+                                        double endX1 = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.X));
+                                        double endY1 = ADoubleSerializerDeserializer.getDouble(bytes0,
+                                                offset0 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.Y));
+
+                                        double startX2 = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.X));
+                                        double startY2 = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getStartPointCoordinateOffset(Coordinate.Y));
+                                        double endX2 = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.X));
+                                        double endY2 = ADoubleSerializerDeserializer.getDouble(bytes1,
+                                                offset1 + ALineSerializerDeserializer
+                                                        .getEndPointCoordinateOffset(Coordinate.Y));
+                                        res = lineLineIntersection(startX1, startY1, endX1, endY1, startX2, startY2,
+                                                endX2, endY2);
+                                        break;
+                                    case POLYGON:
+                                        res = linePolygonIntersection(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case CIRCLE:
+                                        res = lineCircleIntersection(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case RECTANGLE:
+                                        res = lineRectangleIntersection(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    default:
+                                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                                ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_POLYGON_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
+                                }
+                                break;
+                            case POLYGON:
+                                switch (tag1) {
+                                    case POINT:
+                                        res = pointInPolygon(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    case LINE:
+                                        res = linePolygonIntersection(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    case POLYGON:
+                                        int numOfPoints0 = AInt16SerializerDeserializer.getShort(bytes0,
+                                                offset0 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
+                                        int numOfPoints1 = AInt16SerializerDeserializer.getShort(bytes1,
+                                                offset1 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
+
+                                        if (numOfPoints0 < 3 || numOfPoints1 < 3) {
+                                            throw new InvalidDataFormatException(getIdentifier(),
+                                                    ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
+                                        }
 
-                                            getCounterClockWisePolygon(bytes0, offset0, pointsOffsets0, numOfPoints0);
-                                            getCounterClockWisePolygon(bytes1, offset1, pointsOffsets1, numOfPoints1);
-                                            int nonSimplePolygonDetection0 = 2 * numOfPoints0;
-                                            int nonSimplePolygonDetection1 = 2 * numOfPoints1;
-                                            boolean intersect = false;
-                                            int middleVertex0 = numOfPoints0 - 1;
-
-                                            int numOfTriangles1 = 0;
-                                            int middleVertex1 = numOfPoints1 - 1;
-                                            trianglesX1.reset();
-                                            trianglesY1.reset();
-                                            while (true) {
-                                                middleVertex1 = triangulatePolygon(bytes1, offset1, numOfPoints1,
-                                                        pointsOffsets1, trianglesX1, trianglesY1, numOfTriangles1,
-                                                        nonSimplePolygonDetection1, middleVertex1);
-
-                                                if (middleVertex1 == -1) {
-                                                    break;
-                                                }
+                                        getCounterClockWisePolygon(bytes0, offset0, pointsOffsets0, numOfPoints0);
+                                        getCounterClockWisePolygon(bytes1, offset1, pointsOffsets1, numOfPoints1);
+                                        int nonSimplePolygonDetection0 = 2 * numOfPoints0;
+                                        int nonSimplePolygonDetection1 = 2 * numOfPoints1;
+                                        boolean intersect = false;
+                                        int middleVertex0 = numOfPoints0 - 1;
+
+                                        int numOfTriangles1 = 0;
+                                        int middleVertex1 = numOfPoints1 - 1;
+                                        trianglesX1.reset();
+                                        trianglesY1.reset();
+                                        while (true) {
+                                            middleVertex1 = triangulatePolygon(bytes1, offset1, numOfPoints1,
+                                                    pointsOffsets1, trianglesX1, trianglesY1, numOfTriangles1,
+                                                    nonSimplePolygonDetection1, middleVertex1);
+
+                                            if (middleVertex1 == -1) {
+                                                break;
+                                            }
 
-                                                numOfPoints1--;
-                                                nonSimplePolygonDetection1 = 2 * numOfPoints1;
-                                                numOfTriangles1++;
+                                            numOfPoints1--;
+                                            nonSimplePolygonDetection1 = 2 * numOfPoints1;
+                                            numOfTriangles1++;
+                                        }
+                                        int numOfTriangles0 = 0;
+                                        trianglesX0.reset();
+                                        trianglesY0.reset();
+                                        while (true) {
+                                            middleVertex0 = triangulatePolygon(bytes0, offset0, numOfPoints0,
+                                                    pointsOffsets0, trianglesX0, trianglesY0, numOfTriangles0,
+                                                    nonSimplePolygonDetection0, middleVertex0);
+
+                                            if (middleVertex0 == -1) {
+                                                break;
                                             }
-                                            int numOfTriangles0 = 0;
-                                            trianglesX0.reset();
-                                            trianglesY0.reset();
-                                            while (true) {
-                                                middleVertex0 = triangulatePolygon(bytes0, offset0, numOfPoints0,
-                                                        pointsOffsets0, trianglesX0, trianglesY0, numOfTriangles0,
-                                                        nonSimplePolygonDetection0, middleVertex0);
-
-                                                if (middleVertex0 == -1) {
-                                                    break;
-                                                }
-                                                numOfPoints0--;
-                                                nonSimplePolygonDetection0 = 2 * numOfPoints0;
-                                                numOfTriangles0++;
-                                                int lastTriangle = (trianglesX0.length() / 3) - 1;
+                                            numOfPoints0--;
+                                            nonSimplePolygonDetection0 = 2 * numOfPoints0;
+                                            numOfTriangles0++;
+                                            int lastTriangle = (trianglesX0.length() / 3) - 1;
 
-                                                for (int i = 0; i < numOfTriangles1; i++) {
+                                            for (int i = 0; i < numOfTriangles1; i++) {
 
-                                                    res = triangleTriangleIntersection(trianglesX0, trianglesY0,
-                                                            lastTriangle, trianglesX1, trianglesY1, i);
+                                                res = triangleTriangleIntersection(trianglesX0, trianglesY0,
+                                                        lastTriangle, trianglesX1, trianglesY1, i);
 
-                                                    if (res) {
-                                                        res = triangleTriangleIntersection(trianglesX1, trianglesY1, i,
-                                                                trianglesX0, trianglesY0, lastTriangle);
+                                                if (res) {
+                                                    res = triangleTriangleIntersection(trianglesX1, trianglesY1, i,
+                                                            trianglesX0, trianglesY0, lastTriangle);
 
-                                                        if (res) {
-                                                            intersect = true;
-                                                            break;
-                                                        }
+                                                    if (res) {
+                                                        intersect = true;
+                                                        break;
                                                     }
                                                 }
-                                                if (intersect) {
-                                                    break;
-                                                }
                                             }
-                                            break;
-                                        case CIRCLE:
-                                            res = polygonCircleIntersection(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case RECTANGLE:
-                                            res = rectanglePolygonIntersection(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        default:
-                                            throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
-                                                    .getName() + ": does not support the type: " + tag1
-                                                    + "; it is only implemented for POINT, ALINE, POLYGON, and CIRCLE.");
-                                    }
-                                    break;
-                                case CIRCLE:
-                                    switch (tag1) {
-                                        case POINT:
-                                            res = pointInCircle(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case LINE:
-                                            res = lineCircleIntersection(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        case POLYGON:
-                                            res = polygonCircleIntersection(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        case CIRCLE:
-                                            res = circleCircleIntersection(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case RECTANGLE:
-                                            res = rectangleCircleIntersection(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        default:
-                                            throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
-                                                    .getName() + ": does not support the type: " + tag1
-                                                    + "; it is only implemented for POINT, ALINE, POLYGON, and CIRCLE.");
-                                    }
-                                    break;
-                                case RECTANGLE:
-                                    switch (tag1) {
-                                        case POINT:
-                                            res = pointInRectangle(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        case LINE:
-                                            res = lineRectangleIntersection(bytes1, offset1, bytes0, offset0);
-                                            break;
-                                        case POLYGON:
-                                            res = rectanglePolygonIntersection(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case CIRCLE:
-                                            res = rectangleCircleIntersection(bytes0, offset0, bytes1, offset1);
-                                            break;
-                                        case RECTANGLE:
-                                            triangulateRectangle(bytes0, offset0, trianglesX0, trianglesY0);
-                                            triangulateRectangle(bytes1, offset1, trianglesX1, trianglesY1);
-
-                                            boolean intersect = false;
-                                            // 2 triangles in a rectangle
-                                            for (int j = 0; j < 2; j++) {
-                                                for (int i = 0; i < 2; i++) {
-
-                                                    res = triangleTriangleIntersection(trianglesX1, trianglesY1, i,
-                                                            trianglesX0, trianglesY0, j);
+                                            if (intersect) {
+                                                break;
+                                            }
+                                        }
+                                        break;
+                                    case CIRCLE:
+                                        res = polygonCircleIntersection(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case RECTANGLE:
+                                        res = rectanglePolygonIntersection(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    default:
+                                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                                ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_POLYGON_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
+                                }
+                                break;
+                            case CIRCLE:
+                                switch (tag1) {
+                                    case POINT:
+                                        res = pointInCircle(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case LINE:
+                                        res = lineCircleIntersection(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    case POLYGON:
+                                        res = polygonCircleIntersection(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    case CIRCLE:
+                                        res = circleCircleIntersection(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case RECTANGLE:
+                                        res = rectangleCircleIntersection(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    default:
+                                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                                ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_POLYGON_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
+                                }
+                                break;
+                            case RECTANGLE:
+                                switch (tag1) {
+                                    case POINT:
+                                        res = pointInRectangle(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    case LINE:
+                                        res = lineRectangleIntersection(bytes1, offset1, bytes0, offset0);
+                                        break;
+                                    case POLYGON:
+                                        res = rectanglePolygonIntersection(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case CIRCLE:
+                                        res = rectangleCircleIntersection(bytes0, offset0, bytes1, offset1);
+                                        break;
+                                    case RECTANGLE:
+                                        triangulateRectangle(bytes0, offset0, trianglesX0, trianglesY0);
+                                        triangulateRectangle(bytes1, offset1, trianglesX1, trianglesY1);
+
+                                        boolean intersect = false;
+                                        // 2 triangles in a rectangle
+                                        for (int j = 0; j < 2; j++) {
+                                            for (int i = 0; i < 2; i++) {
+
+                                                res = triangleTriangleIntersection(trianglesX1, trianglesY1, i,
+                                                        trianglesX0, trianglesY0, j);
+
+                                                if (res) {
+                                                    res = triangleTriangleIntersection(trianglesX0, trianglesY0, j,
+                                                            trianglesX1, trianglesY1, i);
 
                                                     if (res) {
-                                                        res = triangleTriangleIntersection(trianglesX0, trianglesY0, j,
-                                                                trianglesX1, trianglesY1, i);
-
-                                                        if (res) {
-                                                            intersect = true;
-                                                            break;
-                                                        }
+                                                        intersect = true;
+                                                        break;
                                                     }
                                                 }
-                                                if (intersect) {
-                                                    break;
-                                                }
                                             }
-                                            break;
-                                        default:
-                                            throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
-                                                    .getName() + ": does not support the type: " + tag1
-                                                    + "; it is only implemented for POINT, ALINE, POLYGON, and CIRCLE.");
-                                    }
-                                    break;
-                                default:
-                                    throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
-                                            .getName() + ": does not support the type: " + tag1
-                                            + "; it is only implemented for POINT, ALINE, POLYGON, and CIRCLE.");
-                            }
-
-                            ABoolean aResult = res ? (ABoolean.TRUE) : (ABoolean.FALSE);
-                            aBooleanSerDer.serialize(aResult, out);
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
+                                            if (intersect) {
+                                                break;
+                                            }
+                                        }
+                                        break;
+                                    default:
+                                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                                ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_POLYGON_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG,
+                                                ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
+                                }
+                                break;
+                            default:
+                                throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0],
+                                        ATypeTag.SERIALIZED_POINT_TYPE_TAG, ATypeTag.SERIALIZED_LINE_TYPE_TAG,
+                                        ATypeTag.SERIALIZED_POLYGON_TYPE_TAG, ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG,
+                                        ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
                         }
+
+                        ABoolean aResult = res ? ABoolean.TRUE : ABoolean.FALSE;
+                        aBooleanSerDer.serialize(aResult, out);
                         result.set(resultStorage);
                     }
                 };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringConcatDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
index 07a79c4..1936902 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
@@ -23,21 +23,23 @@ import java.io.IOException;
 
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import org.apache.asterix.om.base.AMissing;
 import org.apache.asterix.om.base.ANull;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.common.AsterixListAccessor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -57,11 +59,10 @@ public class StringConcatDescriptor extends AbstractScalarFunctionDynamicDescrip
     @Override
     public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
-
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
 
                     private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@@ -73,10 +74,12 @@ public class StringConcatDescriptor extends AbstractScalarFunctionDynamicDescrip
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private ISerializerDeserializer<AMissing> missingSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AMISSING);
                     private final byte[] tempLengthArray = new byte[5];
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         try {
                             evalList.evaluate(tuple, inputArgList);
@@ -85,15 +88,11 @@ public class StringConcatDescriptor extends AbstractScalarFunctionDynamicDescrip
 
                             if (listBytes[listOffset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
                                     && listBytes[listOffset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
-                                throw new AlgebricksException(AsterixBuiltinFunctions.STRING_CONCAT.getName()
-                                        + ": expects input type ORDEREDLIST/UNORDEREDLIST, but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(listBytes[listOffset]));
-                            }
-                            try {
-                                listAccessor.reset(listBytes, listOffset);
-                            } catch (AsterixException e) {
-                                throw new AlgebricksException(e);
+                                throw new TypeMismatchException(getIdentifier(), 0, listBytes[listOffset],
+                                        ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG,
+                                        ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
                             }
+                            listAccessor.reset(listBytes, listOffset);
                             try {
                                 // calculate length first
                                 int utf8Len = 0;
@@ -111,15 +110,18 @@ public class StringConcatDescriptor extends AbstractScalarFunctionDynamicDescrip
                                             result.set(resultStorage);
                                             return;
                                         }
-                                        throw new AlgebricksException(AsterixBuiltinFunctions.STRING_CONCAT.getName()
-                                                + ": expects type STRING/NULL for the list item but got " + itemType);
+                                        if (itemType == ATypeTag.MISSING) {
+                                            missingSerde.serialize(AMissing.MISSING, out);
+                                            result.set(resultStorage);
+                                            return;
+                                        }
+                                        throw new UnsupportedItemTypeException(getIdentifier(), itemType.serialize());
                                     }
                                     utf8Len += UTF8StringUtil.getUTFLength(listBytes, itemOffset);
                                 }
                                 out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                                 int cbytes = UTF8StringUtil.encodeUTF8Length(utf8Len, tempLengthArray, 0);
                                 out.write(tempLengthArray, 0, cbytes);
-
                                 for (int i = 0; i < listAccessor.size(); i++) {
                                     int itemOffset = listAccessor.getItemOffset(i);
                                     if (listAccessor.itemsAreSelfDescribing()) {
@@ -130,10 +132,10 @@ public class StringConcatDescriptor extends AbstractScalarFunctionDynamicDescrip
                                             utf8Len);
                                 }
                             } catch (AsterixException ex) {
-                                throw new AlgebricksException(ex);
+                                throw new HyracksDataException(ex);
                             }
                         } catch (IOException e1) {
-                            throw new AlgebricksException(e1.getMessage());
+                            throw new HyracksDataException(e1);
                         }
                         result.set(resultStorage);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringContainsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringContainsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringContainsDescriptor.java
index 5d88b6c..7786f0e 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringContainsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringContainsDescriptor.java
@@ -24,11 +24,11 @@ import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
 public class StringContainsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -42,14 +42,12 @@ public class StringContainsDescriptor extends AbstractScalarFunctionDynamicDescr
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
-
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new AbstractBinaryStringBoolEval(ctx, args[0], args[1],
                         AsterixBuiltinFunctions.STRING_CONTAINS) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEndsWithDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEndsWithDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEndsWithDescriptor.java
index c0996b7..dec422a 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEndsWithDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEndsWithDescriptor.java
@@ -24,11 +24,11 @@ import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
 public class StringEndsWithDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -42,14 +42,12 @@ public class StringEndsWithDescriptor extends AbstractScalarFunctionDynamicDescr
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
-
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new AbstractBinaryStringBoolEval(ctx, args[0], args[1],
                         AsterixBuiltinFunctions.STRING_ENDS_WITH) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
index 78fdba6..bcbf207 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
@@ -24,11 +24,11 @@ import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
 public class StringEqualDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -42,14 +42,12 @@ public class StringEqualDescriptor extends AbstractScalarFunctionDynamicDescript
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
-
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new AbstractBinaryStringBoolEval(ctx, args[0], args[1],
                         AsterixBuiltinFunctions.STRING_EQUAL) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringInitCapDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringInitCapDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringInitCapDescriptor.java
index fee7e06..930f99d 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringInitCapDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringInitCapDescriptor.java
@@ -25,11 +25,11 @@ import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
@@ -49,7 +49,7 @@ public class StringInitCapDescriptor extends AbstractScalarFunctionDynamicDescri
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new AbstractUnaryStringStringEval(ctx, args[0], StringInitCapDescriptor.this.getIdentifier()) {
                     @Override
                     protected void process(UTF8StringPointable inputString, IPointable resultPointable)

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
index 67f3fbd..9e69011 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
@@ -22,18 +22,24 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
+import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import org.apache.asterix.om.base.AMissing;
+import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.asterix.runtime.evaluators.common.AsterixListAccessor;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
+import org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -53,91 +59,102 @@ public class StringJoinDescriptor extends AbstractScalarFunctionDynamicDescripto
     @Override
     public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
-
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
-
-                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
-                    private DataOutput out = resultStorage.getDataOutput();
-                    private IScalarEvaluatorFactory listEvalFactory = args[0];
-                    private IScalarEvaluatorFactory sepEvalFactory = args[1];
-                    private IPointable inputArgList = new VoidPointable();
-                    private IPointable inputArgSep = new VoidPointable();
-                    private IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
-                    private IScalarEvaluator evalSep = sepEvalFactory.createScalarEvaluator(ctx);
+                    private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private final AsterixListAccessor listAccessor = new AsterixListAccessor();
+                    private final DataOutput out = resultStorage.getDataOutput();
+                    private final IScalarEvaluatorFactory listEvalFactory = args[0];
+                    private final IScalarEvaluatorFactory sepEvalFactory = args[1];
+                    private final IPointable inputArgList = new VoidPointable();
+                    private final IPointable inputArgSep = new VoidPointable();
+                    private final IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
+                    private final IScalarEvaluator evalSep = sepEvalFactory.createScalarEvaluator(ctx);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+                    private ISerializerDeserializer<AMissing> missingSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AMISSING);
                     private final byte[] tempLengthArray = new byte[5];
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
-                        try {
-                            resultStorage.reset();
-                            evalList.evaluate(tuple, inputArgList);
-                            byte[] serOrderedList = inputArgList.getByteArray();
-                            int serOrderedListOffset = inputArgList.getStartOffset();
-
-                            evalSep.evaluate(tuple, inputArgSep);
-                            byte[] serSep = inputArgSep.getByteArray();
-                            int serSepOffset = inputArgSep.getStartOffset();
-
-                            if (serOrderedList[serOrderedListOffset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
-                                    && serOrderedList[serOrderedListOffset
-                                            + 1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                throw new AlgebricksException(AsterixBuiltinFunctions.STRING_JOIN.getName()
-                                        + ": expects input type ORDEREDLIST but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER
-                                                .deserialize(serOrderedList[serOrderedListOffset]));
-                            }
-
-                            if (serSep[serSepOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                throw new AlgebricksException(AsterixBuiltinFunctions.STRING_JOIN.getName()
-                                        + ": expects STRING type for the seperator but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serSep[serSepOffset]));
-                            }
-
-                            int size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList,
-                                    serOrderedListOffset);
-                            try {
-                                // calculate length first
-                                int utf_8_len = 0;
-                                int sep_len = UTF8StringUtil.getUTFLength(serSep, serSepOffset + 1);
-                                int sep_meta_len = UTF8StringUtil.getNumBytesToStoreLength(sep_len);
-
-                                for (int i = 0; i < size; i++) {
-                                    int itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serOrderedList,
-                                            serOrderedListOffset, i);
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+                        resultStorage.reset();
+                        evalList.evaluate(tuple, inputArgList);
+                        evalSep.evaluate(tuple, inputArgSep);
+
+                        byte[] listBytes = inputArgList.getByteArray();
+                        int listOffset = inputArgList.getStartOffset();
+                        if (listBytes[listOffset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
+                                && listBytes[listOffset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 0, listBytes[listOffset],
+                                    ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG,
+                                    ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
+                        }
+                        byte[] sepBytes = inputArgSep.getByteArray();
+                        int sepOffset = inputArgSep.getStartOffset();
+                        if (sepBytes[sepOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                            throw new TypeMismatchException(getIdentifier(), 1, sepBytes[sepOffset],
+                                    ATypeTag.SERIALIZED_STRING_TYPE_TAG);
+                        }
+                        int sepLen = UTF8StringUtil.getUTFLength(sepBytes, sepOffset + 1);
+                        int sepMetaLen = UTF8StringUtil.getNumBytesToStoreLength(sepLen);
 
-                                    int currentSize = UTF8StringUtil.getUTFLength(serOrderedList, itemOffset);
-                                    if (i != size - 1 && currentSize != 0) {
-                                        utf_8_len += sep_len;
-                                    }
-                                    utf_8_len += currentSize;
+                        listAccessor.reset(listBytes, listOffset);
+                        try {
+                            // calculate length first
+                            int utf8Len = 0;
+                            int size = listAccessor.size();
+                            for (int i = 0; i < size; i++) {
+                                int itemOffset = listAccessor.getItemOffset(i);
+                                ATypeTag itemType = listAccessor.getItemType(itemOffset);
+                                // Increase the offset by 1 if the give list has heterogeneous elements,
+                                // since the item itself has a typetag.
+                                if (listAccessor.itemsAreSelfDescribing()) {
+                                    itemOffset += 1;
                                 }
-                                out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
-                                int length = UTF8StringUtil.encodeUTF8Length(utf_8_len, tempLengthArray, 0);
-                                out.write(tempLengthArray, 0, length);
-                                for (int i = 0; i < size; i++) {
-                                    int itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serOrderedList,
-                                            serOrderedListOffset, i);
-                                    utf_8_len = UTF8StringUtil.getUTFLength(serOrderedList, itemOffset);
-                                    out.write(serOrderedList,
-                                            itemOffset + UTF8StringUtil.getNumBytesToStoreLength(utf_8_len), utf_8_len);
-                                    if (i == size - 1 || utf_8_len == 0) {
-                                        continue;
+                                if (itemType != ATypeTag.STRING) {
+                                    if (itemType == ATypeTag.NULL) {
+                                        nullSerde.serialize(ANull.NULL, out);
+                                        result.set(resultStorage);
+                                        return;
                                     }
-                                    for (int j = 0; j < sep_len; j++) {
-                                        out.writeByte(serSep[serSepOffset + 1 + sep_meta_len + j]);
+                                    if (itemType == ATypeTag.MISSING) {
+                                        missingSerde.serialize(AMissing.MISSING, out);
+                                        result.set(resultStorage);
+                                        return;
                                     }
+                                    throw new UnsupportedItemTypeException(getIdentifier(), itemType.serialize());
+                                }
+                                int currentSize = UTF8StringUtil.getUTFLength(listBytes, itemOffset);
+                                if (i != size - 1 && currentSize != 0) {
+                                    utf8Len += sepLen;
+                                }
+                                utf8Len += currentSize;
+                            }
+
+                            out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
+                            int cbytes = UTF8StringUtil.encodeUTF8Length(utf8Len, tempLengthArray, 0);
+                            out.write(tempLengthArray, 0, cbytes);
+                            for (int i = 0; i < listAccessor.size(); i++) {
+                                int itemOffset = listAccessor.getItemOffset(i);
+                                if (listAccessor.itemsAreSelfDescribing()) {
+                                    itemOffset += 1;
+                                }
+                                utf8Len = UTF8StringUtil.getUTFLength(listBytes, itemOffset);
+                                out.write(listBytes, UTF8StringUtil.getNumBytesToStoreLength(utf8Len) + itemOffset,
+                                        utf8Len);
+                                for (int j = 0; j < sepLen; j++) {
+                                    out.writeByte(sepBytes[sepOffset + 1 + sepMetaLen + j]);
                                 }
-                            } catch (AsterixException ex) {
-                                throw new AlgebricksException(ex);
                             }
-                            result.set(resultStorage);
-                        } catch (IOException e1) {
-                            throw new AlgebricksException(e1.getMessage());
+                        } catch (IOException | AsterixException ex) {
+                            throw new HyracksDataException(ex);
                         }
+                        result.set(resultStorage);
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrim2Descriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrim2Descriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrim2Descriptor.java
index bcb70e1..69761b7 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrim2Descriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrim2Descriptor.java
@@ -26,11 +26,11 @@ import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.utils.StringTrimmer;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
 public class StringLTrim2Descriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -49,13 +49,12 @@ public class StringLTrim2Descriptor extends AbstractScalarFunctionDynamicDescrip
     }
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new AbstractBinaryStringStringEval(ctx, args[0], args[1],
                         StringLTrim2Descriptor.this.getIdentifier()) {
                     private StringTrimmer stringTrimmer = new StringTrimmer(resultBuilder, resultArray);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrimDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrimDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrimDescriptor.java
index a21b6b4..22ae3b8 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrimDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLTrimDescriptor.java
@@ -26,11 +26,11 @@ import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.utils.StringTrimmer;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
@@ -50,13 +50,12 @@ public class StringLTrimDescriptor extends AbstractScalarFunctionDynamicDescript
     }
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new AbstractUnaryStringStringEval(ctx, args[0], StringLTrimDescriptor.this.getIdentifier()) {
                     private StringTrimmer stringTrimmer = new StringTrimmer(resultBuilder, resultArray, " ");
 


Mime
View raw message