Commit 8900b0ae by Harish Butani

add withPlan clause to DSL

parent 9a4a353d
...@@ -61,13 +61,16 @@ trait QueryKeywords { ...@@ -61,13 +61,16 @@ trait QueryKeywords {
protected val HAS = Keyword("has") protected val HAS = Keyword("has")
protected val AS = Keyword("as") protected val AS = Keyword("as")
protected val TIMES = Keyword("times") protected val TIMES = Keyword("times")
protected val WITHPATH = Keyword("withPath")
} }
trait ExpressionUtils { trait ExpressionUtils {
def loop(input: Expression, l: (Expression, Option[Literal[Integer]])) = l match { def loop(input: Expression, l: (Expression, Option[Literal[Integer]], Option[String])) = l match {
case (c, None) => input.loop(c) case (c, None, None) => input.loop(c)
case (c, t) => input.loop(c, t.get) case (c, t, None) => input.loop(c, t.get)
case (c, None, Some(a)) => input.loop(c).as(a)
case (c, t, Some(a)) => input.loop(c, t.get).as(a)
} }
def select(input: Expression, s: List[(Expression, Option[String])]) = { def select(input: Expression, s: List[(Expression, Option[String])]) = {
...@@ -115,13 +118,18 @@ class QueryParser extends StandardTokenParsers with QueryKeywords with Expressio ...@@ -115,13 +118,18 @@ class QueryParser extends StandardTokenParsers with QueryKeywords with Expressio
override val lexical = new QueryLexer(queryreservedWords, querydelims) override val lexical = new QueryLexer(queryreservedWords, querydelims)
def apply(input: String): Either[NoSuccess, Expression] = { def apply(input: String): Either[NoSuccess, Expression] = {
phrase(query)(new lexical.Scanner(input)) match { phrase(queryWithPath)(new lexical.Scanner(input)) match {
case Success(r, x) => Right(r) case Success(r, x) => Right(r)
case f@Failure(m, x) => Left(f) case f@Failure(m, x) => Left(f)
case e@Error(m, x) => Left(e) case e@Error(m, x) => Left(e)
} }
} }
def queryWithPath = query ~ opt(WITHPATH) ^^ {
case q ~ None => q
case q ~ p => q.path()
}
def query: Parser[Expression] = rep1sep(singleQuery, opt(COMMA)) ^^ { l => l match { def query: Parser[Expression] = rep1sep(singleQuery, opt(COMMA)) ^^ { l => l match {
case h :: Nil => h case h :: Nil => h
case h :: t => t.foldLeft(h)(merge(_, _)) case h :: t => t.foldLeft(h)(merge(_, _))
...@@ -173,10 +181,10 @@ class QueryParser extends StandardTokenParsers with QueryKeywords with Expressio ...@@ -173,10 +181,10 @@ class QueryParser extends StandardTokenParsers with QueryKeywords with Expressio
identifier identifier
def loopExpression: Parser[(Expression, Option[Literal[Integer]])] = def loopExpression: Parser[(Expression, Option[Literal[Integer]], Option[String])] =
LOOP ~ (LPAREN ~> query <~ RPAREN) ~ opt(intConstant <~ TIMES) ^^ { LOOP ~ (LPAREN ~> query <~ RPAREN) ~ opt(intConstant <~ TIMES) ~ opt(AS ~> alias) ^^ {
case l ~ e ~ None => (e, None) case l ~ e ~ None ~ a => (e, None, a)
case l ~ e ~ Some(i) => (e, Some(int(i))) case l ~ e ~ Some(i) ~ a => (e, Some(int(i)), a)
} }
def selectClause: Parser[List[(Expression, Option[String])]] = SELECT ~ rep1sep(selectExpression, COMMA) ^^ { def selectClause: Parser[List[(Expression, Option[String])]] = SELECT ~ rep1sep(selectExpression, COMMA) ^^ {
......
...@@ -77,4 +77,13 @@ class GremlinTest2 extends FunSuite with BeforeAndAfterAll with BaseGremlinTest ...@@ -77,4 +77,13 @@ class GremlinTest2 extends FunSuite with BeforeAndAfterAll with BaseGremlinTest
validateJson(r) validateJson(r)
} }
test("testLineageAllSelectWithPathFromParser") {
val p = new QueryParser
val e = p("Table as src loop (LoadProcess outputTable) as dest " +
"select src.name as srcTable, dest.name as destTable withPath").right.get
//Table as src loop (LoadProcess where LoadProcess.outputTable) as dest select src.name as srcTable, dest.name as destTable withPath
val r = QueryProcessor.evaluate(e, g)
validateJson(r)
}
} }
\ No newline at end of file
...@@ -84,4 +84,18 @@ class ParserTest extends BaseTest { ...@@ -84,4 +84,18 @@ class ParserTest extends BaseTest {
val x = p("from blah") val x = p("from blah")
println(p("from blah").left) println(p("from blah").left)
} }
@Test def testPath1: Unit = {
val p = new QueryParser
println(p("Table loop (LoadProcess outputTable) withPath").right.get.toString)
}
@Test def testPath2: Unit = {
val p = new QueryParser
println(p(
"Table as src loop (LoadProcess outputTable) as dest " +
"select src.name as srcTable, dest.name as destTable withPath").right.get.toString
)
}
} }
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