Repository: incubator-s2graph Updated Branches: refs/heads/master 1881df05c -> 2083d136e
add Not logical operator on WhereParser. Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/f288680c Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/f288680c Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/f288680c Branch: refs/heads/master Commit: f288680c46c23ac90fba1741baf494c061921277 Parents: 32eb344 Author: DO YUNG YOON <[email protected]> Authored: Fri Jun 15 11:21:17 2018 +0900 Committer: DO YUNG YOON <[email protected]> Committed: Fri Jun 15 11:21:17 2018 +0900 ---------------------------------------------------------------------- .../apache/s2graph/core/parsers/WhereParser.scala | 16 ++++++++-------- .../s2graph/core/parsers/WhereParserTest.scala | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f288680c/s2core/src/main/scala/org/apache/s2graph/core/parsers/WhereParser.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/parsers/WhereParser.scala b/s2core/src/main/scala/org/apache/s2graph/core/parsers/WhereParser.scala index 75e9657..d6e176b 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/parsers/WhereParser.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/parsers/WhereParser.scala @@ -198,10 +198,14 @@ case class WhereParser() extends JavaTokenParsers { def paren: Parser[Clause] = "(" ~> clause <~ ")" - def clause: Parser[Clause] = (predicate | paren) * (and ^^^ { (a: Clause, b: Clause) => And(a, b) } | or ^^^ { (a: Clause, b: Clause) => Or(a, b) }) + def clause: Parser[Clause] = (_not | predicate | paren) * (and ^^^ { (a: Clause, b: Clause) => And(a, b) } | or ^^^ { (a: Clause, b: Clause) => Or(a, b) }) def identWithDot: Parser[String] = repsep(ident, ".") ^^ { case values => values.mkString(".") } + val _not = "not|NOT".r ~ (predicate | paren) ^^ { + case op ~ p => Not(p) + } + val _eq = identWithDot ~ ("!=" | "=") ~ stringLiteral ^^ { case f ~ op ~ s => if (op == "=") Eq(f, s) else Not(Eq(f, s)) } @@ -219,14 +223,10 @@ case class WhereParser() extends JavaTokenParsers { case f ~ minV ~ maxV => Between(f, minV, maxV) } - val _in = identWithDot ~ (notIn | in) ~ ("(" ~> repsep(stringLiteral, ",") <~ ")") ^^ { + val _in = identWithDot ~ (in) ~ ("(" ~> repsep(stringLiteral, ",") <~ ")") ^^ { case f ~ op ~ values => - val inClause = - if (f.startsWith("_parent")) IN(f, values.toSet) - else InWithoutParent(f, values.toSet) - - if (op.toLowerCase == "in") inClause - else Not(inClause) + if (f.startsWith("_parent")) IN(f, values.toSet) + else InWithoutParent(f, values.toSet) } val _contains = identWithDot ~ contains ~ stringLiteral ^^ { http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f288680c/s2core/src/test/scala/org/apache/s2graph/core/parsers/WhereParserTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/org/apache/s2graph/core/parsers/WhereParserTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/parsers/WhereParserTest.scala index 342d9c6..0ff4db1 100644 --- a/s2core/src/test/scala/org/apache/s2graph/core/parsers/WhereParserTest.scala +++ b/s2core/src/test/scala/org/apache/s2graph/core/parsers/WhereParserTest.scala @@ -46,6 +46,7 @@ class WhereParserTest extends FunSuite with Matchers with TestCommonWithModels { } val whereOpt = WhereParser().parse(sql) + if (whereOpt.isFailure) { debug(whereOpt) whereOpt.get // touch exception @@ -138,6 +139,7 @@ class WhereParserTest extends FunSuite with Matchers with TestCommonWithModels { f("time > 2")(true) f("time <= 3")(true) f("time < 2")(false) + f("NOT time >= 3")(false) f("(time in (1, 2, 3) and is_blocked = true) or is_hidden = false")(false) f("(time in (1, 2, 3) or is_blocked = true) or is_hidden = false")(true) @@ -169,6 +171,8 @@ class WhereParserTest extends FunSuite with Matchers with TestCommonWithModels { f(s"_from = ${tgtVertex.innerId.value} and _to = 102934")(false) f(s"_from = -1")(false) f(s"_from in (-1, -0.1)")(false) + f(s"NOT (_from = -1)")(true) + f(s"NOT _from contains 'a'")(true) } }
