/// <summary>
        /// Parses an order by expression.
        /// Order by expression consists only of expression optionally followed by ASC or DESC token separated by comma.
        /// OrderBy -> ORDER BY OrderTerm (, OrderTerm)*
        /// OrderTerm -> Expression (ASC|DESC)?
        /// </summary>
        /// <returns> A tree representation of a order by or null if the tokens are missing order token on its first position. </returns>
        static public OrderByNode ParseOrderBy(ref int position, List <Token> tokens)
        {
            OrderByNode orderByNode = new OrderByNode();

            // We expect after reading match expr that the position is set on the Order token.
            // ORDER
            if (!CheckToken(position, Token.TokenType.Order, tokens))
            {
                return(null);
            }
            else
            {
                position++;
                // BY
                if (!CheckToken(position, Token.TokenType.By, tokens))
                {
                    ThrowError("Order by parser", "Expected BY.", position, tokens);
                }
                else
                {
                    position++;
                }


                Node node = ParseOrderTerm(ref position, tokens);
                if (node == null)
                {
                    ThrowError("Order by parser", "Expected order by term.", position, tokens);
                }
                orderByNode.AddNext(node);
                return(orderByNode);
            }
        }
 /// <summary>
 /// The root of the parse tree.
 /// Jumps to the node under the root.
 /// </summary>
 public void Visit(OrderByNode node)
 {
     node.next.Accept(this);
     if (result.Count < 1)
     {
         throw new ArgumentException($"{ this.GetType()}, failed to parse select expr.");
     }
 }
Beispiel #3
0
 public void Visit(OrderByNode node)
 {
     throw new NotImplementedException();
 }
Beispiel #4
0
        /// <summary>
        /// Creates an order by object.
        /// </summary>
        /// <param name="graph"> A graph the query is computed on. </param>
        /// <param name="variableMap"> A map of query variables. </param>
        /// <param name="executionHelper"> An order by execution helper. </param>
        /// <param name="orderByNode"> A parse tree of order by expression. </param>
        /// <param name="exprInfo"> A query expression information. </param>
        public OrderByObject(Graph graph, VariableMap variableMap, IOrderByExecutionHelper executionHelper, OrderByNode orderByNode, QueryExpressionInfo exprInfo)
        {
            if (executionHelper == null || orderByNode == null || variableMap == null || graph == null || exprInfo == null)
            {
                throw new ArgumentNullException($"{this.GetType()}, passing null arguments to the constructor.");
            }

            this.helper = executionHelper;

            var orderByVisitor = new OrderByVisitor(graph.labels, variableMap, exprInfo);

            orderByVisitor.Visit(orderByNode);
            var comps = orderByVisitor.GetResult();

            executionHelper.IsSetOrderBy = true;
            this.comparers = comps.ToArray();
        }
        public static ExpressionComparer[] ParseOrderBy(Graph graph, VariableMap variableMap, IOrderByExecutionHelper executionHelper, OrderByNode orderByNode, QueryExpressionInfo exprInfo, int columnCount)
        {
            if (executionHelper == null || orderByNode == null || variableMap == null || graph == null || exprInfo == null)
            {
                throw new ArgumentNullException($"Order by result processor, passing null arguments to the constructor.");
            }

            var orderByVisitor = new OrderByVisitor(graph.labels, variableMap, exprInfo);

            orderByVisitor.Visit(orderByNode);
            var comps = orderByVisitor.GetResult();

            executionHelper.IsSetOrderBy = true;

            return(comps.ToArray());
        }