Package edu.caltech.nanodb.expressions
Class ScalarSubquery
- java.lang.Object
-
- edu.caltech.nanodb.expressions.Expression
-
- edu.caltech.nanodb.expressions.SubqueryOperator
-
- edu.caltech.nanodb.expressions.ScalarSubquery
-
- All Implemented Interfaces:
java.lang.Cloneable
public class ScalarSubquery extends SubqueryOperator
This class represents a scalar subquery embedded in another query's predicate.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
evaluated
A flag indicating whether the subquery has been evaluated, and therefore whetherresult
is valid or not.(package private) java.lang.Object
result
The cached result of evaluating the scalar subquery.-
Fields inherited from class edu.caltech.nanodb.expressions.SubqueryOperator
subquery, subqueryPlan
-
-
Constructor Summary
Constructors Constructor Description ScalarSubquery(SelectClause subquery)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
clone()
Creates a copy of expression.boolean
equals(java.lang.Object obj)
Checks if the argument is an expression with the same structure, but not necessarily the same references.java.lang.Object
evaluate(Environment env)
Evaluates this expression object in the context of the specified environment.ColumnInfo
getColumnInfo(Schema schema)
Returns aColumnInfo
object describing the type (and possibly the name) of the expression's result.int
hashCode()
Computes the hash-code of this scalar subquery expression.java.lang.String
toString()
Expression
traverse(ExpressionProcessor p)
This method allows the entire expression tree to be traversed node by node, either for analysis or for transformation.-
Methods inherited from class edu.caltech.nanodb.expressions.SubqueryOperator
getSubquery, getSubqueryPlan, setSubqueryPlan
-
Methods inherited from class edu.caltech.nanodb.expressions.Expression
duplicate, evaluate, evaluatePredicate, evaluatePredicate, getAllSymbols, hasSymbols, simplify
-
-
-
-
Field Detail
-
result
java.lang.Object result
The cached result of evaluating the scalar subquery.
-
evaluated
boolean evaluated
A flag indicating whether the subquery has been evaluated, and therefore whetherresult
is valid or not.
-
-
Constructor Detail
-
ScalarSubquery
public ScalarSubquery(SelectClause subquery)
-
-
Method Detail
-
getColumnInfo
public ColumnInfo getColumnInfo(Schema schema) throws SchemaNameException
Description copied from class:Expression
Returns aColumnInfo
object describing the type (and possibly the name) of the expression's result.- Specified by:
getColumnInfo
in classExpression
- Parameters:
schema
- a schema object that can be used to look up name and type details for symbols referenced by the expression.- Returns:
- a column-information object describing the type (and possibly the name and table-name) of this expression's result
- Throws:
SchemaNameException
- if a symbol cannot be resolved, either because it doesn't appear in the schema, or because the name is ambiguous.
-
evaluate
public java.lang.Object evaluate(Environment env)
Description copied from class:Expression
Evaluates this expression object in the context of the specified environment. The environment provides any external information necessary to evaluate the expression, such as the current tuples loaded from tables referenced within the expression.- Specified by:
evaluate
in classExpression
- Parameters:
env
- the environment to look up symbol-values from, when evaluating the expression- Returns:
- the result of the expression evaluation
-
traverse
public Expression traverse(ExpressionProcessor p)
Description copied from class:Expression
This method allows the entire expression tree to be traversed node by node, either for analysis or for transformation. The
ExpressionProcessor
instance receives notifications as each node in the expression is entered and left.The expression tree can also be manipulated by this traversal process, depending on what the
ExpressionProcessor
wants to do. If the expression node thattraverse()
is invoked on, needs to be replaced with a new expression node, the replacement is returned by thetraverse()
method. (TheExpressionProcessor
specifies the replacement as the return-value from theExpressionProcessor.leave(Expression)
method.)- Specified by:
traverse
in classExpression
- Parameters:
p
- the object that performs analysis or transformation of the expression tree- Returns:
- an
Expression
node to replace this node, ornull
if no changes are to be made.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Checks if the argument is an expression with the same structure, but not necessarily the same references.- Specified by:
equals
in classExpression
- Parameters:
obj
- the object to which we are comparing- Design Note:
- This function operates correctly on the assumption that all supported types override Object.equals().
-
hashCode
public int hashCode()
Computes the hash-code of this scalar subquery expression.- Specified by:
hashCode
in classExpression
-
clone
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
Creates a copy of expression.- Overrides:
clone
in classExpression
- Throws:
java.lang.CloneNotSupportedException
- Design Note:
- The reference of the internal value is simply copied since the value types are all immutable.
-
-