private static int GetAggregateFunctionsHashCode(IAggregate <TInput, TState, TOutput> a)
        {
            int x = a.Accumulate().ExpressionToCSharp().StableHash();

            x = x << 3 ^ a.ComputeResult().ExpressionToCSharp().StableHash();
            x = x << 3 ^ a.Deaccumulate().ExpressionToCSharp().StableHash();
            x = x << 3 ^ a.Difference().ExpressionToCSharp().StableHash();
            x = x << 3 ^ a.InitialState().ExpressionToCSharp().StableHash();
            return(x);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="aggregate"></param>
 public AggregateBStream(
     TumblingWindowBStream <TPayload> stream,
     IAggregate <TPayload, TAggState, TResult> aggregate
     ) : base(stream, stream.Period, stream.Offset)
 {
     Aggregate  = aggregate;
     Initialize = Aggregate.InitialState().Compile();
     Acc        = Aggregate.Accumulate().Compile();
     Res        = Aggregate.ComputeResult().Compile();
     Deacc      = Aggregate.Deaccumulate().Compile();
     Diff       = Aggregate.Difference().Compile();
 }
示例#3
0
        public static IAggregate <TInput, TState, TResult> SkipNulls <TInput, TState, TResult>(
            this IAggregate <TInput, TState, TResult> aggregate)
        {
            Contract.Requires(aggregate != null);

            var inputType = typeof(TInput).GetTypeInfo();

            return(inputType.IsClass
                ? GeneratedAggregate.Create(
                       initialState: aggregate.InitialState(),
                       accumulate: AddSkipNullClassLogic(aggregate.Accumulate()),
                       deaccumulate: AddSkipNullClassLogic(aggregate.Deaccumulate()),
                       difference: aggregate.Difference(),
                       computeResult: aggregate.ComputeResult())
                : inputType.IsGenericType && inputType.GetGenericTypeDefinition() == typeof(Nullable <>)
                ? GeneratedAggregate.Create(
                       initialState: aggregate.InitialState(),
                       accumulate: AddSkipNullValueLogic(aggregate.Accumulate()),
                       deaccumulate: AddSkipNullValueLogic(aggregate.Deaccumulate()),
                       difference: aggregate.Difference(),
                       computeResult: aggregate.ComputeResult())
                : aggregate);
        }
示例#4
0
        internal static IAggregate <TInput, TState, TResult> TransformOutput <TInput, TState, TAggregateResult, TResult>(
            this IAggregate <TInput, TState, TAggregateResult> aggregate,
            Expression <Func <TAggregateResult, TResult> > transform)
        {
            Contract.Requires(aggregate != null);
            Contract.Requires(transform != null);

            return(GeneratedAggregate.Create(
                       initialState: aggregate.InitialState(),
                       accumulate: aggregate.Accumulate(),
                       deaccumulate: aggregate.Deaccumulate(),
                       difference: aggregate.Difference(),
                       computeResult: aggregate.ComputeResult().TransformOutput(transform)));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="input"></param>
 /// <param name="aggregate"></param>
 /// <param name="window"></param>
 public TumblingAggregateFWindow(
     FWindowable <TPayload> input,
     IAggregate <TPayload, TAggState, TResult> aggregate,
     long window
     ) : base(input, input.Size, window, input.Offset, window)
 {
     Invariant.IsTrue(input.Size % window == 0, "Input size need to be a multiple of window");
     _window    = window;
     _aggregate = aggregate;
     _init      = _aggregate.InitialState().Compile();
     _acc       = _aggregate.Accumulate().Compile();
     _res       = _aggregate.ComputeResult().Compile();
     _BV        = new BVFSubWindow(Length);
 }
示例#6
0
        public static IAggregate <TInput?, TState, TResult> MakeInputNullableAndSkipNulls <TInput, TState, TResult>(
            this IAggregate <TInput, TState, TResult> aggregate) where TInput : struct
        {
            Contract.Requires(aggregate != null);

            Expression <Func <TState, long, TInput?, TState> > newAccumulate = (oldState, timestamp, input) =>
                                                                               input.HasValue ? CallInliner.Call(aggregate.Accumulate(), oldState, timestamp, input.Value) : oldState;

            Expression <Func <TState, long, TInput?, TState> > newDeaccumulate = (oldState, timestamp, input) =>
                                                                                 input.HasValue ? CallInliner.Call(aggregate.Deaccumulate(), oldState, timestamp, input.Value) : oldState;

            return(GeneratedAggregate.Create(
                       initialState: aggregate.InitialState(),
                       accumulate: newAccumulate.InlineCalls(),
                       deaccumulate: newDeaccumulate.InlineCalls(),
                       difference: aggregate.Difference(),
                       computeResult: aggregate.ComputeResult()));
        }
示例#7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="input"></param>
 /// <param name="aggregate"></param>
 /// <param name="window"></param>
 /// <param name="period"></param>
 public HoppingAggregateFWindow(
     FWindowable <TPayload> input,
     IAggregate <TPayload, TAggState, TResult> aggregate,
     long window, long period
     ) : base(input, input.Size, period, input.Offset, period)
 {
     Invariant.IsTrue(period % Input.Period == 0, "Period must be a multiple of input period");
     Invariant.IsTrue(window % period == 0, "Window must be a multiple of period");
     _window    = window;
     _aggregate = aggregate;
     _init      = _aggregate.InitialState().Compile();
     _acc       = _aggregate.Accumulate().Compile();
     _diff      = aggregate.Difference().Compile();
     _res       = _aggregate.ComputeResult().Compile();
     _states    = new TAggState[(window / period) + 1];
     _idx       = -1;
     _BV        = new BVFSubWindow(Length);
 }
示例#8
0
        public static IAggregate <TInput, NullOutputWrapper <TState>, TResult> OutputDefaultWhenEmpty <TInput, TState, TResult>(
            this IAggregate <TInput, TState, TResult> aggregate)
        {
            Contract.Requires(aggregate != null);

            Expression <Func <NullOutputWrapper <TState> > > newInitialState =
                () => new NullOutputWrapper <TState>
            {
                Count = 0,
                State = CallInliner.Call(aggregate.InitialState())
            };

            Expression <Func <NullOutputWrapper <TState>, long, TInput, NullOutputWrapper <TState> > > newAccumulate =
                (oldState, timestamp, input) => new NullOutputWrapper <TState>
            {
                Count = oldState.Count + 1,
                State = CallInliner.Call(aggregate.Accumulate(), oldState.State, timestamp, input)
            };

            Expression <Func <NullOutputWrapper <TState>, long, TInput, NullOutputWrapper <TState> > > newDeaccumulate =
                (oldState, timestamp, input) => new NullOutputWrapper <TState>
            {
                Count = oldState.Count - 1,
                State = CallInliner.Call(aggregate.Deaccumulate(), oldState.State, timestamp, input)
            };

            Expression <Func <NullOutputWrapper <TState>, NullOutputWrapper <TState>, NullOutputWrapper <TState> > > newDifference =
                (leftState, rightState) => new NullOutputWrapper <TState>
            {
                Count = leftState.Count - rightState.Count,
                State = CallInliner.Call(aggregate.Difference(), leftState.State, rightState.State)
            };

            Expression <Func <NullOutputWrapper <TState>, TResult> > newComputeResult =
                state => state.Count == 0 ? default : CallInliner.Call(aggregate.ComputeResult(), state.State);

                return(GeneratedAggregate.Create(
                           initialState: newInitialState.InlineCalls(),
                           accumulate: newAccumulate.InlineCalls(),
                           deaccumulate: newDeaccumulate.InlineCalls(),
                           difference: newDifference.InlineCalls(),
                           computeResult: newComputeResult.InlineCalls()));
        }
示例#9
0
        public static IAggregate <TInput, TState, TResult> ApplyFilter <TInput, TState, TResult>(
            this IAggregate <TInput, TState, TResult> aggregate,
            Expression <Func <TInput, bool> > filter)
        {
            Contract.Requires(aggregate != null);
            if (filter == null || filter.Body.ExpressionEquals(Expression.Constant(true)))
            {
                return(aggregate);
            }

            Expression <Func <TState, long, TInput, TState> > newAccumulate = (oldState, timestamp, input) =>
                                                                              CallInliner.Call(filter, input) ? CallInliner.Call(aggregate.Accumulate(), oldState, timestamp, input) : oldState;

            Expression <Func <TState, long, TInput, TState> > newDeaccumulate = (oldState, timestamp, input) =>
                                                                                CallInliner.Call(filter, input) ? CallInliner.Call(aggregate.Deaccumulate(), oldState, timestamp, input) : oldState;

            return(GeneratedAggregate.Create(
                       initialState: aggregate.InitialState(),
                       accumulate: newAccumulate.InlineCalls(),
                       deaccumulate: newDeaccumulate.InlineCalls(),
                       difference: aggregate.Difference(),
                       computeResult: aggregate.ComputeResult()));
        }