Class BooleanOperator

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class BooleanOperator
    extends Expression
    This class provides the standard Boolean logical operators AND, OR, and NOT, for two or more terms (or exactly one term, in the case of NOT). In addition, there are several methods provided for manipulating Boolean expressions, since many plan equivalence-rules involve manipulations of the Boolean logical expressions associated with Select and Theta-Join plan nodes.
    • Method Detail

      • getType

        public BooleanOperator.Type getType()
        Returns the type of this Boolean expression.
        Returns:
        the type of this Boolean expression.
      • addTerm

        public void addTerm​(Expression term)
      • getColumnInfo

        public ColumnInfo getColumnInfo​(Schema schema)
                                 throws SchemaNameException
        Description copied from class: Expression
        Returns a ColumnInfo object describing the type (and possibly the name) of the expression's result.
        Specified by:
        getColumnInfo in class Expression
        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)
                                  throws ExpressionException
        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 class Expression
        Parameters:
        env - the environment to look up symbol-values from, when evaluating the expression
        Returns:
        the result of the expression evaluation
        Throws:
        ExpressionException - if the expression cannot be evaluated for some reason.
      • 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 that traverse() is invoked on, needs to be replaced with a new expression node, the replacement is returned by the traverse() method. (The ExpressionProcessor specifies the replacement as the return-value from the ExpressionProcessor.leave(Expression) method.)

        Specified by:
        traverse in class Expression
        Parameters:
        p - the object that performs analysis or transformation of the expression tree
        Returns:
        an Expression node to replace this node, or null if no changes are to be made.
      • toString

        public java.lang.String toString()
        Returns a string representation of this Boolean logical expression and its subexpressions, including parentheses where necessary to specify precedence.
        Overrides:
        toString in class java.lang.Object
      • hasTermsReferencingAllTables

        public boolean hasTermsReferencingAllTables​(java.lang.String... tableNames)
        This method returns true if this Boolean expression contains any terms that reference the exact set of tables specified in the arguments. See the documentation for getTermsReferencingAllTables(java.lang.String...) for more details on what is considered to be a "matching" term by this method.
        Parameters:
        tableNames - a collection of table-names to look for in the terms.
        Returns:
        A list of terms that reference all of the tables specified in the input list, and no others.
        Design Note:
        This method is slightly more efficient than the get/remove methods, since it stops after it has found the first term that satisfies the specified conditions. However, if there will be a subsequent call to the get or remove method, it's probably most efficient to just call it directly.
      • getTermsReferencingAllTables

        public java.util.List<Expression> getTermsReferencingAllTables​(java.lang.String... tableNames)
        This method finds and returns a list of all terms in this Boolean expression that reference the exact set of tables specified in the arguments. If a term references other tables outside of this set then it will not be returned. If a term doesn't reference some table in this set then it will not be returned.
        Parameters:
        tableNames - a collection of table-names to look for in the terms.
        Returns:
        A list of terms that reference all of the tables specified in the input list, and no others.
      • removeTermsReferencingAllTables

        public java.util.List<Expression> removeTermsReferencingAllTables​(java.lang.String... tableNames)
        This method finds, removes, and returns a list of all terms in this Boolean expression that reference the exact set of tables specified in the arguments. If a term references other tables outside of this set then it will not be returned. If a term doesn't reference some table in this set then it will not be returned.

        The sole difference between this and getTermsReferencingAllTables(java.lang.String...) is that this method also removes the found terms from this Boolean expression object.

        Parameters:
        tableNames - a collection of table-names to look for in the terms.
        Returns:
        A list of terms that reference all of the tables specified in the input list, and no others. These terms are also removed from the Boolean expression object.
      • _getTermsReferencingAllTables

        private java.util.List<Expression> _getTermsReferencingAllTables​(java.lang.String[] tableNames,
                                                                         boolean remove)
        Parameters:
        tableNames - an array of table-names to look for in the terms.
        remove - if true then matching terms will be removed from this Boolean operator's list of terms.
        Returns:
        A list of terms that reference all of the tables specified in the input list, and no others.
      • getNumTerms

        public int getNumTerms()
        Returns the number of terms in the boolean expression.
        Returns:
        the number of terms in the boolean expression.
      • removeTerm

        public void removeTerm​(int i)
        Removes the ith term, starting from 0.
        Parameters:
        i - the index of the term to remove.
        Throws:
        java.lang.IllegalArgumentException - if the specified index is invalid.
      • simplify

        public Expression simplify()
        Simplifies a Boolean expression by eliminating and de-nesting as much of the expression as possible.
        Overrides:
        simplify in class Expression
        Returns:
        a reference to an expression, either a simplified version of this expression, or the original unmodified expression
      • equals

        public boolean equals​(java.lang.Object obj)
        Performs a value-eqality test for whether the specified object is an expression with the same structure and contents.
        Specified by:
        equals in class Expression
        Parameters:
        obj - the object to which we are comparing
      • hashCode

        public int hashCode()
        Computes the hash-code of an Expression.
        Specified by:
        hashCode in class Expression
      • clone

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Creates a copy of expression.
        Overrides:
        clone in class Expression
        Throws:
        java.lang.CloneNotSupportedException