Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
8900b0ae
Commit
8900b0ae
authored
9 years ago
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add withPlan clause to DSL
parent
9a4a353d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
8 deletions
+40
-8
QueryParser.scala
.../scala/org/apache/hadoop/metadata/query/QueryParser.scala
+16
-8
GremlinTest2.scala
...scala/org/apache/hadoop/metadata/query/GremlinTest2.scala
+10
-0
ParserTest.scala
...t/scala/org/apache/hadoop/metadata/query/ParserTest.scala
+14
-0
No files found.
repository/src/main/scala/org/apache/hadoop/metadata/query/QueryParser.scala
View file @
8900b0ae
...
...
@@ -61,13 +61,16 @@ trait QueryKeywords {
protected
val
HAS
=
Keyword
(
"has"
)
protected
val
AS
=
Keyword
(
"as"
)
protected
val
TIMES
=
Keyword
(
"times"
)
protected
val
WITHPATH
=
Keyword
(
"withPath"
)
}
trait
ExpressionUtils
{
def
loop
(
input
:
Expression
,
l
:
(
Expression
,
Option
[
Literal
[
Integer
]]))
=
l
match
{
case
(
c
,
None
)
=>
input
.
loop
(
c
)
case
(
c
,
t
)
=>
input
.
loop
(
c
,
t
.
get
)
def
loop
(
input
:
Expression
,
l
:
(
Expression
,
Option
[
Literal
[
Integer
]],
Option
[
String
]))
=
l
match
{
case
(
c
,
None
,
None
)
=>
input
.
loop
(
c
)
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
])])
=
{
...
...
@@ -115,13 +118,18 @@ class QueryParser extends StandardTokenParsers with QueryKeywords with Expressio
override
val
lexical
=
new
QueryLexer
(
queryreservedWords
,
querydelims
)
def
apply
(
input
:
String
)
:
Either
[
NoSuccess
,
Expression
]
=
{
phrase
(
query
)(
new
lexical
.
Scanner
(
input
))
match
{
phrase
(
query
WithPath
)(
new
lexical
.
Scanner
(
input
))
match
{
case
Success
(
r
,
x
)
=>
Right
(
r
)
case
f
@Failure
(
m
,
x
)
=>
Left
(
f
)
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
{
case
h
::
Nil
=>
h
case
h
::
t
=>
t
.
foldLeft
(
h
)(
merge
(
_
,
_
))
...
...
@@ -173,10 +181,10 @@ class QueryParser extends StandardTokenParsers with QueryKeywords with Expressio
identifier
def
loopExpression
:
Parser
[(
Expression
,
Option
[
Literal
[
Integer
]])]
=
LOOP
~
(
LPAREN
~>
query
<~
RPAREN
)
~
opt
(
intConstant
<~
TIMES
)
^^
{
case
l
~
e
~
None
=>
(
e
,
None
)
case
l
~
e
~
Some
(
i
)
=>
(
e
,
Some
(
int
(
i
))
)
def
loopExpression
:
Parser
[(
Expression
,
Option
[
Literal
[
Integer
]]
,
Option
[
String
]
)]
=
LOOP
~
(
LPAREN
~>
query
<~
RPAREN
)
~
opt
(
intConstant
<~
TIMES
)
~
opt
(
AS
~>
alias
)
^^
{
case
l
~
e
~
None
~
a
=>
(
e
,
None
,
a
)
case
l
~
e
~
Some
(
i
)
~
a
=>
(
e
,
Some
(
int
(
i
)),
a
)
}
def
selectClause
:
Parser
[
List
[(
Expression
,
Option
[
String
])]]
=
SELECT
~
rep1sep
(
selectExpression
,
COMMA
)
^^
{
...
...
This diff is collapsed.
Click to expand it.
repository/src/test/scala/org/apache/hadoop/metadata/query/GremlinTest2.scala
View file @
8900b0ae
...
...
@@ -77,4 +77,13 @@ class GremlinTest2 extends FunSuite with BeforeAndAfterAll with BaseGremlinTest
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
This diff is collapsed.
Click to expand it.
repository/src/test/scala/org/apache/hadoop/metadata/query/ParserTest.scala
View file @
8900b0ae
...
...
@@ -84,4 +84,18 @@ class ParserTest extends BaseTest {
val
x
=
p
(
"from blah"
)
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
)
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment