Package edu.caltech.nanodb.plannodes
Class ProjectNode
- java.lang.Object
-
- edu.caltech.nanodb.plannodes.PlanNode
-
- edu.caltech.nanodb.plannodes.ProjectNode
-
- All Implemented Interfaces:
java.lang.Cloneable
public class ProjectNode extends PlanNode
PlanNode representing the SELECT clause in a SQL query. This is the relational algebra Project operator.
-
-
Field Summary
Fields Modifier and Type Field Description private Tuple
currentTuple
Current tuple the node is projecting (in NON-projected form).private boolean
done
True if we have finished pulling tuples from children.private static int
GUESS_NUM_UNIQUE_VALUES
This is our guess of how many unique values will be produced by a project expression, when we cannot determine it from the child plan's statistics.private PlanCost
inputCost
The cost of the input subplan.private Schema
inputSchema
The schema of tuples produced by the subplan.private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.private java.util.List<ColumnInfo>
nonWildcardColumnInfos
This collection holds the non-wildcard column information, so that we can more easily assign schema to projected tuples.private java.util.List<SelectValue>
projectionSpec
The new schema that this project node createsprivate boolean
projectIsTrivial
This flag is set to true if the project is a trivial projection, where tuples are passed through unmodified.-
Fields inherited from class edu.caltech.nanodb.plannodes.PlanNode
cost, environment, leftChild, rightChild, schema, stats
-
-
Constructor Summary
Constructors Constructor Description ProjectNode(PlanNode leftChild, java.util.List<SelectValue> projectionSpec)
Constructs a ProjectNode that pulls tuples from a child node.ProjectNode(java.util.List<SelectValue> projectionSpec)
Constructs a "leaf ProjectNode"; i.e.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
advanceCurrentTuple()
Helper function that advances the current tuple reference in the node.void
cleanUp()
Perform any necessary clean up tasks.protected PlanNode
clone()
Creates a copy of this project node and its subtree.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 and projects it.int
hashCode()
Computes and returns the hash-code of a project node.void
initialize()
Do initialization for the select operation.boolean
isTrivial()
Returns true if the project node is a trivial * projection with no table references.void
markCurrentPosition()
Marks the current tuple in the tuple-stream produced by this node.void
prepare()
This method is responsible for computing critical details about the plan node, such as the schema of the results that are produced, the estimated cost of evaluating the plan node (and its children), and statistics describing the results produced by the plan node.protected void
prepareSchemaStats(Schema inputSchema, java.util.ArrayList<ColumnStats> inputStats)
This helper function computes the schema of the project plan-node, based on the schema of its child-plan, and also the expressions specified in the project operation.private Tuple
projectTuple(Tuple tuple)
This helper method takes an input tuple and projects it to a result tuple based on the projectvoid
resetToLastMark()
Resets the node's tuple-stream to the most recently marked position.java.util.List<OrderByExpression>
resultsOrderedBy()
Determines whether the results of the node are sorted.boolean
supportsMarking()
This node supports marking if its subplan supports marking.java.lang.String
toString()
Returns a string representing this project node's details.private void
updateTrivialFlag()
This helper method sets theprojectIsTrivial
flag based on whether the passed-in projection specification is a single wildcard operation that would allow tuples to pass through unmodified.-
Methods inherited from class edu.caltech.nanodb.plannodes.PlanNode
addParentEnvironmentToPlanTree, duplicate, getCost, getEnvironment, getSchema, getStats, printNodeTree, printNodeTree, printNodeTree, printNodeTreeToString, printNodeTreeToString, requiresLeftMarking, requiresRightMarking, setEnvironment
-
-
-
-
Field Detail
-
logger
private static org.apache.logging.log4j.Logger logger
A logging object for reporting anything interesting that happens.
-
GUESS_NUM_UNIQUE_VALUES
private static final int GUESS_NUM_UNIQUE_VALUES
This is our guess of how many unique values will be produced by a project expression, when we cannot determine it from the child plan's statistics.- See Also:
- Constant Field Values
-
inputSchema
private Schema inputSchema
The schema of tuples produced by the subplan.
-
inputCost
private PlanCost inputCost
The cost of the input subplan.
-
projectionSpec
private java.util.List<SelectValue> projectionSpec
The new schema that this project node creates
-
projectIsTrivial
private boolean projectIsTrivial
This flag is set to true if the project is a trivial projection, where tuples are passed through unmodified.
-
nonWildcardColumnInfos
private java.util.List<ColumnInfo> nonWildcardColumnInfos
This collection holds the non-wildcard column information, so that we can more easily assign schema to projected tuples.
-
currentTuple
private Tuple currentTuple
Current tuple the node is projecting (in NON-projected form).
-
done
private boolean done
True if we have finished pulling tuples from children.
-
-
Constructor Detail
-
ProjectNode
public ProjectNode(PlanNode leftChild, java.util.List<SelectValue> projectionSpec)
Constructs a ProjectNode that pulls tuples from a child node.- Parameters:
leftChild
- the child to pull tuples fromprojectionSpec
- the set of expressions specifying how to project input tuples.
-
ProjectNode
public ProjectNode(java.util.List<SelectValue> projectionSpec)
Constructs a "leaf ProjectNode"; i.e. one that doesn't pull tuples from anywhere, but rather generates one tuple from its projection specification and then stops.- Parameters:
projectionSpec
- the set of expressions specifying how to project input tuples.
-
-
Method Detail
-
updateTrivialFlag
private void updateTrivialFlag()
This helper method sets theprojectIsTrivial
flag based on whether the passed-in projection specification is a single wildcard operation that would allow tuples to pass through unmodified.
-
isTrivial
public boolean isTrivial()
Returns true if the project node is a trivial * projection with no table references. If the projection is trivial then it could even be removed.- Returns:
- true if the select value is a full wildcard value, not even specifying a table name
-
prepare
public void prepare()
Description copied from class:PlanNode
This method is responsible for computing critical details about the plan node, such as the schema of the results that are produced, the estimated cost of evaluating the plan node (and its children), and statistics describing the results produced by the plan node.
-
prepareSchemaStats
protected void prepareSchemaStats(Schema inputSchema, java.util.ArrayList<ColumnStats> inputStats)
This helper function computes the schema of the project plan-node, based on the schema of its child-plan, and also the expressions specified in the project operation.
-
resultsOrderedBy
public java.util.List<OrderByExpression> resultsOrderedBy()
Determines whether the results of the node are sorted.- 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()
This node supports marking if its subplan supports marking.- Overrides:
supportsMarking
in classPlanNode
- Returns:
- true if the node supports position marking, false otherwise.
-
getNextTuple
public Tuple getNextTuple()
Gets the next tuple and projects it.- Specified by:
getNextTuple
in classPlanNode
- Returns:
- the tuple to be passed up to the next node.
-
advanceCurrentTuple
private void advanceCurrentTuple()
Helper function that advances the current tuple reference in the node.
-
projectTuple
private Tuple projectTuple(Tuple tuple)
This helper method takes an input tuple and projects it to a result tuple based on the project- Parameters:
tuple
- the tuple to project- Returns:
- the projected version of the tuple
-
initialize
public void initialize()
Do initialization for the select operation. Resets state variables.- Overrides:
initialize
in classPlanNode
-
markCurrentPosition
public void markCurrentPosition()
Description copied from class:PlanNode
Marks the current tuple in the tuple-stream produced by this node. ThePlanNode.resetToLastMark()
method can be used to return to this tuple. Note that only one marker can be set in the tuple-stream at a time.- Overrides:
markCurrentPosition
in classPlanNode
-
resetToLastMark
public void resetToLastMark()
Description copied from class:PlanNode
Resets the node's tuple-stream to the most recently marked position. Note that only one marker can be set in the tuple-stream at a time.- Overrides:
resetToLastMark
in classPlanNode
-
cleanUp
public void cleanUp()
Description copied from class:PlanNode
Perform any necessary clean up tasks. This should probably be called when we are done with this plan node.
-
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.
-
hashCode
public int hashCode()
Computes and returns the hash-code of a project node.
-
toString
public java.lang.String toString()
Returns a string representing this project node's details.
-
clone
protected PlanNode clone() throws java.lang.CloneNotSupportedException
Creates a copy of this project node and its subtree. This method is used byPlanNode.duplicate()
to copy a plan tree.
-
-