Merged asterix_stabilization_spatial_accessors branch into trunk r782:788.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization@789 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/spatial/circle_accessor.aql b/asterix-app/src/test/resources/runtimets/queries/spatial/circle_accessor.aql
new file mode 100644
index 0000000..1d48ebd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/spatial/circle_accessor.aql
@@ -0,0 +1,14 @@
+/*
+ * Description : Test spatial accessors
+ * Expected Result : Success
+ * Date : Oct 17, 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/spatial_circle_accessor.adm";
+
+let $circle := create-circle(create-point(6.0,3.0), 1.0)
+return {"circle-radius": get-radius($circle), "circle-center": get-center($circle)}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/spatial/line_accessor.aql b/asterix-app/src/test/resources/runtimets/queries/spatial/line_accessor.aql
new file mode 100644
index 0000000..2085436
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/spatial/line_accessor.aql
@@ -0,0 +1,16 @@
+/*
+ * Description : Test spatial accessors
+ * Expected Result : Success
+ * Date : Oct 17, 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/spatial_line_accessor.adm";
+
+let $line := create-line(create-point(100.6,999.4), create-point(-872.0,-876.9))
+let $line_list := get-points($line)
+for $p in $line_list
+return $p
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/spatial/point_accessor.aql b/asterix-app/src/test/resources/runtimets/queries/spatial/point_accessor.aql
new file mode 100644
index 0000000..c408630
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/spatial/point_accessor.aql
@@ -0,0 +1,14 @@
+/*
+ * Description : Test spatial accessors
+ * Expected Result : Success
+ * Date : Oct 17, 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/spatial_point_accessor.adm";
+
+let $point := create-point(2.3,5.0)
+return {"x-coordinate": get-x($point), "y-coordinate": get-y($point)}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/spatial/polygon_accessor.aql b/asterix-app/src/test/resources/runtimets/queries/spatial/polygon_accessor.aql
new file mode 100644
index 0000000..a181648
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/spatial/polygon_accessor.aql
@@ -0,0 +1,16 @@
+/*
+ * Description : Test spatial accessors
+ * Expected Result : Success
+ * Date : Oct 17, 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/spatial_polygon_accessor.adm";
+
+let $polygon := create-polygon(create-point(1.0,1.0), create-point(2.0,2.0), create-point(3.0,3.0), create-point(4.0,4.0))
+let $polygon_list := get-points($polygon)
+for $p in $polygon_list
+return $p
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/spatial/rectangle_accessor.aql b/asterix-app/src/test/resources/runtimets/queries/spatial/rectangle_accessor.aql
new file mode 100644
index 0000000..676888c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/spatial/rectangle_accessor.aql
@@ -0,0 +1,16 @@
+/*
+ * Description : Test spatial accessors
+ * Expected Result : Success
+ * Date : Oct 17, 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/spatial_rectangle_accessor.adm";
+
+let $rectangle := create-rectangle(create-point(9.2,49.0), create-point(77.8,111.1))
+let $rectangle_list := get-points($rectangle)
+for $p in $rectangle_list
+return $p
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/spatial/circle_accessor.adm b/asterix-app/src/test/resources/runtimets/results/spatial/circle_accessor.adm
new file mode 100644
index 0000000..8848521
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/spatial/circle_accessor.adm
@@ -0,0 +1 @@
+{ "circle-radius": 1.0d, "circle-center": point("6.0,3.0") }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/spatial/line_accessor.adm b/asterix-app/src/test/resources/runtimets/results/spatial/line_accessor.adm
new file mode 100644
index 0000000..c6d1c06
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/spatial/line_accessor.adm
@@ -0,0 +1,2 @@
+point("100.6,999.4")
+point("-872.0,-876.9")
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/spatial/point_accessor.adm b/asterix-app/src/test/resources/runtimets/results/spatial/point_accessor.adm
new file mode 100644
index 0000000..0fa3fe4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/spatial/point_accessor.adm
@@ -0,0 +1 @@
+{ "x-coordinate": 2.3d, "y-coordinate": 5.0d }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/spatial/polygon_accessor.adm b/asterix-app/src/test/resources/runtimets/results/spatial/polygon_accessor.adm
new file mode 100644
index 0000000..12685ce
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/spatial/polygon_accessor.adm
@@ -0,0 +1,4 @@
+point("1.0,1.0")
+point("2.0,2.0")
+point("3.0,3.0")
+point("4.0,4.0")
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/spatial/rectangle_accessor.adm b/asterix-app/src/test/resources/runtimets/results/spatial/rectangle_accessor.adm
new file mode 100644
index 0000000..f198dff
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/spatial/rectangle_accessor.adm
@@ -0,0 +1,2 @@
+point("9.2,49.0")
+point("77.8,111.1")
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
index a624cf9..3594358 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
@@ -58,6 +58,7 @@
import edu.uci.ics.asterix.om.typecomputer.impl.OptionalATimeTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListConstructorResultType;
import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAInt32TypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAPointTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAStringTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAnyTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.QuadStringStringOrNullTypeComputer;
@@ -393,6 +394,12 @@
public final static FunctionIdentifier CAST_RECORD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"cast-record", 1);
+ public final static FunctionIdentifier GET_POINT_X_COORDINATE_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-x", 1);
+ public final static FunctionIdentifier GET_POINT_Y_COORDINATE_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-y", 1);
+ public final static FunctionIdentifier GET_CIRCLE_RADIUS_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-radius", 1);
+ public final static FunctionIdentifier GET_CIRCLE_CENTER_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-center", 1);
+ public final static FunctionIdentifier GET_POINTS_LINE_RECTANGLE_POLYGON_ACCESSOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-points", 1);
+
public static final FunctionIdentifier EQ = AlgebricksBuiltinFunctions.EQ;
public static final FunctionIdentifier LE = AlgebricksBuiltinFunctions.LE;
public static final FunctionIdentifier GE = AlgebricksBuiltinFunctions.GE;
@@ -585,6 +592,11 @@
add(SPATIAL_CELL, ARectangleTypeComputer.INSTANCE);
add(SPATIAL_DISTANCE, ADoubleTypeComputer.INSTANCE);
add(SPATIAL_INTERSECT, ABooleanTypeComputer.INSTANCE);
+ add(GET_POINT_X_COORDINATE_ACCESSOR, ADoubleTypeComputer.INSTANCE);
+ add(GET_POINT_Y_COORDINATE_ACCESSOR, ADoubleTypeComputer.INSTANCE);
+ add(GET_CIRCLE_RADIUS_ACCESSOR, ADoubleTypeComputer.INSTANCE);
+ add(GET_CIRCLE_CENTER_ACCESSOR, APointTypeComputer.INSTANCE);
+ add(GET_POINTS_LINE_RECTANGLE_POLYGON_ACCESSOR, OrderedListOfAPointTypeComputer.INSTANCE);
add(STARTS_WITH, ABooleanTypeComputer.INSTANCE);
add(STRING_CONSTRUCTOR, OptionalAStringTypeComputer.INSTANCE);
add(SUBSET_COLLECTION, new IResultTypeComputer() {
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OrderedListOfAPointTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OrderedListOfAPointTypeComputer.java
new file mode 100644
index 0000000..f5ffeef
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OrderedListOfAPointTypeComputer.java
@@ -0,0 +1,24 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.AOrderedListType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+
+public class OrderedListOfAPointTypeComputer implements IResultTypeComputer {
+
+ public static final OrderedListOfAPointTypeComputer INSTANCE = new OrderedListOfAPointTypeComputer();
+
+ private OrderedListOfAPointTypeComputer() {
+ }
+
+ @Override
+ public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+ IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+ return new AOrderedListType(BuiltinType.APOINT, null);
+ }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/CircleCenterAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/CircleCenterAccessor.java
new file mode 100644
index 0000000..577a1fb
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/CircleCenterAccessor.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2009-2011 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.accessors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.Coordinate;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AMutablePoint;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.APoint;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class CircleCenterAccessor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-center", 1);
+ private static final byte SER_CICLE_TAG = ATypeTag.CIRCLE.serialize();
+ private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new CircleCenterAccessor();
+ }
+ };
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+ return new ICopyEvaluatorFactory() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+ return new ICopyEvaluator() {
+ private final DataOutput out = output.getDataOutput();
+ private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval = args[0].createEvaluator(argOut);
+
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+ private final AMutablePoint aPoint = new AMutablePoint(0, 0);
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<APoint> pointSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.APOINT);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ argOut.reset();
+ eval.evaluate(tuple);
+ byte[] bytes = argOut.getByteArray();
+
+ try {
+ double cX;
+ double cY;
+ if (bytes[0] == SER_CICLE_TAG) {
+ cX = ADoubleSerializerDeserializer.getDouble(bytes,
+ ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
+ cY = ADoubleSerializerDeserializer.getDouble(bytes,
+ ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
+ aPoint.setValue(cX, cY);
+ pointSerde.serialize(aPoint, out);
+ } else if (bytes[0] == SER_NULL_TYPE_TAG) {
+ nullSerde.serialize(ANull.NULL, out);
+ } else {
+ throw new AlgebricksException("get-center does not support the type: " + bytes[0]
+ + " It is only implemented for CIRCLE.");
+ }
+
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/CircleRadiusAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/CircleRadiusAccessor.java
new file mode 100644
index 0000000..ffaae9e
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/CircleRadiusAccessor.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2009-2011 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.accessors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ADouble;
+import edu.uci.ics.asterix.om.base.AMutableDouble;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class CircleRadiusAccessor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-radius", 1);
+ private static final byte SER_CICLE_TAG = ATypeTag.CIRCLE.serialize();
+ private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new CircleRadiusAccessor();
+ }
+ };
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+ return new ICopyEvaluatorFactory() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+ return new ICopyEvaluator() {
+ private final DataOutput out = output.getDataOutput();
+ private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval = args[0].createEvaluator(argOut);
+
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+ private final AMutableDouble aDouble = new AMutableDouble(0);
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ADouble> doubleSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADOUBLE);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ argOut.reset();
+ eval.evaluate(tuple);
+ byte[] bytes = argOut.getByteArray();
+
+ try {
+ double radius;
+ if (bytes[0] == SER_CICLE_TAG) {
+ radius = ADoubleSerializerDeserializer.getDouble(bytes,
+ ACircleSerializerDeserializer.getRadiusOffset());
+ aDouble.setValue(radius);
+ doubleSerde.serialize(aDouble, out);
+ } else if (bytes[0] == SER_NULL_TYPE_TAG) {
+ nullSerde.serialize(ANull.NULL, out);
+ } else {
+ throw new AlgebricksException("get-radius does not support the type: " + bytes[0]
+ + " It is only implemented for CIRCLE.");
+ }
+
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/LineRectanglePolygonAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/LineRectanglePolygonAccessor.java
new file mode 100644
index 0000000..68ff480
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/LineRectanglePolygonAccessor.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2009-2011 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.accessors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.builders.IAOrderedListBuilder;
+import edu.uci.ics.asterix.builders.OrderedListBuilder;
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.Coordinate;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ALineSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APolygonSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARectangleSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AMutablePoint;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.APoint;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.AOrderedListType;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class LineRectanglePolygonAccessor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-points", 1);
+ private static final byte SER_LINE_TAG = ATypeTag.LINE.serialize();
+ private static final byte SER_RECTANGLE_TAG = ATypeTag.RECTANGLE.serialize();
+ private static final byte SER_POLYGON_TAG = ATypeTag.POLYGON.serialize();
+ private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new LineRectanglePolygonAccessor();
+ }
+ };
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+ return new ICopyEvaluatorFactory() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+ return new ICopyEvaluator() {
+ private final DataOutput out = output.getDataOutput();
+ private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval = args[0].createEvaluator(argOut);
+
+ private final IAOrderedListBuilder listBuilder = new OrderedListBuilder();
+ private final ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
+ private final AOrderedListType pointListType = new AOrderedListType(BuiltinType.APOINT, null);
+
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+ private final AMutablePoint aPoint = new AMutablePoint(0, 0);
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<APoint> pointSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.APOINT);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ argOut.reset();
+ eval.evaluate(tuple);
+ byte[] bytes = argOut.getByteArray();
+
+ try {
+ if (bytes[0] == SER_LINE_TAG) {
+ listBuilder.reset(pointListType);
+
+ inputVal.reset();
+ double startX = ADoubleSerializerDeserializer.getDouble(bytes,
+ ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
+ double startY = ADoubleSerializerDeserializer.getDouble(bytes,
+ ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
+ aPoint.setValue(startX, startY);
+ pointSerde.serialize(aPoint, inputVal.getDataOutput());
+ listBuilder.addItem(inputVal);
+
+ inputVal.reset();
+ double endX = ADoubleSerializerDeserializer.getDouble(bytes,
+ ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
+ double endY = ADoubleSerializerDeserializer.getDouble(bytes,
+ ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
+ aPoint.setValue(endX, endY);
+ pointSerde.serialize(aPoint, inputVal.getDataOutput());
+ listBuilder.addItem(inputVal);
+ listBuilder.write(out, true);
+
+ } else if (bytes[0] == SER_RECTANGLE_TAG) {
+ listBuilder.reset(pointListType);
+
+ inputVal.reset();
+ double x1 = ADoubleSerializerDeserializer.getDouble(bytes,
+ ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
+ double y1 = ADoubleSerializerDeserializer.getDouble(bytes,
+ ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
+ aPoint.setValue(x1, y1);
+ pointSerde.serialize(aPoint, inputVal.getDataOutput());
+ listBuilder.addItem(inputVal);
+
+ inputVal.reset();
+ double x2 = ADoubleSerializerDeserializer.getDouble(bytes,
+ ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
+ double y2 = ADoubleSerializerDeserializer.getDouble(bytes,
+ ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
+ aPoint.setValue(x2, y2);
+ pointSerde.serialize(aPoint, inputVal.getDataOutput());
+ listBuilder.addItem(inputVal);
+ listBuilder.write(out, true);
+
+ } else if (bytes[0] == SER_POLYGON_TAG) {
+ int numOfPoints = AInt16SerializerDeserializer.getShort(bytes,
+ APolygonSerializerDeserializer.getNumberOfPointsOffset());
+
+ if (numOfPoints < 3) {
+ throw new HyracksDataException("Polygon must have at least 3 points.");
+ }
+ listBuilder.reset(pointListType);
+ for (int i = 0; i < numOfPoints; ++i) {
+ inputVal.reset();
+ double x = ADoubleSerializerDeserializer.getDouble(bytes,
+ APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
+ double y = ADoubleSerializerDeserializer.getDouble(bytes,
+ APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
+ aPoint.setValue(x, y);
+ pointSerde.serialize(aPoint, inputVal.getDataOutput());
+ listBuilder.addItem(inputVal);
+ }
+ listBuilder.write(out, true);
+ } else if (bytes[0] == SER_NULL_TYPE_TAG) {
+ nullSerde.serialize(ANull.NULL, out);
+ } else {
+ throw new AlgebricksException("get-points does not support the type: " + bytes[0]
+ + " It is only implemented for LINE, RECTANGLE, or POLYGON.");
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/PointXCoordinateAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/PointXCoordinateAccessor.java
new file mode 100644
index 0000000..7fcfd20
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/PointXCoordinateAccessor.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2009-2011 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.accessors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.Coordinate;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ADouble;
+import edu.uci.ics.asterix.om.base.AMutableDouble;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class PointXCoordinateAccessor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-x", 1);
+ private static final byte SER_POINT_TAG = ATypeTag.POINT.serialize();
+ private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new PointXCoordinateAccessor();
+ }
+ };
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+ return new ICopyEvaluatorFactory() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+ return new ICopyEvaluator() {
+ private final DataOutput out = output.getDataOutput();
+ private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval = args[0].createEvaluator(argOut);
+
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+ private final AMutableDouble aDouble = new AMutableDouble(0);
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ADouble> doubleSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADOUBLE);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ argOut.reset();
+ eval.evaluate(tuple);
+ byte[] bytes = argOut.getByteArray();
+
+ try {
+ double x;
+ if (bytes[0] == SER_POINT_TAG) {
+ x = ADoubleSerializerDeserializer.getDouble(bytes,
+ APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
+ aDouble.setValue(x);
+ doubleSerde.serialize(aDouble, out);
+ } else if (bytes[0] == SER_NULL_TYPE_TAG) {
+ nullSerde.serialize(ANull.NULL, out);
+ } else {
+ throw new AlgebricksException("get-x does not support the type: " + bytes[0]
+ + " It is only implemented for POINT.");
+ }
+
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/PointYCoordinateAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/PointYCoordinateAccessor.java
new file mode 100644
index 0000000..1c47efa
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/PointYCoordinateAccessor.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2009-2011 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.accessors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.Coordinate;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ADouble;
+import edu.uci.ics.asterix.om.base.AMutableDouble;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class PointYCoordinateAccessor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-y", 1);
+ private static final byte SER_POINT_TAG = ATypeTag.POINT.serialize();
+ private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new PointYCoordinateAccessor();
+ }
+ };
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+ return new ICopyEvaluatorFactory() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+ return new ICopyEvaluator() {
+ private final DataOutput out = output.getDataOutput();
+ private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval = args[0].createEvaluator(argOut);
+
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+ private final AMutableDouble aDouble = new AMutableDouble(0);
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ADouble> doubleSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADOUBLE);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ argOut.reset();
+ eval.evaluate(tuple);
+ byte[] bytes = argOut.getByteArray();
+
+ try {
+ double y;
+ if (bytes[0] == SER_POINT_TAG) {
+ y = ADoubleSerializerDeserializer.getDouble(bytes,
+ APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
+ aDouble.setValue(y);
+ doubleSerde.serialize(aDouble, out);
+ } else if (bytes[0] == SER_NULL_TYPE_TAG) {
+ nullSerde.serialize(ANull.NULL, out);
+ } else {
+ throw new AlgebricksException("get-y does not support the type: " + bytes[0]
+ + " It is only implemented for POINT.");
+ }
+
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
index c641f1a..d4d1619 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
@@ -9,9 +9,12 @@
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARectangleSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ANull;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.EnumDeserializer;
import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.common.SpatialUtils;
@@ -20,6 +23,7 @@
import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -44,9 +48,13 @@
public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
return new ICopyEvaluator() {
- private DataOutput out = output.getDataOutput();
- private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
- private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+ private final DataOutput out = output.getDataOutput();
+ private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval = args[0].createEvaluator(argOut);
+
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
@Override
public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -66,11 +74,15 @@
throw new AlgebricksException("Polygon must have at least 3 points");
}
area = Math.abs(SpatialUtils.polygonArea(argOut.getByteArray(), numOfPoints));
+ out.writeByte(ATypeTag.DOUBLE.serialize());
+ out.writeDouble(area);
break;
case CIRCLE:
double radius = ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(),
ACircleSerializerDeserializer.getRadiusOffset());
area = SpatialUtils.pi() * radius * radius;
+ out.writeByte(ATypeTag.DOUBLE.serialize());
+ out.writeDouble(area);
break;
case RECTANGLE:
double x1 = ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(),
@@ -87,13 +99,16 @@
ARectangleSerializerDeserializer
.getUpperRightCoordinateOffset(Coordinate.Y));
area = (x2 - x1) * (y2 - y1);
+ out.writeByte(ATypeTag.DOUBLE.serialize());
+ out.writeDouble(area);
+ break;
+ case NULL:
+ nullSerde.serialize(ANull.NULL, out);
break;
default:
throw new NotImplementedException("spatial-area does not support the type: " + tag
+ " It is only implemented for POLYGON, CIRCLE and RECTANGLE.");
}
- out.writeByte(ATypeTag.DOUBLE.serialize());
- out.writeDouble(area);
} catch (HyracksDataException hde) {
throw new AlgebricksException(hde);
} catch (IOException e) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
index 1426f91..3d918d8 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
@@ -10,6 +10,7 @@
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.AMutablePoint;
import edu.uci.ics.asterix.om.base.AMutableRectangle;
+import edu.uci.ics.asterix.om.base.ANull;
import edu.uci.ics.asterix.om.base.ARectangle;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
@@ -46,20 +47,24 @@
public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
return new ICopyEvaluator() {
- private DataOutput out = output.getDataOutput();
+ private final DataOutput out = output.getDataOutput();
- private ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
- private ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
- private ArrayBackedValueStorage outInput2 = new ArrayBackedValueStorage();
- private ArrayBackedValueStorage outInput3 = new ArrayBackedValueStorage();
- private ICopyEvaluator eval0 = args[0].createEvaluator(outInput0);
- private ICopyEvaluator eval1 = args[1].createEvaluator(outInput1);
- private ICopyEvaluator eval2 = args[2].createEvaluator(outInput2);
- private ICopyEvaluator eval3 = args[3].createEvaluator(outInput3);
- private AMutableRectangle aRectangle = new AMutableRectangle(null, null);
- private AMutablePoint[] aPoint = { new AMutablePoint(0, 0), new AMutablePoint(0, 0) };
+ private final ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
+ private final ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
+ private final ArrayBackedValueStorage outInput2 = new ArrayBackedValueStorage();
+ private final ArrayBackedValueStorage outInput3 = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval0 = args[0].createEvaluator(outInput0);
+ private final ICopyEvaluator eval1 = args[1].createEvaluator(outInput1);
+ private final ICopyEvaluator eval2 = args[2].createEvaluator(outInput2);
+ private final ICopyEvaluator eval3 = args[3].createEvaluator(outInput3);
+ private final AMutableRectangle aRectangle = new AMutableRectangle(null, null);
+ private final AMutablePoint[] aPoint = { new AMutablePoint(0, 0), new AMutablePoint(0, 0) };
+
@SuppressWarnings("unchecked")
- private ISerializerDeserializer<ARectangle> rectangleSerde = AqlSerializerDeserializerProvider.INSTANCE
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ARectangle> rectangleSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ARECTANGLE);
@Override
@@ -96,6 +101,8 @@
aPoint[1].setValue(x + xInc, y + yInc);
aRectangle.setValue(aPoint[0], aPoint[1]);
rectangleSerde.serialize(aRectangle, out);
+ } else if (tag == ATypeTag.NULL) {
+ nullSerde.serialize(ANull.NULL, out);
} else {
throw new NotImplementedException("spatial-cell does not support the type: " + tag
+ " It is only implemented for POINT.");
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
index d83f62e..63032b9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
@@ -7,9 +7,12 @@
import edu.uci.ics.asterix.dataflow.data.nontagged.Coordinate;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ANull;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
import edu.uci.ics.asterix.om.types.EnumDeserializer;
import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -17,6 +20,7 @@
import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -42,11 +46,15 @@
public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
return new ICopyEvaluator() {
- private DataOutput out = output.getDataOutput();
- private ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
- private ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
- private ICopyEvaluator eval0 = args[0].createEvaluator(outInput0);
- private ICopyEvaluator eval1 = args[1].createEvaluator(outInput1);
+ private final DataOutput out = output.getDataOutput();
+ private final ArrayBackedValueStorage outInput0 = new ArrayBackedValueStorage();
+ private final ArrayBackedValueStorage outInput1 = new ArrayBackedValueStorage();
+ private final ICopyEvaluator eval0 = args[0].createEvaluator(outInput0);
+ private final ICopyEvaluator eval1 = args[1].createEvaluator(outInput1);
+
+ @SuppressWarnings("unchecked")
+ private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
@Override
public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -76,6 +84,8 @@
throw new NotImplementedException("spatial-distance does not support the type: "
+ tag1 + " It is only implemented for POINT.");
}
+ } else if (tag0 == ATypeTag.NULL || tag1 == ATypeTag.NULL) {
+ nullSerde.serialize(ANull.NULL, out);
} else {
throw new NotImplementedException("spatial-distance does not support the type: " + tag0
+ " It is only implemented for POINT.");
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
index c2d6c50..07c21fb 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
@@ -65,6 +65,11 @@
import edu.uci.ics.asterix.runtime.aggregates.std.SumAggregateDescriptor;
import edu.uci.ics.asterix.runtime.aggregates.stream.EmptyStreamAggregateDescriptor;
import edu.uci.ics.asterix.runtime.aggregates.stream.NonEmptyStreamAggregateDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.CircleCenterAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.CircleRadiusAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.LineRectanglePolygonAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.PointXCoordinateAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.PointYCoordinateAccessor;
import edu.uci.ics.asterix.runtime.evaluators.common.CreateMBREvalFactory;
import edu.uci.ics.asterix.runtime.evaluators.common.FieldAccessByIndexEvalFactory;
import edu.uci.ics.asterix.runtime.evaluators.common.FunctionManagerImpl;
@@ -280,7 +285,6 @@
temp.add(NonEmptyStreamAggregateDescriptor.FACTORY);
temp.add(RangeDescriptor.FACTORY);
-// Xiaoyu Ma add for numeric unary functions
temp.add(NumericAbsDescriptor.FACTORY);
temp.add(NumericCeilingDescriptor.FACTORY);
temp.add(NumericFloorDescriptor.FACTORY);
@@ -289,21 +293,21 @@
temp.add(NumericRoundHalfToEven2Descriptor.FACTORY);
// String functions
temp.add(StringEqualDescriptor.FACTORY);
- temp.add(StringStartWithDescrtiptor.FACTORY);
- temp.add(StringEndWithDescrtiptor.FACTORY);
- temp.add(StringMatchesDescriptor.FACTORY);
- temp.add(StringLowerCaseDescriptor.FACTORY);
+ temp.add(StringStartWithDescrtiptor.FACTORY);
+ temp.add(StringEndWithDescrtiptor.FACTORY);
+ temp.add(StringMatchesDescriptor.FACTORY);
+ temp.add(StringLowerCaseDescriptor.FACTORY);
temp.add(StringMatchesWithFlagDescriptor.FACTORY);
- temp.add(StringReplaceDescriptor.FACTORY);
- temp.add(StringReplaceWithFlagsDescriptor.FACTORY);
- temp.add(StringLengthDescriptor.FACTORY);
- temp.add(Substring2Descriptor.FACTORY);
- temp.add(SubstringBeforeDescriptor.FACTORY);
- temp.add(SubstringAfterDescriptor.FACTORY);
- temp.add(StringToCodePointDescriptor.FACTORY);
- temp.add(CodePointToStringDescriptor.FACTORY);
- temp.add(StringConcatDescriptor.FACTORY);
- temp.add(StringJoinDescriptor.FACTORY);
+ temp.add(StringReplaceDescriptor.FACTORY);
+ temp.add(StringReplaceWithFlagsDescriptor.FACTORY);
+ temp.add(StringLengthDescriptor.FACTORY);
+ temp.add(Substring2Descriptor.FACTORY);
+ temp.add(SubstringBeforeDescriptor.FACTORY);
+ temp.add(SubstringAfterDescriptor.FACTORY);
+ temp.add(StringToCodePointDescriptor.FACTORY);
+ temp.add(CodePointToStringDescriptor.FACTORY);
+ temp.add(StringConcatDescriptor.FACTORY);
+ temp.add(StringJoinDescriptor.FACTORY);
// aggregates
temp.add(ListifyAggregateDescriptor.FACTORY);
@@ -332,7 +336,7 @@
temp.add(ScalarSumAggregateDescriptor.FACTORY);
temp.add(ScalarMaxAggregateDescriptor.FACTORY);
temp.add(ScalarMinAggregateDescriptor.FACTORY);
-
+
// new functions - constructors
temp.add(ABooleanConstructorDescriptor.FACTORY);
temp.add(ANullConstructorDescriptor.FACTORY);
@@ -365,6 +369,11 @@
temp.add(SpatialIntersectDescriptor.FACTORY);
temp.add(CreateMBRDescriptor.FACTORY);
temp.add(SpatialCellDescriptor.FACTORY);
+ temp.add(PointXCoordinateAccessor.FACTORY);
+ temp.add(PointYCoordinateAccessor.FACTORY);
+ temp.add(CircleRadiusAccessor.FACTORY);
+ temp.add(CircleCenterAccessor.FACTORY);
+ temp.add(LineRectanglePolygonAccessor.FACTORY);
// fuzzyjoin function
temp.add(FuzzyEqDescriptor.FACTORY);
@@ -541,7 +550,7 @@
typeInference(expr, fd, context);
return fd;
}
-
+
private void typeInference(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context)
throws AlgebricksException {
if (fd.getIdentifier().equals(AsterixBuiltinFunctions.LISTIFY)) {
@@ -552,7 +561,7 @@
IAType itemType = (IAType) context.getType(f.getArguments().get(0).getValue());
// Convert UNION types into ANY.
if (itemType instanceof AUnionType) {
- itemType = BuiltinType.ANY;
+ itemType = BuiltinType.ANY;
}
((ListifyAggregateDescriptor) fd).reset(new AOrderedListType(itemType, null));
}