/
krasninja
/
querycat
Обзор
Документация
Войти
/
krasninja
/
querycat
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/QueryCat.Backend/Functions/Aggregate/SumAggregateFunction.cs
30 строк
1 KB
Ivan Kozhin
Introduce safe functions concept
25 янв 2024, 09:56
25 янв 2024, 09:56
d7659d7
Код
Авторство
О чём код?
using System.ComponentModel; using QueryCat.Backend.Core.Functions; using QueryCat.Backend.Core.Types; namespace QueryCat.Backend.Functions.Aggregate; /// <summary> /// Implements "summary" aggregation function. /// </summary> [SafeFunction] [Description("Computes the sum of values.")] [AggregateFunctionSignature("sum(value: integer): integer")] [AggregateFunctionSignature("sum(value: float): float")] [AggregateFunctionSignature("sum(value: numeric): numeric")] // ReSharper disable once ClassNeverInstantiated.Global internal sealed class SumAggregateFunction : IAggregateFunction { /// <inheritdoc /> public VariantValue[] GetInitialState(DataType type) => [VariantValue.Null]; /// <inheritdoc /> public void Invoke(VariantValue[] state, FunctionCallInfo callInfo) { var value = callInfo.GetAt(0); AggregateFunctionsUtils.ExecuteWithNullInitialState(ref state[0], in value, VariantValue.Add); } /// <inheritdoc /> public VariantValue GetResult(VariantValue[] state) => state[0]; }