Package edu.caltech.nanodb.plannodes
Class SortNode
- java.lang.Object
-
- edu.caltech.nanodb.plannodes.PlanNode
-
- edu.caltech.nanodb.plannodes.SortNode
-
- All Implemented Interfaces:
java.lang.Cloneable
public class SortNode extends PlanNode
This plan node provides a simple in-memory sort operation for use in ORDER BY clauses.
-
-
Field Summary
Fields Modifier and Type Field Description private TupleComparator
comparator
The comparator that imposes the ordering specification of the sort node.private int
currentTupleIndex
The index of the current tuple in the sorted results.private boolean
done
A flag indicating whether the sort node has generate all of its output or not.private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.private java.util.List<OrderByExpression>
orderByExprs
A specification of the ordering of the results of this plan node.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.-
Fields inherited from class edu.caltech.nanodb.plannodes.PlanNode
cost, environment, leftChild, rightChild, schema, stats
-
-
Constructor Summary
Constructors Constructor Description SortNode(PlanNode subplan, java.util.List<OrderByExpression> orderByExprs)
Constructs a PlanNode with a given operation type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanUp()
Clean up after evaluation of the sort plan-node.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.Tuple
getNextTuple()
Gets the next tuple that fulfills the conditions for this plan node.int
hashCode()
Computes the hash-code of a plan-node, including any sub-plans of this plan.void
initialize()
Does any initialization the node might need.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.private void
prepareSortedResults()
boolean
requiresLeftMarking()
The sort plan-node doesn't require marking from either of its children.boolean
requiresRightMarking()
The sort plan-node doesn't require marking from either of its children.java.util.List<OrderByExpression>
resultsOrderedBy()
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.boolean
supportsMarking()
The sort plan-node doesn't support marking.java.lang.String
toString()
Reports this node and its vital parameters as a string.-
Methods inherited from class edu.caltech.nanodb.plannodes.PlanNode
addParentEnvironmentToPlanTree, clone, duplicate, getCost, getEnvironment, getSchema, getStats, markCurrentPosition, printNodeTree, printNodeTree, printNodeTree, printNodeTreeToString, printNodeTreeToString, resetToLastMark, setEnvironment
-
-
-
-
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.- Parameters:
subplan
- the subplan that produces the results to sortorderByExprs
- 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 classPlanNode
- Returns:
- 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.- Overrides:
supportsMarking
in classPlanNode
- Returns:
- 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.- Overrides:
requiresLeftMarking
in classPlanNode
- Returns:
- 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.- Overrides:
requiresRightMarking
in classPlanNode
- Returns:
- 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.
-
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.- Overrides:
initialize
in classPlanNode
-
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 classPlanNode
- Returns:
- the next tuple to be generated by this plan, or null if the plan has finished generating plan nodes.
- Throws:
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.
-
toString
public java.lang.String toString()
Description copied from class:PlanNode
Reports this node and its vital parameters as a string.
-
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.
-
-