Example #1
0
 public override System.Data.Entity.Core.Query.InternalTrees.Node Visit(
     ConstrainedSortOp op,
     System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     if (op.Keys.Count > 0 || n.Children.Count != 3 || (n.Child0 == null || n.Child1 == null) || (n.Child0.Op.OpType != OpType.Sort || n.Child1.Op.OpType != OpType.Null || n.Child0.Children.Count != 1))
     {
         return(n);
     }
     return(this.m_command.CreateNode((Op)this.m_command.CreateConstrainedSortOp(((SortBaseOp)n.Child0.Op).Keys, op.WithTies), n.Child0.Child0, n.Child1, n.Child2));
 }
Example #2
0
        // <summary>
        // ITreeGenerator.CreateLimitNode transforms Limit(Sort(x)) to ConstrainedSort(x,Null,Limit)
        // with the same keys as the input Sort. The transformation ensures that the sort is not
        // eliminated by the SortRemover if it occurs in a subquery.
        // ITreeGenerator.CreateLimitNode also transforms Limit(x) to ConstrainedSort(x,Null,Limit),
        // with no keys, when x is neither a Sort nor a ConstrainedSort. However, there are scenarios
        // where x includes a Sort that will be lifted during NestPullup, in which case this becomes
        // ConstrainedSort(Sort(x),Null,Limit) which is basically equivalent to Limit(Sort(x)) and
        // thus it needs to be transformed to ConstrainedSort(x,Null,Limit) with the same keys as
        // the input Sort.
        // </summary>
        public override Node Visit(ConstrainedSortOp op, Node n)
        {
            if (op.Keys.Count > 0 ||
                n.Children.Count != 3 ||
                n.Child0 == null ||
                n.Child1 == null ||
                n.Child0.Op.OpType != OpType.Sort ||
                n.Child1.Op.OpType != OpType.Null ||
                n.Child0.Children.Count != 1)
            {
                return(n);
            }

            return
                (m_command.CreateNode(
                     m_command.CreateConstrainedSortOp(((SortOp)n.Child0.Op).Keys, op.WithTies),
                     n.Child0.Child0,
                     n.Child1,
                     n.Child2));
        }
Example #3
0
        // <summary>
        // ITreeGenerator.CreateLimitNode transforms Limit(Sort(x)) to ConstrainedSort(x,Null,Limit)
        // with the same keys as the input Sort. The transformation ensures that the sort is not 
        // eliminated by the SortRemover if it occurs in a subquery.
        // ITreeGenerator.CreateLimitNode also transforms Limit(x) to ConstrainedSort(x,Null,Limit), 
        // with no keys, when x is neither a Sort nor a ConstrainedSort. However, there are scenarios
        // where x includes a Sort that will be lifted during NestPullup, in which case this becomes
        // ConstrainedSort(Sort(x),Null,Limit) which is basically equivalent to Limit(Sort(x)) and 
        // thus it needs to be transformed to ConstrainedSort(x,Null,Limit) with the same keys as 
        // the input Sort.
        // </summary>
        public override Node Visit(ConstrainedSortOp op, Node n)
        {
            if (op.Keys.Count > 0
                || n.Children.Count != 3
                || n.Child0 == null
                || n.Child1 == null
                || n.Child0.Op.OpType != OpType.Sort
                || n.Child1.Op.OpType != OpType.Null
                || n.Child0.Children.Count != 1)
            {
                return n;
            }

            return
                m_command.CreateNode(
                    m_command.CreateConstrainedSortOp(((SortOp)n.Child0.Op).Keys, op.WithTies),
                    n.Child0.Child0,
                    n.Child1,
                    n.Child2);
        }
Example #4
0
        // <summary>
        // ConstrainedSortOp
        // </summary>
        // <remarks>
        // Push the ConstrainedSortOp onto the driving node of the NestOp:
        // ConstrainedSortOp(NestOp(X,Y,...)) ==> NestOp(ConstrainedSortOp(X),Y,...)
        // There should not be any need for var renaming, because the ConstrainedSortOp cannot
        // refer to any vars from the NestOp
        // </remarks>
        public override Node Visit(ConstrainedSortOp op, Node n)
        {
            // Visit the children
            VisitChildren(n);

            // If the input is a nest op, we push the ConstrainedSort onto
            // the driving node.
            var nestOp = n.Child0.Op as NestBaseOp;
            if (nestOp != null)
            {
                var nestNode = n.Child0;
                n.Child0 = nestNode.Child0;
                nestNode.Child0 = n;
                nestNode.Op = GetNestOpWithConsolidatedSortKeys(nestOp, op.Keys);
                n = nestNode;
            }
            return n;
        }
        /// <summary>
        ///     Convert a ConstrainedSortOp. Specifically, walk the SortKeys, and expand out
        ///     any Structured type Var references
        /// </summary>
        /// <param name="op"> the constrainedSortOp </param>
        /// <param name="n"> the current node </param>
        /// <returns> new subtree </returns>
        public override Node Visit(ConstrainedSortOp op, Node n)
        {
            VisitChildren(n);

            var newSortKeys = HandleSortKeys(op.Keys);

            if (newSortKeys != op.Keys)
            {
                n.Op = m_command.CreateConstrainedSortOp(newSortKeys, op.WithTies);
            }
            return n;
        }
 public override void Visit(ConstrainedSortOp op, Node n)
 {
     base.Visit(op, n);
     AssertScalarOp(n.Child1.Op);
     Assert(
         TypeSemantics.IsIntegerNumericType(n.Child1.Op.Type), "ConstrainedSortOp Skip Count Node must have an integer result type");
     AssertScalarOp(n.Child2.Op);
     Assert(TypeSemantics.IsIntegerNumericType(n.Child2.Op.Type), "ConstrainedSortOp Limit Node must have an integer result type");
 }
 /// <summary>
 ///     Visitor pattern method for ConstrainedSortOp
 /// </summary>
 /// <param name="op"> The ConstrainedSortOp being visited </param>
 /// <param name="n"> The Node that references the Op </param>
 public virtual void Visit(ConstrainedSortOp op, Node n)
 {
     VisitSortOp(op, n);
 }
Example #8
0
        // <summary>
        // Copies a constrained sort node
        // </summary>
        // <param name="op"> The Op to Copy </param>
        // <param name="n"> The Node that references the Op </param>
        // <returns> A copy of the original Node that references a copy of the original Op </returns>
        public override Node Visit(ConstrainedSortOp op, Node n)
        {
            // Visit the Node's children and map their Vars
            var children = ProcessChildren(n);

            // Copy the ConstrainedSortOp's SortKeys
            var newSortKeys = Copy(op.Keys);

            // Create a new ConstrainedSortOp that uses the copied SortKeys and the original Op's WithTies value
            var newSortOp = m_destCmd.CreateConstrainedSortOp(newSortKeys, op.WithTies);

            // Return a new Node that references the copied SortOp and has the copied child Nodes as its children
            return m_destCmd.CreateNode(newSortOp, children);
        }