public class Environment extends java.lang.ObjectThis 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
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.
Fields Modifier and Type Field Description
currentSchemasA list of the schemas being considered by the environment.
currentTuplesA mapping of string table names, to the current tuple for each of those tables.
parentsIn the case of correlated evaluation, this field holds parent environments that can be used to resolve symbol names into values.
Constructors Constructor Description
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
addTuple(Schema schema, Tuple tuple)Adds a tuple to the environment with the given schema.
clear()Reset the environment.
getColumnValue(ColumnName colName)Get the actual value at the specified column.
getCurrentTuples()Returns the ArrayList of tuples being considered.
private java.util.ArrayList<Schema> currentSchemasA list of the schemas being considered by the environment.
private java.util.ArrayList<Tuple> currentTuplesA 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.
private java.util.ArrayList<Environment> parents
public void clear()Reset the environment.
public void addParentEnvironment(Environment env)
addTupleAdds a tuple to the environment with the given schema.
schema- the schema for the specified tuple
tuple- the tuple to be added
public java.util.ArrayList<Tuple> getCurrentTuples()Returns the ArrayList of tuples being considered.
public java.lang.Object getColumnValue(ColumnName colName)Get the actual value at the specified column.
colName- the name of the column