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(); }
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))); }
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); }
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())); }
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())); }
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())); }
public static bool HasSameStateAs <TInput, TState1, TState2, TResult1, TResult2>(this IAggregate <TInput, TState1, TResult1> left, IAggregate <TInput, TState2, TResult2> right) => typeof(TState1) == typeof(TState2) && left.Accumulate().ExpressionEquals(right.Accumulate()) && left.Deaccumulate().ExpressionEquals(right.Deaccumulate()) && left.Difference().ExpressionEquals(right.Difference()) && left.InitialState().ExpressionEquals(right.InitialState());