Search in sources :

Example 16 with FrameTupleReference

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);
        }
    };
}
Also used : AbstractOneInputOneOutputOneFramePushRuntime(org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputOneFramePushRuntime) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) IPointable(org.apache.hyracks.data.std.api.IPointable) ByteBuffer(java.nio.ByteBuffer)

Example 17 with FrameTupleReference

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() {
        }
    };
}
Also used : AggregateState(org.apache.hyracks.dataflow.std.group.AggregateState) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) IAggregatorDescriptor(org.apache.hyracks.dataflow.std.group.IAggregatorDescriptor) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) IAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable)

Example 18 with FrameTupleReference

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();
}
Also used : FrameFixedFieldTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldTupleAppender) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor)

Aggregations

FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)18 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)12 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)11 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)10 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)9 DataOutput (java.io.DataOutput)7 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)7 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)7 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)4 IPointable (org.apache.hyracks.data.std.api.IPointable)4 AbstractOneInputOneOutputOneFramePushRuntime (org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputOneFramePushRuntime)3 PermutingFrameTupleReference (org.apache.hyracks.storage.am.common.tuples.PermutingFrameTupleReference)3 ISearchOperationCallback (org.apache.hyracks.storage.common.ISearchOperationCallback)3 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)2 PrimaryIndexLogMarkerCallback (org.apache.asterix.common.transactions.PrimaryIndexLogMarkerCallback)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2