Ejemplo n.º 1
0
        /// <summary>
        /// Create aggregation functions
        /// </summary>
        public static Expression Aggregate(this Expression me, AggregationFunctionType aggregation)
        {
            var aggregateMethod = typeof(Enumerable).GetGenericMethod(aggregation.ToString(),
                                                                      new Type[] { me.Type.GetTypeInfo().GenericTypeArguments[0] },
                                                                      new Type[] { me.Type });

            return(Expression.Call(aggregateMethod as MethodInfo, me));
        }
Ejemplo n.º 2
0
        public Aggregation Instantiate(ColumnType columnType, AggregationFunctionType function, IScalarResolver[] parameters, IAggregationStrategy[] strategies)
        {
            var missingValue = (IMissingValueStrategy)(strategies.SingleOrDefault(x => x is IMissingValueStrategy) ?? new DropStrategy(columnType));
            var emptySeries  = (IEmptySeriesStrategy)(strategies.SingleOrDefault(x => x is IEmptySeriesStrategy) ?? new ReturnDefaultStrategy(columnType));

            var @namespace = $"{this.GetType().Namespace}.Function.";
            var typeName   = $"{Enum.GetName(typeof(AggregationFunctionType), function)}{Enum.GetName(typeof(ColumnType), columnType)}";
            var type       = GetType().Assembly.GetType($"{@namespace}{typeName}", false, true) ?? throw new ArgumentException($"No aggregation named '{typeName}' has been found in the namespace '{@namespace}'.");

            if ((parameters?.Count() ?? 0) == 0)
            {
                return(new Aggregation((IAggregationFunction)(type.GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>())), missingValue, emptySeries));
            }
            else
            {
                var ctor = type.GetConstructors().Where(x => x.IsPublic && (x.GetParameters().Count() == parameters.Count())).FirstOrDefault()
                           ?? throw new ArgumentException($"No public constructor for the aggregation '{function}' expecting {parameters.Count()} parameters.");
                return(new Aggregation((IAggregationFunction)ctor.Invoke(parameters), missingValue, emptySeries));
            }
        }
Ejemplo n.º 3
0
 public AggregationArgs(AggregationFunctionType function, ColumnType columnType, IList <IScalarResolver> parameters)
 => (ColumnType, Function, Parameters) = (columnType, function, parameters ?? new List <IScalarResolver>());
Ejemplo n.º 4
0
        public void Instantiate_ColumnTypeAndAggregationFunction_CorrectAggregation(ColumnType columnType, AggregationFunctionType function)
        {
            var factory = new AggregationFactory();

            Assert.Throws <ArgumentException>(() => factory.Instantiate(columnType, function, Array.Empty <IScalarResolver>(), Array.Empty <IAggregationStrategy>()));
        }
Ejemplo n.º 5
0
        public void Instantiate_ColumnTypeandAggregationFunction_CorrectAggregation(ColumnType columnType, AggregationFunctionType function, Type expectedType)
        {
            var factory     = new AggregationFactory();
            var aggregation = factory.Instantiate(columnType, function, Array.Empty <IScalarResolver>(), Array.Empty <IAggregationStrategy>());

            Assert.That(aggregation, Is.Not.Null);
            Assert.That(aggregation.Function, Is.TypeOf(expectedType));
        }
Ejemplo n.º 6
0
 public ColumnAggregationArgs(IColumnIdentifier identifier, AggregationFunctionType function, ColumnType columnType, IList <IScalarResolver> parameters)
     : base(function, columnType, parameters)
     => (Identifier) = (identifier);
Ejemplo n.º 7
0
 public AggregationXml(AggregationFunctionType function) => Function = function;