Skip to content

Commit

Permalink
Use string predicate methods in interpreted
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Oct 5, 2018
1 parent f88006b commit 61c5fc2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,32 +211,32 @@ case class CachedNodePropertyExists(cachedNodeProperty: Expression) extends Pred
trait StringOperator {
self: Predicate =>
override def isMatch(m: ExecutionContext, state: QueryState) = (lhs(m, state), rhs(m, state)) match {
case (l: TextValue, r: TextValue) => Some(compare(l.stringValue(), r.stringValue()))
case (l: TextValue, r: TextValue) => Some(compare(l, r)
case (_, _) => None
}

def lhs: Expression
def rhs: Expression
def compare(a: String, b: String): Boolean
def compare(a: TextValue, b: TextValue): Boolean
override def containsIsNull = false
override def arguments = Seq(lhs, rhs)
override def symbolTableDependencies = lhs.symbolTableDependencies ++ rhs.symbolTableDependencies
}

case class StartsWith(lhs: Expression, rhs: Expression) extends Predicate with StringOperator {
override def compare(a: String, b: String) = a.startsWith(b)
override def compare(a: TextValue, b: TextValue) = a.startsWith(b)

override def rewrite(f: (Expression) => Expression) = f(copy(lhs.rewrite(f), rhs.rewrite(f)))
}

case class EndsWith(lhs: Expression, rhs: Expression) extends Predicate with StringOperator {
override def compare(a: String, b: String) = a.endsWith(b)
override def compare(a: TextValue, b: TextValue) = a.endsWith(b)

override def rewrite(f: (Expression) => Expression) = f(copy(lhs.rewrite(f), rhs.rewrite(f)))
}

case class Contains(lhs: Expression, rhs: Expression) extends Predicate with StringOperator {
override def compare(a: String, b: String) = a.contains(b)
override def compare(a: TextValue, b: TextValue) = a.contains(b)

override def rewrite(f: (Expression) => Expression) = f(copy(lhs.rewrite(f), rhs.rewrite(f)))
}
Expand Down Expand Up @@ -271,11 +271,8 @@ case class RegularExpression(lhsExpr: Expression, regexExpr: Expression)
val lValue = lhsExpr(m, state)
val rValue = regexExpr(m, state)
(lValue, rValue) match {
case (lhs, rhs) if rhs == Values.NO_VALUE || lhs == Values.NO_VALUE => None
case (lhs, rhs) => CypherBoolean.regex(lhs, rhs) match {
case b: BooleanValue => Some(b.booleanValue())
case _ => None
}
case (lhs: TextValue, rhs) if rhs != Values.NO_VALUE => Some(CypherBoolean.regex(lhs, rhs).booleanValue())
case _ => None
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public boolean contains( TextValue other )
}

final byte first = substring.bytes[substring.offset];
int max = offset + byteLength - substring.byteLength;
final int max = offset + byteLength - substring.byteLength;
for ( int pos = offset; pos <= max; pos++ )
{
//find first byte
Expand Down

0 comments on commit 61c5fc2

Please sign in to comment.