Search in sources :

Example 1 with IRunningAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator in project asterixdb by apache.

the class TidRunningAggregateDescriptor method createRunningAggregateEvaluatorFactory.

@Override
public IRunningAggregateEvaluatorFactory createRunningAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args) {
    return new IRunningAggregateEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
            return new IRunningAggregateEvaluator() {

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final ISerializerDeserializer<AInt64> serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                private final AMutableInt64 m = new AMutableInt64(0);

                private int cnt;

                @Override
                public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    m.setValue(cnt);
                    serde.serialize(m, resultStorage.getDataOutput());
                    result.set(resultStorage);
                    ++cnt;
                }

                @Override
                public void init() throws HyracksDataException {
                    cnt = 1;
                }
            };
        }
    };
}
Also used : IRunningAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IRunningAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Example 2 with IRunningAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator in project asterixdb by apache.

the class TupleCountRunningAggregateFunctionFactory method createRunningAggregateEvaluator.

@Override
public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
    final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    return new IRunningAggregateEvaluator() {

        int cnt;

        @Override
        public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            try {
                ++cnt;
                abvs.reset();
                abvs.getDataOutput().writeInt(cnt);
                result.set(abvs);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void init() throws HyracksDataException {
            cnt = 0;
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IRunningAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

IRunningAggregateEvaluator (org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator)2 IPointable (org.apache.hyracks.data.std.api.IPointable)2 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)2 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)2 IOException (java.io.IOException)1 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)1 IRunningAggregateEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluatorFactory)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1