use of org.apache.asterix.om.base.APoint in project asterixdb by apache.
the class ALineSerializerDeserializer method deserialize.
@Override
public ALine deserialize(DataInput in) throws HyracksDataException {
try {
APoint p1 = APointSerializerDeserializer.INSTANCE.deserialize(in);
APoint p2 = APointSerializerDeserializer.INSTANCE.deserialize(in);
return new ALine(p1, p2);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
use of org.apache.asterix.om.base.APoint in project asterixdb by apache.
the class APolygonSerializerDeserializer method deserialize.
@Override
public APolygon deserialize(DataInput in) throws HyracksDataException {
try {
short numberOfPoints = in.readShort();
APoint[] points = new APoint[numberOfPoints];
for (int i = 0; i < numberOfPoints; i++) {
points[i] = APointSerializerDeserializer.INSTANCE.deserialize(in);
}
return new APolygon(points);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
use of org.apache.asterix.om.base.APoint 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);
}
};
}
};
}
use of org.apache.asterix.om.base.APoint in project asterixdb by apache.
the class APointConstructorDescriptor 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 ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private AMutablePoint aPoint = new AMutablePoint(0, 0);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<APoint> pointSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.APOINT);
private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
int len = inputArg.getLength();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
utf8Ptr.set(serString, offset + 1, len - 1);
String s = utf8Ptr.toString();
aPoint.setValue(Double.parseDouble(s.substring(0, s.indexOf(','))), Double.parseDouble(s.substring(s.indexOf(',') + 1, s.length())));
pointSerde.serialize(aPoint, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
result.set(resultStorage);
} catch (IOException e) {
throw new InvalidDataFormatException(getIdentifier(), e, ATypeTag.SERIALIZED_POINT_TYPE_TAG);
}
}
};
}
};
}
Aggregations