예제 #1
0
        private static FormulaValue RunAggregator(IAggregator agg, EvalVisitor runner, SymbolContext context, IRContext irContext, FormulaValue[] args)
        {
            var arg0 = (TableValue)args[0];
            var arg1 = (LambdaFormulaValue)args[1];

            foreach (DValue <RecordValue> row in arg0.Rows)
            {
                if (row.IsValue)
                {
                    var childContext = context.WithScopeValues(row.Value);
                    var value        = arg1.Eval(runner, childContext);

                    if (value is NumberValue number)
                    {
                        value = FiniteChecker(irContext, 0, number);
                    }

                    if (value is ErrorValue error)
                    {
                        return(error);
                    }
                    agg.Apply(value);
                }
            }

            return(agg.GetResult(irContext));
        }
예제 #2
0
        public override void Process(K key, V value)
        {
            if (key == null || value == null)
            {
                log.Warn($"Skipping record due to null key or value. key=[{key}] value=[{value}] topic=[{Context.Topic}] partition=[{Context.Partition}] offset=[{Context.Offset}]");
                return;
            }

            ValueAndTimestamp <T> oldAggAndTimestamp = store.Get(key);
            T    oldAgg, newAgg;
            long newTimestamp;

            if (oldAggAndTimestamp == null)
            {
                oldAgg       = initializer.Apply();
                newTimestamp = Context.Timestamp;
            }
            else
            {
                oldAgg       = oldAggAndTimestamp.Value;
                newTimestamp = Math.Max(Context.Timestamp, oldAggAndTimestamp.Timestamp);
            }

            newAgg = aggregator.Apply(key, value, oldAgg);

            store.Put(key, ValueAndTimestamp <T> .Make(newAgg, newTimestamp));
            tupleForwarder.MaybeForward(key, newAgg, sendOldValues ? oldAgg : default, newTimestamp);
예제 #3
0
 private static FormulaValue RunAggregator(IAggregator agg, IRContext irContext, FormulaValue[] values)
 {
     foreach (var value in values)
     {
         agg.Apply(value);
     }
     return(agg.GetResult(irContext));
 }
        public override void Process(K key, Change <V> value)
        {
            if (key == null)
            {
                throw new StreamsException($"Record key for KTable aggregate operator with state {queryableStoreName} should not be null.");
            }

            ValueAndTimestamp <T> oldAggAndTimestamp = store.Get(key);
            T    oldAgg = oldAggAndTimestamp != null ? oldAggAndTimestamp.Value : default;
            T    intermediateAgg;
            long newTimestamp = Context.Timestamp;

            // first try to remove the old value
            if (oldAggAndTimestamp != null && value.OldValue != null && oldAgg != null)
            {
                intermediateAgg = remove.Apply(key, value.OldValue, oldAgg);
                newTimestamp    = Math.Max(Context.Timestamp, oldAggAndTimestamp.Timestamp);
            }
            else
            {
                intermediateAgg = oldAgg;
            }

            // then try to add the new value
            T newAgg;

            if (value.NewValue != null)
            {
                T initializedAgg;
                if (intermediateAgg == null)
                {
                    initializedAgg = initializer.Apply();
                }
                else
                {
                    initializedAgg = intermediateAgg;
                }

                newAgg = add.Apply(key, value.NewValue, initializedAgg);
                if (oldAggAndTimestamp != null)
                {
                    newTimestamp = Math.Max(Context.Timestamp, oldAggAndTimestamp.Timestamp);
                }
            }
            else
            {
                newAgg = intermediateAgg;
            }

            // update the store with the new value
            store.Put(key, ValueAndTimestamp <T> .Make(newAgg, newTimestamp));
            tupleForwarder.MaybeForward(key, newAgg, sendOldValues ? oldAgg : default, newTimestamp);
        public override void Process(K key, V value)
        {
            if (key == null)
            {
                log.Warn($"Skipping record due to null key.value =[{value}] topic =[{Context.RecordContext.Topic}] partition =[{Context.RecordContext.Partition}] offset =[{Context.RecordContext.Offset }]");
                return;
            }

            observedStreamTime = Math.Max(observedStreamTime, Context.Timestamp);
            long closeTime      = observedStreamTime - windowOptions.GracePeriodMs;
            var  matchedWindows = windowOptions.WindowsFor(Context.Timestamp);

            foreach (var entry in matchedWindows)
            {
                long windowStart = entry.Key, windowEnd = entry.Value.EndMs;
                if (windowEnd > closeTime)
                {
                    var oldAggAndTimestamp = windowStore.Fetch(key, windowStart);

                    Agg oldAgg = oldAggAndTimestamp == null ? default : oldAggAndTimestamp.Value;
                                 long newTs;
                                 Agg  newAgg;

                                 if (oldAggAndTimestamp == null)
                                 {
                                     oldAgg = initializer.Apply();
                                     newTs  = Context.Timestamp;
                                 }
                                 else
                                 {
                                     newTs = Math.Max(Context.Timestamp, oldAggAndTimestamp.Timestamp);
                                 }

                                 newAgg = aggregator.Apply(key, value, oldAgg);
                                 windowStore.Put(key, ValueAndTimestamp <Agg> .Make(newAgg, newTs), windowStart);
                                 tupleForwarder.MaybeForward(new Windowed <K>(key, entry.Value), newAgg, sendOldValues ? oldAgg : default, newTs);