コード例 #1
0
ファイル: Validator.cs プロジェクト: chenzuo/nquery
        public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
        {
            // Check that all aggregated expressions appear only in queries.

            if (_queryNestingLevel == 0)
                _errorReporter.AggregateInvalidInCurrentContext(expression);

            // Check that all aggregated expressions do not contain other aggregated
            // expressions.

            if (_currentAggregateExpression != null)
            {
                // Oops, we found a nested aggregate.

                _errorReporter.AggregateCannotContainAggregate(_currentAggregateExpression, _currentAggregateExpression.Aggregate, expression.Aggregate);
                return base.VisitAggregagateExpression(expression);
            }

            // Validate all embedded expressions that check aggregation expressions.

            _currentAggregateExpression = expression;
            ExpressionNode result = base.VisitAggregagateExpression(expression);
            _currentAggregateExpression = null;

            return result;
        }
コード例 #2
0
ファイル: AggregateBinder.cs プロジェクト: chenzuo/nquery
			public void Add(AggregateExpression aggregateExpression)
			{
				AggregateExpression matchingAggregateExpression = null;
				foreach (AggregateExpression existingAggregateExpression in _aggregateExpressions)
				{
					if (existingAggregateExpression.IsStructuralEqualTo(aggregateExpression))
					{
						matchingAggregateExpression = existingAggregateExpression;
						break;
					}
				}

				if (matchingAggregateExpression != null)
				{
					aggregateExpression.ValueDefinition = matchingAggregateExpression.ValueDefinition;
				}
				else
				{
					RowBufferEntry rowBufferEntry = new RowBufferEntry(aggregateExpression.Aggregator.ReturnType);

					AggregatedValueDefinition aggregatedValueDefinition = new AggregatedValueDefinition();
					aggregatedValueDefinition.Target = rowBufferEntry;
					aggregatedValueDefinition.Aggregate = aggregateExpression.Aggregate;
					aggregatedValueDefinition.Aggregator = aggregateExpression.Aggregator;
					aggregatedValueDefinition.Argument = aggregateExpression.Argument;
					aggregateExpression.ValueDefinition = aggregatedValueDefinition;
					_aggregateExpressions.Add(aggregateExpression);
				}
			}
コード例 #3
0
ファイル: AggregateExpression.cs プロジェクト: chenzuo/nquery
		public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements)
		{
			AggregateExpression result = new AggregateExpression();
			result.Aggregate = _aggregate;
			result.Aggregator = _aggregator;
			result.Argument = _argument;
			result.HasAsteriskModifier = _hasAsteriskModifier;
			return result;
		}
コード例 #4
0
		public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
		{
			expression.Argument = VisitExpression(expression.Argument);

			expression.ValueDefinition.Argument = expression.Argument;

			RowBufferEntryExpression rowBufferExpression = new RowBufferEntryExpression();
			rowBufferExpression.RowBufferEntry = expression.ValueDefinition.Target;
			return rowBufferExpression;
		}
コード例 #5
0
        public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
        {
            expression.Argument = VisitExpression(expression.Argument);

            expression.ValueDefinition.Argument = expression.Argument;

            RowBufferEntryExpression rowBufferExpression = new RowBufferEntryExpression();

            rowBufferExpression.RowBufferEntry = expression.ValueDefinition.Target;
            return(rowBufferExpression);
        }
コード例 #6
0
        public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
        {
            _xmlWriter.WriteStartElement("aggregagateExpression");
            _xmlWriter.WriteAttributeString("aggregateFunction", expression.Aggregate.Name);
            WriteTypeAttribute(expression.ExpressionType);

            WriteAstNode("argument", expression.Argument);

            _xmlWriter.WriteEndElement();

            return(expression);
        }
コード例 #7
0
        public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
        {
            _writer.WriteIdentifier(expression.Aggregate.Name);

            if (expression.HasAsteriskModifier)
            {
                _writer.Write("(*)");
            }
            else
            {
                _writer.Write("(");
                Visit(expression.Argument);
                _writer.Write(")");
            }

            return(expression);
        }
コード例 #8
0
ファイル: AggregateBinder.cs プロジェクト: chenzuo/nquery
		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);
			}
		}
コード例 #9
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);
            }
        }
コード例 #10
0
ファイル: StandardVisitor.cs プロジェクト: chenzuo/nquery
		public virtual ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
		{
			expression.Argument = VisitExpression(expression.Argument);
			return expression;
		}
コード例 #11
0
ファイル: Comparer.cs プロジェクト: chenzuo/nquery
		private static bool VisitAggregagateExpression(AggregateExpression node1, AggregateExpression node2)
		{
			return node2 != null &&
			       node1.HasAsteriskModifier == node2.HasAsteriskModifier &&
			       node1.Aggregate == node2.Aggregate &&
			       Visit(node1.Argument, node2.Argument);
		}
コード例 #12
0
ファイル: SourceGenerator.cs プロジェクト: chenzuo/nquery
		public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
		{
			_writer.WriteIdentifier(expression.Aggregate.Name);

			if (expression.HasAsteriskModifier)
			{
				_writer.Write("(*)");
			}
			else
			{
				_writer.Write("(");
				Visit(expression.Argument);
				_writer.Write(")");
			}

			return expression;
		}
コード例 #13
0
ファイル: ErrorProvider.cs プロジェクト: chenzuo/nquery
 void IErrorReporter.AggregateInvalidInCurrentContext(AggregateExpression aggregateExpression)
 {
     string message = String.Format(CultureInfo.CurrentCulture, Resources.AggregateInvalidInCurrentContext, aggregateExpression.GenerateSource());
     HandleError(ErrorId.AggregateInvalidInCurrentContext, message);
 }
コード例 #14
0
ファイル: ErrorProvider.cs プロジェクト: chenzuo/nquery
 void IErrorReporter.AggregateCannotContainSubquery(AggregateExpression expression)
 {
     string message = String.Format(CultureInfo.CurrentCulture, Resources.AggregateCannotContainSubquery, expression.GenerateSource());
     HandleError(ErrorId.AggregateCannotContainAggregate, message);
 }
コード例 #15
0
ファイル: XmlProducer.cs プロジェクト: chenzuo/nquery
		public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
		{
			_xmlWriter.WriteStartElement("aggregagateExpression");
			_xmlWriter.WriteAttributeString("aggregateFunction", expression.Aggregate.Name);
			WriteTypeAttribute(expression.ExpressionType);

			WriteAstNode("argument", expression.Argument);

			_xmlWriter.WriteEndElement();

			return expression;
		}
コード例 #16
0
        public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
        {
            // We don't visit the arguments of aggregation nodes. This way
            // we get only columns that are not contained in an aggregate.

            return expression;
        }
コード例 #17
0
 public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
 {
     _containsGroupByHavingOrAggregate = true;
     return(base.VisitAggregagateExpression(expression));
 }
コード例 #18
0
ファイル: Resolver.cs プロジェクト: chenzuo/nquery
        public override ExpressionNode VisitFunctionInvocationExpression(FunctionInvocationExpression expression)
        {
            // Resolve aggregation
            // -- or --
            // Resolve method

            // First all parameters must be resolved.

            base.VisitFunctionInvocationExpression(expression);

            // If the type of any argument could not be resolved we cannot resolve the method.

            foreach (ExpressionNode argument in expression.Arguments)
            {
                if (argument.ExpressionType == null)
                    return expression;
            }

            // Resolve aggregate

            bool canBeAggregate = expression.Arguments.Length == 1 || (expression.Arguments.Length == 0 && expression.HasAsteriskModifier);
            if (canBeAggregate)
            {
                AggregateBinding aggregateBinding = ResolveAggregate(expression.NameSourceRange, expression.Name);

                if (aggregateBinding != null)
                {
                    ExpressionNode aggregateArgument;

                    if (!expression.HasAsteriskModifier)
                    {
                        aggregateArgument = expression.Arguments[0];
                    }
                    else
                    {
                        // Only COUNT can have the asterisk modifier.

                        Identifier countName = Identifier.CreateNonVerbatim("COUNT");
                        if (!countName.Matches(aggregateBinding.Name))
                            ErrorReporter.AsteriskModifierNotAllowed(expression.NameSourceRange, expression);

                        // The semantic of COUNT(*) says that it counts all rows of the bound
                        // query. The same result can be accomplished by using COUNT(0) (or any
                        // otherc onstant non-null expression as argument). Therefore we use a
                        // literal zero as the argument.
                        aggregateArgument = LiteralExpression.FromInt32(0);
                    }

                    IAggregator aggregator = aggregateBinding.CreateAggregator(aggregateArgument.ExpressionType);

                    if (aggregator == null)
                    {
                        ErrorReporter.AggregateDoesNotSupportType(aggregateBinding, aggregateArgument.ExpressionType);
                        return expression;
                    }

                    AggregateExpression aggregateExpression = new AggregateExpression();
                    aggregateExpression.Aggregate = aggregateBinding;
                    aggregateExpression.Aggregator = aggregator;
                    aggregateExpression.Argument = aggregateArgument;
                    aggregateExpression.HasAsteriskModifier = expression.HasAsteriskModifier;
                    return aggregateExpression;
                }
            }

            // Resolve method

            if (expression.HasAsteriskModifier)
            {
                // Simple invocations cannot have asterisk modifier.
                ErrorReporter.AsteriskModifierNotAllowed(expression.NameSourceRange, expression);

                // Leave to avoid cascading errors.
                return expression;
            }

            Type[] argumentTypes = new Type[expression.Arguments.Length];
            for (int i = 0; i < argumentTypes.Length; i++)
                argumentTypes[i] = expression.Arguments[i].ExpressionType;

            expression.Function = ResolveFunction(expression.Name, argumentTypes);

            if (expression.Function == null)
            {
                ErrorReporter.UndeclaredFunction(expression.NameSourceRange, expression.Name, argumentTypes);
            }
            else
            {
                // Convert all arguments if necessary

                Type[] parameterTypes = expression.Function.GetParameterTypes();

                for (int i = 0; i < expression.Arguments.Length; i++)
                    expression.Arguments[i] = Binder.ConvertExpressionIfRequired(expression.Arguments[i], parameterTypes[i]);
            }

            return expression;
        }
コード例 #19
0
		public override ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
		{
			_containsGroupByHavingOrAggregate = true;
			return base.VisitAggregagateExpression(expression);
		}
コード例 #20
0
 public virtual ExpressionNode VisitAggregagateExpression(AggregateExpression expression)
 {
     expression.Argument = VisitExpression(expression.Argument);
     return(expression);
 }
コード例 #21
0
ファイル: ErrorProvider.cs プロジェクト: chenzuo/nquery
 void IErrorReporter.AggregateCannotContainAggregate(AggregateExpression expression, AggregateBinding parent, AggregateBinding nested)
 {
     string message = String.Format(CultureInfo.CurrentCulture, Resources.AggregateCannotContainAggregate, expression.GenerateSource(), parent.Name, nested.Name);
     HandleError(ErrorId.AggregateCannotContainAggregate, message);
 }
コード例 #22
0
ファイル: AggregateBinder.cs プロジェクト: chenzuo/nquery
		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;
		}