use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator in project asterixdb by apache.
the class FirstElementEvalFactory method createAggregateEvaluator.
@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IAggregateEvaluator() {
private boolean first = true;
// Needs to copy the bytes from inputVal to outputVal because the byte space of inputVal could be re-used
// by consequent tuples.
private ArrayBackedValueStorage outputVal = new ArrayBackedValueStorage();
private IPointable inputVal = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private final byte[] nullBytes = new byte[] { ATypeTag.SERIALIZED_NULL_TYPE_TAG };
private final byte[] systemNullBytes = new byte[] { ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG };
@Override
public void init() throws HyracksDataException {
first = true;
}
@Override
public void step(IFrameTupleReference tuple) throws HyracksDataException {
if (!first) {
return;
}
eval.evaluate(tuple, inputVal);
byte typeTagByte = inputVal.getByteArray()[inputVal.getStartOffset()];
if (typeTagByte == ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG) {
// Ignores SYSTEM_NULLs generated by local-first-element.
return;
}
outputVal.assign(inputVal);
first = false;
}
@Override
public void finish(IPointable result) throws HyracksDataException {
if (first) {
result.set(isLocal ? systemNullBytes : nullBytes, 0, 1);
return;
}
result.set(outputVal);
}
@Override
public void finishPartial(IPointable result) throws HyracksDataException {
finish(result);
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator 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.algebricks.runtime.base.IAggregateEvaluator 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.algebricks.runtime.base.IAggregateEvaluator in project asterixdb by apache.
the class ListifyAggregateFunctionEvalFactory method createAggregateEvaluator.
@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IAggregateEvaluator() {
private IPointable inputVal = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private OrderedListBuilder builder = new OrderedListBuilder();
@Override
public void init() throws HyracksDataException {
builder.reset(orderedlistType);
}
@Override
public void step(IFrameTupleReference tuple) throws HyracksDataException {
try {
eval.evaluate(tuple, inputVal);
builder.addItem(inputVal);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
@Override
public void finish(IPointable result) throws HyracksDataException {
resultStorage.reset();
try {
builder.write(resultStorage.getDataOutput(), true);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
@Override
public void finishPartial(IPointable result) throws HyracksDataException {
finish(result);
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator in project asterixdb by apache.
the class EmptyStreamAggregateDescriptor 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 = true;
@Override
public void init() throws HyracksDataException {
res = true;
}
@Override
public void step(IFrameTupleReference tuple) throws HyracksDataException {
res = false;
}
@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);
}
};
}
};
}
Aggregations