Class 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 creates
      private boolean projectIsTrivial
      This flag is set to true if the project is a trivial projection, where tuples are passed through unmodified.
    • 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.
    • 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 from
        projectionSpec - 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 the projectIsTrivial 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.
        Specified by:
        prepare in class PlanNode
      • 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 class PlanNode
        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 class PlanNode
        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 class PlanNode
        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 class PlanNode
      • markCurrentPosition

        public void markCurrentPosition()
        Description copied from class: PlanNode
        Marks the current tuple in the tuple-stream produced by this node. The PlanNode.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 class PlanNode
      • 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 class PlanNode
      • 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.
        Specified by:
        cleanUp in class PlanNode
      • 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
        Parameters:
        obj - the object to which we are comparing
      • hashCode

        public int hashCode()
        Computes and returns the hash-code of a project node.
        Specified by:
        hashCode in class PlanNode
        Returns:
        the hash code for the plan node and any subnodes it may contain.
      • toString

        public java.lang.String toString()
        Returns a string representing this project node's details.
        Specified by:
        toString in class PlanNode
        Returns:
        a string representing this project-node.
      • clone

        protected PlanNode clone()
                          throws java.lang.CloneNotSupportedException
        Creates a copy of this project node and its subtree. This method is used by PlanNode.duplicate() to copy a plan tree.
        Overrides:
        clone in class PlanNode
        Throws:
        java.lang.CloneNotSupportedException