Search in sources :

Example 1 with IRunningAggregateEvaluatorFactory

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

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

the class RunningAggregatePOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    RunningAggregateOperator ragg = (RunningAggregateOperator) op;
    List<LogicalVariable> variables = ragg.getVariables();
    List<Mutable<ILogicalExpression>> expressions = ragg.getExpressions();
    int[] outColumns = new int[variables.size()];
    for (int i = 0; i < outColumns.length; i++) {
        outColumns[i] = opSchema.findVariable(variables.get(i));
    }
    IRunningAggregateEvaluatorFactory[] runningAggFuns = new IRunningAggregateEvaluatorFactory[expressions.size()];
    IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
    for (int i = 0; i < runningAggFuns.length; i++) {
        StatefulFunctionCallExpression expr = (StatefulFunctionCallExpression) expressions.get(i).getValue();
        runningAggFuns[i] = expressionRuntimeProvider.createRunningAggregateFunctionFactory(expr, context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas, context);
    }
    // TODO push projections into the operator
    int[] projectionList = JobGenHelper.projectAllVariables(opSchema);
    RunningAggregateRuntimeFactory runtime = new RunningAggregateRuntimeFactory(outColumns, runningAggFuns, projectionList);
    // contribute one Asterix framewriter
    RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
    builder.contributeMicroOperator(ragg, runtime, recDesc);
    // and contribute one edge from its child
    ILogicalOperator src = ragg.getInputs().get(0).getValue();
    builder.contributeGraphEdge(src, 0, ragg, 0);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) RunningAggregateRuntimeFactory(org.apache.hyracks.algebricks.runtime.operators.std.RunningAggregateRuntimeFactory) IRunningAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluatorFactory) StatefulFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.StatefulFunctionCallExpression) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) IExpressionRuntimeProvider(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionRuntimeProvider) RunningAggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator)

Aggregations

IRunningAggregateEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluatorFactory)2 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)1 Mutable (org.apache.commons.lang3.mutable.Mutable)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)1 IExpressionRuntimeProvider (org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionRuntimeProvider)1 StatefulFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.StatefulFunctionCallExpression)1 RunningAggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator)1 IRunningAggregateEvaluator (org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator)1 RunningAggregateRuntimeFactory (org.apache.hyracks.algebricks.runtime.operators.std.RunningAggregateRuntimeFactory)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)1 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)1 IPointable (org.apache.hyracks.data.std.api.IPointable)1 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)1 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)1