Ejemplo n.º 1
0
        public override void AcceptChildren(WSqlFragmentVisitor visitor)
        {
            if (FromClause != null)
            {
                FromClause.Accept(visitor);
            }
            if (WhereClause != null)
            {
                WhereClause.Accept(visitor);
            }
            if (TopRowFilter != null)
            {
                TopRowFilter.Accept(visitor);
            }
            if (GroupByClause != null)
            {
                GroupByClause.Accept(visitor);
            }
            if (HavingClause != null)
            {
                HavingClause.Accept(visitor);
            }

            if (SelectElements != null)
            {
                var index = 0;
                for (var count = SelectElements.Count; index < count; ++index)
                {
                    SelectElements[index].Accept(visitor);
                }
            }

            base.AcceptChildren(visitor);
        }
Ejemplo n.º 2
0
        public void TestGroupByClauseAccept()
        {
            Mock <KoraliumSqlVisitor> mock          = new Mock <KoraliumSqlVisitor>();
            GroupByClause             groupByClause = new GroupByClause();

            groupByClause.Accept(mock.Object);
            mock.Verify(x => x.VisitGroupByClause(groupByClause));
        }
Ejemplo n.º 3
0
        public static GroupByStage GetGroupByStage(
            IQueryStage previousStage,
            GroupByClause groupByClause,
            HashSet <PropertyInfo> usedProperties,
            VisitorMetadata visitorMetadata)
        {
            GroupByVisitor groupByVisitor = new GroupByVisitor(previousStage, visitorMetadata);

            groupByClause.Accept(groupByVisitor);

            foreach (var property in groupByVisitor.UsedProperties)
            {
                usedProperties.Add(property);
            }

            var expressions = groupByVisitor.GroupByExpressions;

            var propertyTypes   = expressions.Select(x => x.Expression.Type).ToArray();
            var tupleType       = GetTupleType(propertyTypes);
            var builder         = SqlTypeInfo.NewBuilder();
            var tupleProperties = tupleType.GetProperties();

            for (int i = 0; i < expressions.Count; i++)
            {
                builder.AddProperty(expressions[i].Name, tupleProperties[i], expressions[i].OriginalProperty);
            }

            var groupingType = GetGroupingType(tupleType, previousStage.CurrentType);

            var constructor       = tupleType.GetConstructor(propertyTypes);
            var groupByExpression = Expression.New(constructor, expressions.Select(x => x.Expression));

            var groupParameter = Expression.Parameter(groupingType);

            var keyPropertyInfo        = groupingType.GetProperty("Key");
            var keyParameterExpression = Expression.MakeMemberAccess(groupParameter, keyPropertyInfo);

            return(new GroupByStage(
                       groupingType,
                       previousStage.CurrentType,
                       previousStage.TypeInfo,
                       builder.Build(),
                       groupParameter,
                       keyParameterExpression,
                       previousStage.ParameterExpression,
                       groupByExpression,
                       tupleType,
                       previousStage.FromAliases
                       ));
        }