Class StringMatchOperator
- java.lang.Object
-
- edu.caltech.nanodb.expressions.Expression
-
- edu.caltech.nanodb.expressions.StringMatchOperator
-
- All Implemented Interfaces:
java.lang.Cloneable
public class StringMatchOperator extends Expression
This class implements string matching operations. The supported operations are:
- basic SQL pattern matching, a [NOT] LIKE b
- regex pattern matching, a [NOT] SIMILAR TO b
The a NOT LIKE ... and a NOT SIMILAR TO ... operation is translated into NOT (a LIKE ...) etc. by the parser.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StringMatchOperator.Type
This enumeration specifies the types of matching that can be performed.
-
Field Summary
Fields Modifier and Type Field Description (package private) Expression
leftExpr
The left expression in the comparison.private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.(package private) Expression
rightExpr
The right expression in the comparison.(package private) StringMatchOperator.Type
type
The kind of comparison, such as "LIKE" or "SIMILAR TO."
-
Constructor Summary
Constructors Constructor Description StringMatchOperator(StringMatchOperator.Type type, Expression lhs, Expression rhs)
-
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 comparison expression and returns eitherBoolean.TRUE
orBoolean.FALSE
.ColumnInfo
getColumnInfo(Schema schema)
Returns aColumnInfo
object describing the type (and possibly the name) of the expression's result.Expression
getLeftExpression()
Returns the left expression.Expression
getRightExpression()
Returns the right expression.StringMatchOperator.Type
getType()
Returns the type of this comparison operator.int
hashCode()
Computes the hashcode of an Expression.private java.lang.String
sqlLikeToRegex(java.lang.String sqlLike)
This helper method converts a SQL LIKE match-expression into a corresponding regular expression.java.lang.String
toString()
Returns a string representation of this comparison expression and its subexpressions.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.Expression
duplicate, evaluate, evaluatePredicate, evaluatePredicate, getAllSymbols, hasSymbols, simplify
-
-
-
-
Field Detail
-
logger
private static org.apache.logging.log4j.Logger logger
A logging object for reporting anything interesting that happens.
-
type
StringMatchOperator.Type type
The kind of comparison, such as "LIKE" or "SIMILAR TO."
-
leftExpr
Expression leftExpr
The left expression in the comparison.
-
rightExpr
Expression rightExpr
The right expression in the comparison.
-
-
Constructor Detail
-
StringMatchOperator
public StringMatchOperator(StringMatchOperator.Type type, Expression lhs, Expression rhs)
-
-
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.
-
sqlLikeToRegex
private java.lang.String sqlLikeToRegex(java.lang.String sqlLike)
This helper method converts a SQL LIKE match-expression into a corresponding regular expression. The challenge is that the match expression might contain regular-expression characters, so characters other than "%" and "_" must be quoted so they don't cause any effects.- Parameters:
sqlLike
- the SQL LIKE match-expression- Returns:
- a regular expression corresponding to the match-expression
-
evaluate
public java.lang.Object evaluate(Environment env) throws ExpressionException
Evaluates this comparison expression and returns eitherBoolean.TRUE
orBoolean.FALSE
. If either the left-hand or right-hand expression evaluates tonull
(representing the SQL NULL value), then the expression's result is alwaysFALSE
.- 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
- 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 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()
Returns a string representation of this comparison expression and its subexpressions.- Overrides:
toString
in classjava.lang.Object
-
getType
public StringMatchOperator.Type getType()
Returns the type of this comparison operator.- Returns:
- the type of comparison
-
getLeftExpression
public Expression getLeftExpression()
Returns the left expression.- Returns:
- the left expression
-
getRightExpression
public Expression getRightExpression()
Returns the right expression.- Returns:
- the right expression
-
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
-
hashCode
public int hashCode()
Computes the hashcode of an Expression. This method is used to see if two expressions might be equal.- Specified by:
hashCode
in classExpression
-
clone
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
Creates a copy of expression. This method is used by theExpression.duplicate()
method to make a deep copy of an expression tree.- Overrides:
clone
in classExpression
- Throws:
java.lang.CloneNotSupportedException
-
-