Class SortNode

  • All Implemented Interfaces:

    public class SortNode
    extends PlanNode
    This plan node provides a simple in-memory sort operation for use in ORDER BY clauses.
    • Field Detail

      • logger

        private static org.apache.logging.log4j.Logger logger
        A logging object for reporting anything interesting that happens.
      • orderByExprs

        private java.util.List<OrderByExpression> orderByExprs
        A specification of the ordering of the results of this plan node.
      • sortedResults

        private java.util.ArrayList<Tuple> sortedResults
        This array receives all tuples from the child plan node, and then they are sorted and passed along to the parent from this array.
      • comparator

        private TupleComparator comparator
        The comparator that imposes the ordering specification of the sort node.
      • currentTupleIndex

        private int currentTupleIndex
        The index of the current tuple in the sorted results.
      • done

        private boolean done
        A flag indicating whether the sort node has generate all of its output or not.
    • Constructor Detail

      • SortNode

        public SortNode​(PlanNode subplan,
                        java.util.List<OrderByExpression> orderByExprs)
        Constructs a PlanNode with a given operation type. This method will be called by subclass constructors.
        subplan - the subplan that produces the results to sort
        orderByExprs - a specification of how the results should be ordered
    • Method Detail

      • resultsOrderedBy

        public java.util.List<OrderByExpression> resultsOrderedBy()
        Description copied from class: PlanNode
        If the results are ordered in some way, this method returns a collection of expressions specifying what columns or expressions the results are ordered by. If the results are not ordered then this method may return either an empty list or a null value.

        When this method returns a list of ordering expressions, the order of the expressions themselves also matters. The entire set of results will be ordered by the first expression; rows with the same value for the first expression will be ordered by the second expression; etc.

        Specified by:
        resultsOrderedBy in class PlanNode
        If the plan node produces ordered results, this will be a list of objects specifying the ordering. If the node doesn't produce ordered results then the return-value will either be an empty list or it will be null.
      • supportsMarking

        public boolean supportsMarking()
        The sort plan-node doesn't support marking.
        supportsMarking in class PlanNode
        true if the node supports position marking, false otherwise.
      • requiresLeftMarking

        public boolean requiresLeftMarking()
        The sort plan-node doesn't require marking from either of its children.
        requiresLeftMarking in class PlanNode
        true if the node requires that its left child supports marking, false otherwise.
      • requiresRightMarking

        public boolean requiresRightMarking()
        The sort plan-node doesn't require marking from either of its children.
        requiresRightMarking in class PlanNode
        true if the node requires that its right child supports marking, false otherwise.
      • prepare

        public void prepare()
        The sort plan-node produces the same schema as its child plan-node, so this method simply caches the subplan's schema object.
        Specified by:
        prepare in class PlanNode
      • initialize

        public void initialize()
        Does any initialization the node might need. This could include resetting state variables or starting the node over from the beginning.
        initialize in class PlanNode
      • getNextTuple

        public Tuple getNextTuple()
                           throws java.lang.IllegalStateException
        Gets the next tuple that fulfills the conditions for this plan node. If the node has a child, it should call getNextTuple() on the child. If the node is a leaf, the tuple comes from some external source such as a table file, the network, etc.
        Specified by:
        getNextTuple in class PlanNode
        the next tuple to be generated by this plan, or null if the plan has finished generating plan nodes.
        java.lang.IllegalStateException - if a plan node is not properly initialized
      • prepareSortedResults

        private void prepareSortedResults()
      • cleanUp

        public void cleanUp()
        Clean up after evaluation of the sort plan-node.
        Specified by:
        cleanUp in class PlanNode
      • toString

        public java.lang.String toString()
        Description copied from class: PlanNode
        Reports this node and its vital parameters as a string.
        Specified by:
        toString in class PlanNode
        the node in string format.
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if the argument is a plan node tree with the same structure, but not necesarily the same references.
        Specified by:
        equals in class PlanNode
        obj - the object to which we are comparing
        Design Note:
        We re-declare this here to force its implementation in subclasses.
      • hashCode

        public int hashCode()
        Computes the hash-code of a plan-node, including any sub-plans of this plan. This method is used to see if two plan nodes (or subtrees) might be equal.
        Specified by:
        hashCode in class PlanNode
        the hash code for the plan node and any subnodes it may contain.