use of org.apache.asterix.om.base.AMutablePoint in project asterixdb by apache.
the class CircleCenterAccessor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final AMutablePoint aPoint = new AMutablePoint(0, 0);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<APoint> pointSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.APOINT);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval.evaluate(tuple, argPtr);
byte[] bytes = argPtr.getByteArray();
int startOffset = argPtr.getStartOffset();
resultStorage.reset();
try {
double cX;
double cY;
if (bytes[startOffset] == ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG) {
cX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
cY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
aPoint.setValue(cX, cY);
pointSerde.serialize(aPoint, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations