Пример #1
0
        public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
        {
            MetaInfo metaInfo = AstUtil.GetMetaInfo(expression.Argument);

            // Find associated query scope and ensure the aggregate's argument does not mix
            // tables from different query scopes.

            QueryScope associatedScope = null;

            foreach (TableRefBinding tableDependency in metaInfo.TableDependencies)
            {
                if (associatedScope == null)
                {
                    associatedScope = tableDependency.Scope;
                }
                else if (associatedScope != tableDependency.Scope)
                {
                    _errorReporter.AggregateContainsColumnsFromDifferentQueries(expression.Argument);
                }
            }

            // Enter aggregate dependency.

            AddAggregateDependency(associatedScope, expression);

            return(expression);
        }
Пример #2
0
        private ICollection <AggregateExpression> GetAggregateDependencies(QueryScope associatedScope)
        {
            AggregateList associatedAggregateExpressions;

            if (_aggregateDependencies.TryGetValue(associatedScope, out associatedAggregateExpressions))
            {
                return(associatedAggregateExpressions.Values);
            }

            return(null);
        }
Пример #3
0
        private bool QueryHasAggregates(QueryScope queryScope)
        {
            if (_unscopedAggregateExpressionStack.Peek().Values.Count > 0)
            {
                return(true);
            }

            AggregateList queryAggregateList;

            if (_aggregateDependencies.TryGetValue(queryScope, out queryAggregateList) &&
                queryAggregateList.Values.Count > 0)
            {
                return(true);
            }

            return(false);
        }
Пример #4
0
        private void AddAggregateDependency(QueryScope associatedScope, AggregateExpression aggregateExpression)
        {
            if (associatedScope == null)
            {
                AggregateList currentUnscopedAggregateList = _unscopedAggregateExpressionStack.Peek();
                currentUnscopedAggregateList.Add(aggregateExpression);
            }
            else
            {
                AggregateList associatedAggregateExpressions;
                if (!_aggregateDependencies.TryGetValue(associatedScope, out associatedAggregateExpressions))
                {
                    associatedAggregateExpressions = new AggregateList();
                    _aggregateDependencies.Add(associatedScope, associatedAggregateExpressions);
                }

                associatedAggregateExpressions.Add(aggregateExpression);
            }
        }
Пример #5
0
 public QueryScope(QueryScope parentScope)
 {
     _parentScope = parentScope;
 }
Пример #6
0
 public void PushQueryScope(QueryScope queryScope)
 {
     _queryScopeStack.Push(queryScope);
 }
Пример #7
0
 private bool IsOuterScope(QueryScope scope)
 {
     return(!_queryScopeStack.Contains(scope));
 }