Class Environment


  • public class Environment
    extends java.lang.Object
    This class holds the environment for evaluating expressions that include symbols. For example, in the SQL command:
      SELECT a, b + 5 FROM t WHERE c < 20;
    All of the expressions refer to columns in the current tuple being considered from the table t, and thus need to be able to access the current tuple. This is the role that the environment class serves.

    An important detail about the environment is that a single tuple's schema can hold values from multiple tables, such as when a tuple is produced as the result of a join operation between two tables.

    Design Note:
    (donnie) This class could be applied in several different ways. Any SELECT clause really could (or should) have its own environment associated with it, because it will reference tables. In addition, a derived table (a named subquery in the FROM clause) can also be referred to by name. So, we will have to devise a strategy for managing environments properly. Some plan-nodes will have to be responsible for updating environments, but definitely not all will do so.

    It probably makes the most sense to give every plan-node its own environment-reference. If the reference is null, the node could get its parent's environment. Or, we could set all plan-nodes to have a specific environment, and just manage that assignment process carefully.

    Environments can refer to a parent environment, for cases where a query contains subqueries. The subqueries can refer to the same table(s) as the outer query, and thus they need their own environment to track that information. This becomes especially useful with correlated subqueries, as the inner query needs to be completely reevaluated for each value of the outer query.

    Matching a symbol name goes from child to parent. If a child environment contains a value for a particular symbol, that value is returned. It is only if the child environment doesn't contain a value that the parent environment is utilized.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ArrayList<Schema> currentSchemas
      A list of the schemas being considered by the environment.
      private java.util.ArrayList<Tuple> currentTuples
      A mapping of string table names, to the current tuple for each of those tables.
      private java.util.ArrayList<Environment> parents
      In the case of correlated evaluation, this field holds parent environments that can be used to resolve symbol names into values.
    • Constructor Summary

      Constructors 
      Constructor Description
      Environment()  
    • Field Detail

      • currentSchemas

        private java.util.ArrayList<Schema> currentSchemas
        A list of the schemas being considered by the environment.
      • currentTuples

        private java.util.ArrayList<Tuple> currentTuples
        A mapping of string table names, to the current tuple for each of those tables. This class does not allow either table names or "current tuple" values to be null.
      • parents

        private java.util.ArrayList<Environment> parents
        In the case of correlated evaluation, this field holds parent environments that can be used to resolve symbol names into values.
    • Constructor Detail

      • Environment

        public Environment()
    • Method Detail

      • clear

        public void clear()
        Reset the environment.
      • addParentEnvironment

        public void addParentEnvironment​(Environment env)
      • addTuple

        public void addTuple​(Schema schema,
                             Tuple tuple)
        Adds a tuple to the environment with the given schema.
        Parameters:
        schema - the schema for the specified tuple
        tuple - the tuple to be added
      • getCurrentTuples

        public java.util.ArrayList<Tuple> getCurrentTuples()
        Returns the ArrayList of tuples being considered.
      • getColumnValue

        public java.lang.Object getColumnValue​(ColumnName colName)
        Get the actual value at the specified column.
        Parameters:
        colName - the name of the column