Search in sources :

Example 6 with IAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator 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)

Aggregations

IAggregateEvaluator (org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator)6 IPointable (org.apache.hyracks.data.std.api.IPointable)6 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)5 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)5 IOException (java.io.IOException)2 ABoolean (org.apache.asterix.om.base.ABoolean)2 IAggregateEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory)2 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)2 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)2 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)2 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)1 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)1 AggregateState (org.apache.hyracks.dataflow.std.group.AggregateState)1 IAggregatorDescriptor (org.apache.hyracks.dataflow.std.group.IAggregatorDescriptor)1