Commit 24161f80 authored by Donald H. (Donnie) Pinkston, III's avatar Donald H. (Donnie) Pinkston, III
Browse files

Support for "NOT LIKE" and "NOT SIMILAR TO"

The parser and StringMatchOperator class only supported "LIKE" and
"SIMILAR TO", not the inverse.  Now this is fixed.
parent b7961100
No related merge requests found
Showing with 23 additions and 5 deletions
+23 -5
......@@ -17,7 +17,7 @@ appender.console.filter.threshold.level = debug
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = ./nanodb-%d{MMddyy-HHmmss}-%i.log
appender.rolling.filePattern = ./nanodb-%i.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
appender.rolling.policies.type = Policies
......
......@@ -358,8 +358,8 @@ expression:
| expression op=( '<' | '<=' | '>' | '>=' | '=' | '==' | '!=' | '<>' ) expression # ExprCompare
| expression IS NOT? NULL # ExprIsNull
| expression NOT? BETWEEN expression AND expression # ExprBetween
| expression LIKE expression # ExprLike
| expression SIMILAR TO expression # ExprSimilarTo
| expression NOT? LIKE expression # ExprLike
| expression NOT? SIMILAR TO expression # ExprSimilarTo
| expression NOT? IN expressionList # ExprOneColInValues
| expression NOT? IN '(' selectStmt ')' # ExprOneColInSubquery
| expressionList NOT? IN '(' selectStmt ')' # ExprMultiColInSubquery
......
......@@ -74,6 +74,13 @@ public class StringMatchOperator extends Expression {
Expression rightExpr;
/**
* If this is false, the operator computes <tt>IS LIKE</tt>; if true,
* the operator computes <tt>IS NOT LIKE</tt>.
*/
private boolean invert;
public StringMatchOperator(Type type, Expression lhs, Expression rhs) {
if (type == null || lhs == null || rhs == null)
throw new NullPointerException();
......@@ -84,6 +91,11 @@ public class StringMatchOperator extends Expression {
}
public void setInvert(boolean invert) {
this.invert = invert;
}
public ColumnInfo getColumnInfo(Schema schema) throws SchemaNameException {
// Comparisons always return Boolean values, so just pass a Boolean
// value in to the TypeConverter to get out the corresponding SQL type.
......@@ -189,7 +201,10 @@ public class StringMatchOperator extends Expression {
"Unrecognized string-matching type " + type);
}
return Boolean.valueOf(result);
if (invert)
result = !result;
return result;
}
......@@ -211,6 +226,8 @@ public class StringMatchOperator extends Expression {
String leftStr = leftExpr.toString();
String rightStr = rightExpr.toString();
String opStr = " " + type.stringRep() + " ";
if (invert)
opStr = " NOT" + opStr;
// For now, assume we don't need parentheses.
......@@ -260,7 +277,7 @@ public class StringMatchOperator extends Expression {
if (obj instanceof StringMatchOperator) {
StringMatchOperator other = (StringMatchOperator) obj;
return (type == other.type &&
return (type == other.type && invert == other.invert &&
leftExpr.equals(other.leftExpr) &&
rightExpr.equals(other.rightExpr));
}
......@@ -277,6 +294,7 @@ public class StringMatchOperator extends Expression {
public int hashCode() {
int hash = 7;
hash = 31 * hash + type.hashCode();
hash = 31 * hash + Boolean.hashCode(invert);
hash = 31 * hash + leftExpr.hashCode();
hash = 31 * hash + rightExpr.hashCode();
return hash;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment