Example #1
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            Visit(query.Input);

            _writer.WriteLine();
            _writer.Write(ORDERBY);
            _writer.Write(" ");
            _writer.Indent += SELECT_INDENT;

            bool isFirst = true;

            foreach (OrderByColumn orderByColumn in query.OrderByColumns)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    _writer.Write(",");
                    _writer.WriteLine();
                }

                Visit(orderByColumn.Expression);

                if (orderByColumn.SortOrder == SortOrder.Descending)
                {
                    _writer.Write(" DESC");
                }
            }

            _writer.Indent -= SELECT_INDENT;

            return(query);
        }
Example #2
0
		public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements)
		{
			SortedQuery result = new SortedQuery();
			result.Input = (QueryNode)_input.Clone(alreadyClonedElements);
			result.OrderByColumns = ArrayHelpers.CreateDeepCopyOfAstElementArray(_orderByColumns, alreadyClonedElements);
			return result;
		}
Example #3
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            ResultAlgebraNode input = (ResultAlgebraNode)ConvertAstNode(query.Input);

            List <RowBufferEntry> sortColumns = new List <RowBufferEntry>();
            List <SortOrder>      sortOrders  = new List <SortOrder>();

            foreach (OrderByColumn orderByColumn in query.OrderByColumns)
            {
                RowBufferEntry sortColumn = input.OutputList[orderByColumn.ColumnIndex];
                sortColumns.Add(sortColumn);
                sortOrders.Add(orderByColumn.SortOrder);
            }

            SortAlgebraNode sortAlgebraNode = new SortAlgebraNode();

            sortAlgebraNode.Input       = input.Input;
            sortAlgebraNode.SortEntries = sortColumns.ToArray();
            sortAlgebraNode.SortOrders  = sortOrders.ToArray();
            input.Input = sortAlgebraNode;

            SetLastAlgebraNode(input);

            return(query);
        }
Example #4
0
        public override AstElement Clone(Dictionary <AstElement, AstElement> alreadyClonedElements)
        {
            SortedQuery result = new SortedQuery();

            result.Input          = (QueryNode)_input.Clone(alreadyClonedElements);
            result.OrderByColumns = ArrayHelpers.CreateDeepCopyOfAstElementArray(_orderByColumns, alreadyClonedElements);
            return(result);
        }
Example #5
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            query.Input = VisitQuery(query.Input);

            // NOTE: We don't visit the ORDER BY columns since they can only refer to existing expressions
            //       in the output of the inner most query. Later phases will ensure this is true.

            return(query);
        }
		public override QueryNode VisitSortedQuery(SortedQuery query)
		{
			query.Input = VisitQuery(query.Input);

			// NOTE: We don't visit the ORDER BY columns since they can only refer to existing expressions
			//       in the output of the inner most query. Later phases will ensure this is true.

			return query;
		}
Example #7
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            _xmlWriter.WriteStartElement("sortedQuery");

            WriteAstNode("input", query.Input);
            WriteOrderBy(query.OrderByColumns);

            _xmlWriter.WriteEndElement();

            return(query);
        }
Example #8
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            // Check if the input is select query. In this case we push the ORDER BY clause into the select query.
            // This is needed because the semantic of ORDER BY is slightly different for SELECT / UNION SELECT queries.

            SelectQuery inputAsSelectQuery = query.Input as SelectQuery;

            if (inputAsSelectQuery != null)
            {
                inputAsSelectQuery.OrderByColumns = query.OrderByColumns;
                return(VisitQuery(inputAsSelectQuery));
            }

            return(base.VisitSortedQuery(query));
        }
Example #9
0
        public virtual QueryNode VisitSortedQuery(SortedQuery query)
        {
            // Visit input
            query.Input = VisitQuery(query.Input);

            // Visit ORDER BY expressions

            if (query.OrderByColumns != null)
            {
                for (int i = 0; i < query.OrderByColumns.Length; i++)
                {
                    query.OrderByColumns[i].Expression = VisitExpression(query.OrderByColumns[i].Expression);
                }
            }

            return(query);
        }
Example #10
0
        private QueryNode ParseQuery()
        {
            EnableQueryKeywords();

            QueryNode result = ParseUnifiedOrExceptionalQuery();

            // ORDER BY

            if (_token.Id == TokenId.ORDER)
            {
                NextToken();
                Match(TokenId.BY);

                SortedQuery sortedQuery = new SortedQuery();
                sortedQuery.Input          = result;
                sortedQuery.OrderByColumns = ParseOrderByColumns();
                result = sortedQuery;
            }

            return(result);
        }
Example #11
0
        private static bool VisitSortedQuery(SortedQuery node1, SortedQuery node2)
        {
            if (node2 == null)
            {
                return(false);
            }

            if ((node1.Input == null) != (node2.Input == null) ||
                (node1.OrderByColumns == null) != (node2.OrderByColumns == null) ||
                node1.OrderByColumns.Length != node2.OrderByColumns.Length)
            {
                return(false);
            }

            if (node1.Input != null)
            {
                if (!Visit(node1.Input, node2.Input))
                {
                    return(false);
                }
            }

            if (node1.OrderByColumns != null)
            {
                for (int i = 0; i < node1.OrderByColumns.Length; i++)
                {
                    if (node1.OrderByColumns[i].SortOrder != node2.OrderByColumns[i].SortOrder)
                    {
                        return(false);
                    }

                    if (!Visit(node1.OrderByColumns[i].Expression, node2.OrderByColumns[i].Expression))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #12
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            _queryNestingLevel++;
            base.VisitSortedQuery(query);
            _queryNestingLevel--;

            ValidateOrderByClause(query.OrderByColumns);

            // Ensure that all ORDER BY expressions are present in the
            // input.

            if (query.Input is BinaryQuery)
            {
                bool allColumnsAreInInput = GetAllColumnsAreInInput(query.GetColumns(), query.OrderByColumns);
                if (!allColumnsAreInInput)
                {
                    _errorReporter.OrderByItemsMustBeInSelectListIfUnionSpecified();
                }
            }

            return(query);
        }
Example #13
0
		public override QueryNode VisitSortedQuery(SortedQuery query)
		{
			_xmlWriter.WriteStartElement("sortedQuery");

			WriteAstNode("input", query.Input);
			WriteOrderBy(query.OrderByColumns);

			_xmlWriter.WriteEndElement();

			return query;
		}
Example #14
0
		public override QueryNode VisitSortedQuery(SortedQuery query)
		{
			ResultAlgebraNode input = (ResultAlgebraNode)ConvertAstNode(query.Input);

			List<RowBufferEntry> sortColumns = new List<RowBufferEntry>();
			List<SortOrder> sortOrders = new List<SortOrder>();
			foreach (OrderByColumn orderByColumn in query.OrderByColumns)
			{
				RowBufferEntry sortColumn = input.OutputList[orderByColumn.ColumnIndex];
				sortColumns.Add(sortColumn);
				sortOrders.Add(orderByColumn.SortOrder);
			}

			SortAlgebraNode sortAlgebraNode = new SortAlgebraNode();
			sortAlgebraNode.Input = input.Input;
			sortAlgebraNode.SortEntries = sortColumns.ToArray();
			sortAlgebraNode.SortOrders = sortOrders.ToArray();
			input.Input = sortAlgebraNode;

			SetLastAlgebraNode(input);

			return query;
		}
Example #15
0
		private static bool VisitSortedQuery(SortedQuery node1, SortedQuery node2)
		{
			if (node2 == null)
				return false;

			if ((node1.Input == null) != (node2.Input == null) ||
				(node1.OrderByColumns == null) != (node2.OrderByColumns == null) ||
				node1.OrderByColumns.Length != node2.OrderByColumns.Length)
				return false;

			if (node1.Input != null)
				if (!Visit(node1.Input, node2.Input))
					return false;

			if (node1.OrderByColumns != null)
			{
				for (int i = 0; i < node1.OrderByColumns.Length; i++)
				{
					if (node1.OrderByColumns[i].SortOrder != node2.OrderByColumns[i].SortOrder)
						return false;

					if (!Visit(node1.OrderByColumns[i].Expression, node2.OrderByColumns[i].Expression))
						return false;
				}
			}

			return true;
		}
Example #16
0
		public override QueryNode VisitSortedQuery(SortedQuery query)
		{
			Visit(query.Input);

			_writer.WriteLine();
			_writer.Write(ORDERBY);
			_writer.Write(" ");
			_writer.Indent += SELECT_INDENT;

			bool isFirst = true;
			foreach (OrderByColumn orderByColumn in query.OrderByColumns)
			{
				if (isFirst)
				{
					isFirst = false;
				}
				else
				{
					_writer.Write(",");
					_writer.WriteLine();
				}

				Visit(orderByColumn.Expression);

				if (orderByColumn.SortOrder == SortOrder.Descending)
					_writer.Write(" DESC");
			}

			_writer.Indent -= SELECT_INDENT;

			return query;
		}
Example #17
0
        private QueryNode ParseQuery()
        {
            EnableQueryKeywords();

            QueryNode result = ParseUnifiedOrExceptionalQuery();

            // ORDER BY

            if (_token.Id == TokenId.ORDER)
            {
                NextToken();
                Match(TokenId.BY);

                SortedQuery sortedQuery = new SortedQuery();
                sortedQuery.Input = result;
                sortedQuery.OrderByColumns = ParseOrderByColumns();
                result = sortedQuery;
            }

            return result;
        }
Example #18
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            _queryNestingLevel++;
            base.VisitSortedQuery(query);
            _queryNestingLevel--;

            ValidateOrderByClause(query.OrderByColumns);

            // Ensure that all ORDER BY expressions are present in the
            // input.

            if (query.Input is BinaryQuery)
            {
                bool allColumnsAreInInput = GetAllColumnsAreInInput(query.GetColumns(), query.OrderByColumns);
                if (!allColumnsAreInInput)
                    _errorReporter.OrderByItemsMustBeInSelectListIfUnionSpecified();
            }

            return query;
        }
Example #19
0
		public override QueryNode VisitSortedQuery(SortedQuery query)
		{
			// Check if the input is select query. In this case we push the ORDER BY clause into the select query.
			// This is needed because the semantic of ORDER BY is slightly different for SELECT / UNION SELECT queries.

			SelectQuery inputAsSelectQuery = query.Input as SelectQuery;

			if (inputAsSelectQuery != null)
			{
				inputAsSelectQuery.OrderByColumns = query.OrderByColumns;
				return VisitQuery(inputAsSelectQuery);
			} 
			
			return base.VisitSortedQuery(query);
		}
Example #20
0
		public virtual QueryNode VisitSortedQuery(SortedQuery query)
		{
			// Visit input
			query.Input = VisitQuery(query.Input);

			// Visit ORDER BY expressions

			if (query.OrderByColumns != null)
			{
				for (int i = 0; i < query.OrderByColumns.Length; i++)
					query.OrderByColumns[i].Expression = VisitExpression(query.OrderByColumns[i].Expression);
			}

			return query;
		}
Example #21
0
        public override QueryNode VisitSortedQuery(SortedQuery query)
        {
            // It is legal but meaningless to sort a select query that have no
            // tables. So we simply optimize this SortedQuery node away.

            SelectQuery selectQuery = query.Input as SelectQuery;
            if (selectQuery != null && selectQuery.TableReferences == null)
                return VisitQuery(query.Input);

            // First we resolve the input.

            query.Input = VisitQuery(query.Input);

            // Find innermost SELECT query.
            //
            // This is the SELECT query the COLUMN definition is bought from.

            QueryNode currentInput = query.Input;
            SelectQuery innerMostInput = null;

            while (innerMostInput == null)
            {
                innerMostInput = currentInput as SelectQuery;

                if (innerMostInput == null)
                {
                    if (currentInput.NodeType == AstNodeType.BinaryQuery)
                    {
                        BinaryQuery inputAsBinaryQuery = (BinaryQuery)currentInput;
                        currentInput = inputAsBinaryQuery.Left;
                    }
                    else
                    {
                        throw ExceptionBuilder.InternalError("Unexpected input node: {0}\nSource:{1}", currentInput.NodeType, currentInput.GenerateSource());
                    }

                }
            }

            PushScope(innerMostInput.QueryScope);

            try
            {
                ResolveOrderBy(query.Input.GetColumns(), query.OrderByColumns);
                return query;
            }
            finally
            {
                PopScope();
            }
        }