Deveel.Data.Sql.Query.QueryPlanner.FilterHaving C# (CSharp) Method

FilterHaving() private method

private FilterHaving ( SqlExpression havingExpression, IList aggregates, IRequest context ) : SqlExpression
havingExpression Deveel.Data.Sql.Expressions.SqlExpression
aggregates IList
context IRequest
return Deveel.Data.Sql.Expressions.SqlExpression
        private SqlExpression FilterHaving(SqlExpression havingExpression, IList<SqlExpression> aggregates, IRequest context)
        {
            if (havingExpression is SqlBinaryExpression) {
                var binary = (SqlBinaryExpression) havingExpression;
                var expType = binary.ExpressionType;
                var newLeft = FilterHaving(binary.Left, aggregates, context);
                var newRight = FilterHaving(binary.Right, aggregates, context);
                return SqlExpression.Binary(newLeft, expType, newRight);
            }

            // Not logical so determine if the expression is an aggregate or not
            if (havingExpression.HasAggregate(context)) {
                // Has aggregate functions so we must WriteByte this expression on the
                // aggregate list.

                aggregates.Add(havingExpression);

                var name = new ObjectName(FunctionTableName, String.Format("HAVINGAGG_{0}", aggregates.Count));
                return SqlExpression.Reference(name);
            }

            return havingExpression;
        }