use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.
the class IntegerAddEvalFactory method createScalarEvaluator.
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private IPointable p = VoidPointable.FACTORY.createPointable();
private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
private IScalarEvaluator evalLeft = evalLeftFactory.createScalarEvaluator(ctx);
private IScalarEvaluator evalRight = evalRightFactory.createScalarEvaluator(ctx);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
evalLeft.evaluate(tuple, p);
int v1 = IntegerPointable.getInteger(p.getByteArray(), p.getStartOffset());
evalRight.evaluate(tuple, p);
int v2 = IntegerPointable.getInteger(p.getByteArray(), p.getStartOffset());
try {
argOut.reset();
argOut.getDataOutput().writeInt(v1 + v2);
result.set(argOut);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
};
}
use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.
the class TupleCountAggregateFunctionFactory method createAggregateEvaluator.
@Override
public IAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
return new IAggregateEvaluator() {
int cnt;
@Override
public void step(IFrameTupleReference tuple) throws HyracksDataException {
++cnt;
}
@Override
public void init() throws HyracksDataException {
cnt = 0;
}
@Override
public void finish(IPointable result) throws HyracksDataException {
try {
abvs.reset();
abvs.getDataOutput().writeInt(cnt);
result.set(abvs);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
@Override
public void finishPartial(IPointable result) throws HyracksDataException {
finish(result);
}
};
}
use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.
the class TupleCountRunningAggregateFunctionFactory method createRunningAggregateEvaluator.
@Override
public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
return new IRunningAggregateEvaluator() {
int cnt;
@Override
public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
++cnt;
abvs.reset();
abvs.getDataOutput().writeInt(cnt);
result.set(abvs);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
@Override
public void init() throws HyracksDataException {
cnt = 0;
}
};
}
use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.
the class SpatialAreaDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable argPtr = new VoidPointable();
private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval.evaluate(tuple, argPtr);
try {
byte[] bytes = argPtr.getByteArray();
int offset = argPtr.getStartOffset();
ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
double area = 0.0;
switch(tag) {
case POLYGON:
int numOfPoints = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
if (numOfPoints < 3) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
area = Math.abs(SpatialUtils.polygonArea(bytes, offset, numOfPoints));
out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
out.writeDouble(area);
break;
case CIRCLE:
double radius = ADoubleSerializerDeserializer.getDouble(bytes, offset + ACircleSerializerDeserializer.getRadiusOffset());
area = SpatialUtils.pi() * radius * radius;
out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
out.writeDouble(area);
break;
case RECTANGLE:
double x1 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
double y1 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
double x2 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
double y2 = ADoubleSerializerDeserializer.getDouble(bytes, offset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
area = (x2 - x1) * (y2 - y1);
out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
out.writeDouble(area);
break;
default:
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_POLYGON_TYPE_TAG, ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG, ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.
the class SpatialCellDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputArg0 = new VoidPointable();
private final IPointable inputArg1 = new VoidPointable();
private final IPointable inputArg2 = new VoidPointable();
private final IPointable inputArg3 = new VoidPointable();
private final IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private final IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
private final IScalarEvaluator eval2 = args[2].createScalarEvaluator(ctx);
private final IScalarEvaluator eval3 = args[3].createScalarEvaluator(ctx);
private final AMutableRectangle aRectangle = new AMutableRectangle(null, null);
private final AMutablePoint[] aPoint = { new AMutablePoint(0, 0), new AMutablePoint(0, 0) };
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<ARectangle> rectangleSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ARECTANGLE);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, inputArg0);
eval1.evaluate(tuple, inputArg1);
eval2.evaluate(tuple, inputArg2);
eval3.evaluate(tuple, inputArg3);
byte[] bytes0 = inputArg0.getByteArray();
byte[] bytes1 = inputArg1.getByteArray();
byte[] bytes2 = inputArg2.getByteArray();
byte[] bytes3 = inputArg3.getByteArray();
int offset0 = inputArg0.getStartOffset();
int offset1 = inputArg1.getStartOffset();
int offset2 = inputArg2.getStartOffset();
int offset3 = inputArg3.getStartOffset();
try {
byte tag0 = bytes0[offset0];
byte tag1 = bytes1[offset1];
byte tag2 = bytes2[offset2];
byte tag3 = bytes3[offset3];
if (tag0 == ATypeTag.SERIALIZED_POINT_TYPE_TAG && tag1 == ATypeTag.SERIALIZED_POINT_TYPE_TAG && tag2 == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG && tag3 == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
double xLoc = ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
double yLoc = ADoubleSerializerDeserializer.getDouble(bytes0, offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
double xOrigin = ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
double yOrigin = ADoubleSerializerDeserializer.getDouble(bytes1, offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
double xInc = ADoubleSerializerDeserializer.getDouble(bytes2, offset2 + 1);
double yInc = ADoubleSerializerDeserializer.getDouble(bytes3, offset3 + 1);
double x = xOrigin + (Math.floor((xLoc - xOrigin) / xInc)) * xInc;
double y = yOrigin + (Math.floor((yLoc - yOrigin) / yInc)) * yInc;
aPoint[0].setValue(x, y);
aPoint[1].setValue(x + xInc, y + yInc);
aRectangle.setValue(aPoint[0], aPoint[1]);
rectangleSerde.serialize(aRectangle, out);
} else {
if (tag0 != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, tag0, ATypeTag.SERIALIZED_POINT_TYPE_TAG);
}
if (tag1 != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, tag1, ATypeTag.SERIALIZED_POINT_TYPE_TAG);
}
if (tag2 != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 2, tag2, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
if (tag3 != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 3, tag3, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
}
}
result.set(resultStorage);
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
}
};
}
};
}
Aggregations