use of org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable in project asterixdb by apache.
the class AbstractIntervalLogicFuncDescriptor 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() {
protected final IntervalLogic il = new IntervalLogic();
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private TaggedValuePointable argPtr0 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
private TaggedValuePointable argPtr1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
private AIntervalPointable interval0 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();
private AIntervalPointable interval1 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
// possible output types
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ABoolean> booleanSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, argPtr0);
eval1.evaluate(tuple, argPtr1);
byte typeTag0 = argPtr0.getTag();
if (typeTag0 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, typeTag0, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
byte typeTag1 = argPtr0.getTag();
if (typeTag1 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, typeTag1, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
}
argPtr0.getValue(interval0);
argPtr1.getValue(interval1);
if (typeTag0 != typeTag1) {
throw new IncompatibleTypeException(getIdentifier(), typeTag0, typeTag1);
}
ABoolean res = compareIntervals(il, interval0, interval1) ? ABoolean.TRUE : ABoolean.FALSE;
booleanSerde.serialize(res, out);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable in project asterixdb by apache.
the class GetOverlappingIntervalDescriptor 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() {
protected final IntervalLogic il = new IntervalLogic();
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private TaggedValuePointable argPtr0 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
private TaggedValuePointable argPtr1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
private AIntervalPointable interval0 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();
private AIntervalPointable interval1 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();
private IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
private final AMutableInterval aInterval = new AMutableInterval(0, 0, (byte) -1);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInterval> intervalSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINTERVAL);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
eval0.evaluate(tuple, argPtr0);
eval1.evaluate(tuple, argPtr1);
byte type0 = argPtr0.getTag();
byte type1 = argPtr1.getTag();
if (type0 == ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG && type0 == type1) {
argPtr0.getValue(interval0);
argPtr1.getValue(interval1);
byte intervalType0 = interval0.getType();
byte intervalType1 = interval1.getType();
if (intervalType0 != intervalType1) {
throw new IncompatibleTypeException(getIdentifier(), intervalType0, intervalType1);
}
if (il.overlaps(interval0, interval1) || il.overlappedBy(interval0, interval1) || il.covers(interval0, interval1) || il.coveredBy(interval0, interval1)) {
long start = Math.max(interval0.getStartValue(), interval1.getStartValue());
long end = Math.min(interval0.getEndValue(), interval1.getEndValue());
aInterval.setValue(start, end, intervalType0);
intervalSerde.serialize(aInterval, out);
} else {
nullSerde.serialize(ANull.NULL, out);
}
result.set(resultStorage);
return;
} else if (type0 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, type0, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
} else {
throw new IncompatibleTypeException(getIdentifier(), type0, type1);
}
}
};
}
};
}
Aggregations