use of org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference in project asterixdb by apache.
the class RunningAggregateRuntimeFactory method createOneOutputPushRuntime.
@Override
public AbstractOneInputOneOutputOneFramePushRuntime createOneOutputPushRuntime(final IHyracksTaskContext ctx) throws HyracksDataException {
final int[] projectionToOutColumns = new int[projectionList.length];
for (int j = 0; j < projectionList.length; j++) {
projectionToOutColumns[j] = Arrays.binarySearch(outColumns, projectionList[j]);
}
return new AbstractOneInputOneOutputOneFramePushRuntime() {
private final IPointable p = VoidPointable.FACTORY.createPointable();
private final IRunningAggregateEvaluator[] raggs = new IRunningAggregateEvaluator[runningAggregates.length];
private final ArrayTupleBuilder tupleBuilder = new ArrayTupleBuilder(projectionList.length);
private boolean first = true;
private boolean isOpen = false;
@Override
public void open() throws HyracksDataException {
initAccessAppendRef(ctx);
if (first) {
first = false;
int n = runningAggregates.length;
for (int i = 0; i < n; i++) {
raggs[i] = runningAggregates[i].createRunningAggregateEvaluator(ctx);
}
}
for (int i = 0; i < runningAggregates.length; i++) {
raggs[i].init();
}
isOpen = true;
writer.open();
}
@Override
public void close() throws HyracksDataException {
if (isOpen) {
super.close();
}
}
@Override
public void fail() throws HyracksDataException {
if (isOpen) {
super.fail();
}
}
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
tAccess.reset(buffer);
int nTuple = tAccess.getTupleCount();
for (int t = 0; t < nTuple; t++) {
tRef.reset(tAccess, t);
produceTuple(tupleBuilder, tAccess, t, tRef);
appendToFrameFromTupleBuilder(tupleBuilder);
}
}
private void produceTuple(ArrayTupleBuilder tb, IFrameTupleAccessor accessor, int tIndex, FrameTupleReference tupleRef) throws HyracksDataException {
tb.reset();
for (int f = 0; f < projectionList.length; f++) {
int k = projectionToOutColumns[f];
if (k >= 0) {
raggs[k].step(tupleRef, p);
tb.addField(p.getByteArray(), p.getStartOffset(), p.getLength());
} else {
tb.addField(accessor, tIndex, projectionList[f]);
}
}
}
@Override
public void flush() throws HyracksDataException {
appender.flush(writer);
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference in project asterixdb by apache.
the class SimpleAlgebricksAccumulatingAggregatorFactory method createAggregator.
@Override
public IAggregatorDescriptor createAggregator(final IHyracksTaskContext ctx, RecordDescriptor inRecordDesc, RecordDescriptor outRecordDescriptor, int[] aggKeys, int[] partialKeys) throws HyracksDataException {
return new IAggregatorDescriptor() {
private FrameTupleReference ftr = new FrameTupleReference();
private IPointable p = VoidPointable.FACTORY.createPointable();
@Override
public void init(ArrayTupleBuilder tupleBuilder, IFrameTupleAccessor accessor, int tIndex, AggregateState state) throws HyracksDataException {
IAggregateEvaluator[] agg = (IAggregateEvaluator[]) state.state;
// initialize aggregate functions
for (int i = 0; i < agg.length; i++) {
agg[i].init();
}
ftr.reset(accessor, tIndex);
for (int i = 0; i < agg.length; i++) {
agg[i].step(ftr);
}
}
@Override
public void aggregate(IFrameTupleAccessor accessor, int tIndex, IFrameTupleAccessor stateAccessor, int stateTupleIndex, AggregateState state) throws HyracksDataException {
IAggregateEvaluator[] agg = (IAggregateEvaluator[]) state.state;
ftr.reset(accessor, tIndex);
for (int i = 0; i < agg.length; i++) {
agg[i].step(ftr);
}
}
@Override
public boolean outputFinalResult(ArrayTupleBuilder tupleBuilder, IFrameTupleAccessor stateAccessor, int tIndex, AggregateState state) throws HyracksDataException {
IAggregateEvaluator[] agg = (IAggregateEvaluator[]) state.state;
for (int i = 0; i < agg.length; i++) {
agg[i].finish(p);
tupleBuilder.addField(p.getByteArray(), p.getStartOffset(), p.getLength());
}
return true;
}
@Override
public AggregateState createAggregateStates() throws HyracksDataException {
IAggregateEvaluator[] agg = new IAggregateEvaluator[aggFactories.length];
for (int i = 0; i < agg.length; i++) {
agg[i] = aggFactories[i].createAggregateEvaluator(ctx);
}
return new AggregateState(agg);
}
@Override
public void reset() {
}
@Override
public boolean outputPartialResult(ArrayTupleBuilder tupleBuilder, IFrameTupleAccessor stateAccessor, int tIndex, AggregateState state) throws HyracksDataException {
IAggregateEvaluator[] agg = (IAggregateEvaluator[]) state.state;
for (int i = 0; i < agg.length; i++) {
agg[i].finishPartial(p);
tupleBuilder.addField(p.getByteArray(), p.getStartOffset(), p.getLength());
}
return true;
}
@Override
public void close() {
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference in project asterixdb by apache.
the class AbstractOneInputOneOutputOneFieldFramePushRuntime method initAccessAppendFieldRef.
protected final void initAccessAppendFieldRef(IHyracksTaskContext ctx) throws HyracksDataException {
frame = new VSizeFrame(ctx);
appender = new FrameFixedFieldTupleAppender(inputRecordDesc.getFieldCount());
appender.reset(frame, true);
tAccess = new FrameTupleAccessor(inputRecordDesc);
tRef = new FrameTupleReference();
}
Aggregations