use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class CreateMBREvalFactory method createScalarEvaluator.
@Override
public IScalarEvaluator createScalarEvaluator(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 IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = dimensionEvalFactory.createScalarEvaluator(ctx);
private IScalarEvaluator eval2 = coordinateEvalFactory.createScalarEvaluator(ctx);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval0.evaluate(tuple, inputArg0);
eval1.evaluate(tuple, inputArg1);
eval2.evaluate(tuple, inputArg2);
byte[] data0 = inputArg0.getByteArray();
byte[] data1 = inputArg1.getByteArray();
byte[] data2 = inputArg2.getByteArray();
int startOffset0 = inputArg0.getStartOffset();
int startOffset1 = inputArg1.getStartOffset();
int startOffset2 = inputArg2.getStartOffset();
try {
if (data0[startOffset0] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || data1[startOffset1] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG || data2[startOffset2] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
result.set(resultStorage);
return;
}
if (data0[startOffset0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG || data1[startOffset1] == ATypeTag.SERIALIZED_NULL_TYPE_TAG || data2[startOffset2] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
result.set(resultStorage);
return;
}
resultStorage.reset();
if (data1[startOffset1] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 1, data1[startOffset1], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
}
int dimension = AInt32SerializerDeserializer.getInt(data1, startOffset1 + 1);
if (data2[startOffset2] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 2, data2[startOffset2], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
}
int coordinate = AInt32SerializerDeserializer.getInt(data2, startOffset2 + 1);
double value;
if (dimension == 2) {
ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data0[startOffset0]);
switch(tag) {
case POINT:
switch(coordinate) {
// 0 is for min x, 1 is for min y, 2
case 0:
// max x, and 3 for max y
case 2:
{
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
value = x;
}
break;
case 1:
case 3:
{
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
value = y;
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case LINE:
value = Double.MAX_VALUE;
switch(coordinate) {
case 0:
{
value = Double.MAX_VALUE;
double startX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
double endX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
value = Math.min(Math.min(startX, endX), value);
}
break;
case 1:
{
value = Double.MAX_VALUE;
double startY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
double endY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
value = Math.min(Math.min(startY, endY), value);
}
break;
case 2:
{
value = Double.MIN_VALUE;
double startX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
double endX = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
value = Math.max(Math.min(startX, endX), value);
}
break;
case 3:
{
value = Double.MIN_VALUE;
double startY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
double endY = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
value = Math.max(Math.min(startY, endY), value);
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case POLYGON:
int numOfPoints = AInt16SerializerDeserializer.getShort(data0, startOffset0 + APolygonSerializerDeserializer.getNumberOfPointsOffset());
switch(coordinate) {
case 0:
{
value = Double.MAX_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
value = Math.min(x, value);
}
}
break;
case 1:
{
value = Double.MAX_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
value = Math.min(y, value);
}
}
break;
case 2:
{
value = Double.MIN_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
value = Math.max(x, value);
}
}
break;
case 3:
{
value = Double.MIN_VALUE;
for (int i = 0; i < numOfPoints; i++) {
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
value = Math.max(y, value);
}
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case CIRCLE:
switch(coordinate) {
case 0:
{
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = x - radius;
}
break;
case 1:
{
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = y - radius;
}
break;
case 2:
{
double x = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.X));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = x + radius;
}
break;
case 3:
{
double y = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getCenterPointCoordinateOffset(Coordinate.Y));
double radius = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ACircleSerializerDeserializer.getRadiusOffset());
value = y + radius;
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
case RECTANGLE:
switch(coordinate) {
case 0:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
}
break;
case 1:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
}
break;
case 2:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
}
break;
case 3:
{
value = ADoubleSerializerDeserializer.getDouble(data0, startOffset0 + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
}
break;
default:
{
throw new NotImplementedException(coordinate + " is not a valid coordinate option");
}
}
break;
default:
throw new TypeMismatchException(BuiltinFunctions.CREATE_MBR, 0, data0[startOffset0], 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);
}
} else {
throw new NotImplementedException(dimension + "D is not supported");
}
out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
out.writeDouble(value);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class NonEmptyStreamAggregateDescriptor method createAggregateEvaluatorFactory.
@Override
public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args) {
return new IAggregateEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IAggregateEvaluator() {
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@SuppressWarnings("rawtypes")
private ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
boolean res = false;
@Override
public void init() throws HyracksDataException {
res = false;
}
@Override
public void step(IFrameTupleReference tuple) throws HyracksDataException {
res = true;
}
@SuppressWarnings("unchecked")
@Override
public void finish(IPointable result) throws HyracksDataException {
resultStorage.reset();
ABoolean b = res ? ABoolean.TRUE : ABoolean.FALSE;
serde.serialize(b, resultStorage.getDataOutput());
result.set(resultStorage);
}
@Override
public void finishPartial(IPointable result) throws HyracksDataException {
finish(result);
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class LineRectanglePolygonAccessor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(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 OrderedListBuilder listBuilder = new OrderedListBuilder();
private final ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
private final AOrderedListType pointListType = new AOrderedListType(BuiltinType.APOINT, null);
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 {
if (bytes[startOffset] == ATypeTag.SERIALIZED_LINE_TYPE_TAG) {
listBuilder.reset(pointListType);
inputVal.reset();
double startX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
double startY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.Y));
aPoint.setValue(startX, startY);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
inputVal.reset();
double endX = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.X));
double endY = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ALineSerializerDeserializer.getEndPointCoordinateOffset(Coordinate.Y));
aPoint.setValue(endX, endY);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
listBuilder.write(out, true);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG) {
listBuilder.reset(pointListType);
inputVal.reset();
double x1 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.X));
double y1 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getBottomLeftCoordinateOffset(Coordinate.Y));
aPoint.setValue(x1, y1);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
inputVal.reset();
double x2 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.X));
double y2 = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + ARectangleSerializerDeserializer.getUpperRightCoordinateOffset(Coordinate.Y));
aPoint.setValue(x2, y2);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
listBuilder.write(out, true);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_POLYGON_TYPE_TAG) {
int numOfPoints = AInt16SerializerDeserializer.getShort(bytes, startOffset + APolygonSerializerDeserializer.getNumberOfPointsOffset());
if (numOfPoints < 3) {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
listBuilder.reset(pointListType);
for (int i = 0; i < numOfPoints; ++i) {
inputVal.reset();
double x = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
double y = ADoubleSerializerDeserializer.getDouble(bytes, startOffset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
aPoint.setValue(x, y);
pointSerde.serialize(aPoint, inputVal.getDataOutput());
listBuilder.addItem(inputVal);
}
listBuilder.write(out, true);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_LINE_TYPE_TAG, ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG, ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class TemporalHourAccessor method createEvaluatorFactory.
/* (non-Javadoc)
* @see org.apache.asterix.om.function.IFunctionDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory[])
*/
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(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 GregorianCalendarSystem calSystem = GregorianCalendarSystem.getInstance();
// for output: type integer
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt64> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
private final AMutableInt64 aMutableInt64 = new AMutableInt64(0);
@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 {
if (bytes[startOffset] == ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationHour(ADurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
if (bytes[startOffset] == ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG) {
aMutableInt64.setValue(calSystem.getDurationHour(ADayTimeDurationSerializerDeserializer.getDayTime(bytes, startOffset + 1)));
intSerde.serialize(aMutableInt64, out);
result.set(resultStorage);
return;
}
long chrononTimeInMs = 0;
if (bytes[startOffset] == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, startOffset + 1);
} else if (bytes[startOffset] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
chrononTimeInMs = AInt64SerializerDeserializer.getLong(bytes, startOffset + 1);
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_DAY_TIME_DURATION_TYPE_TAG, ATypeTag.SERIALIZED_TIME_TYPE_TAG, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
}
int hour = calSystem.getHourOfDay(chrononTimeInMs);
aMutableInt64.setValue(hour);
intSerde.serialize(aMutableInt64, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class TemporalIntervalEndAccessor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(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);
// possible output
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<ADate> dateSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATE);
private final AMutableDate aDate = new AMutableDate(0);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<ADateTime> datetimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
private final AMutableDateTime aDateTime = new AMutableDateTime(0);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<ATime> timeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ATIME);
private final AMutableTime aTime = new AMutableTime(0);
@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 {
if (bytes[startOffset] == ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
byte timeType = AIntervalSerializerDeserializer.getIntervalTimeType(bytes, startOffset + 1);
long endTime = AIntervalSerializerDeserializer.getIntervalEnd(bytes, startOffset + 1);
if (timeType == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
aDate.setValue((int) (endTime));
dateSerde.serialize(aDate, out);
} else if (timeType == ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
aTime.setValue((int) (endTime));
timeSerde.serialize(aTime, out);
} else if (timeType == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
aDateTime.setValue(endTime);
datetimeSerde.serialize(aDateTime, out);
} else {
throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
} else {
throw new TypeMismatchException(getIdentifier(), 0, bytes[startOffset], ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations