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
47594923
Commit
47594923
authored
Feb 03, 2015
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified toStrings, fix issues exposed with fieldValidator in play
parent
d7c74678
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
20 deletions
+33
-20
Expressions.scala
.../scala/org/apache/hadoop/metadata/query/Expressions.scala
+1
-0
GremlinQuery.scala
...scala/org/apache/hadoop/metadata/query/GremlinQuery.scala
+4
-1
Resolver.scala
...ain/scala/org/apache/hadoop/metadata/query/Resolver.scala
+6
-4
TypeUtils.scala
...in/scala/org/apache/hadoop/metadata/query/TypeUtils.scala
+7
-0
ExpressionTest.scala
...ala/org/apache/hadoop/metadata/query/ExpressionTest.scala
+15
-15
GremlinTest.scala
.../scala/org/apache/hadoop/metadata/query/GremlinTest.scala
+0
-0
No files found.
typesystem/src/main/scala/org/apache/hadoop/metadata/query/Expressions.scala
View file @
47594923
...
...
@@ -249,6 +249,7 @@ object Expressions {
case
e
:
Expression
if
e.toString
contains
"
\n
"
=>
s
"(${e.simpleString})"
::
Nil
case
seq
:
Seq
[
_
]
=>
seq
.
mkString
(
"["
,
","
,
"]"
)
::
Nil
case
set
:
Set
[
_
]
=>
set
.
mkString
(
"{"
,
","
,
"}"
)
::
Nil
case
f
:
IDataType
[
_
]
=>
f
.
getName
::
Nil
case
other
=>
other
::
Nil
}.
mkString
(
", "
)
...
...
typesystem/src/main/scala/org/apache/hadoop/metadata/query/GremlinQuery.scala
View file @
47594923
...
...
@@ -53,7 +53,10 @@ trait SelectExpressionHandling {
}
def
apply
(
e
:
Expression
)
=
e
match
{
case
SelectExpression
(
_:
AliasExpression
,
_
)
=>
e
case
SelectExpression
(
aliasE
@AliasExpression
(
_
,
_
),
selList
)
=>
{
idx
=
idx
+
1
SelectExpression
(
aliasE
,
selList
.
map
(
_
.
transformUp
(
new
DecorateFieldWithAlias
(
aliasE
))))
}
case
SelectExpression
(
child
,
selList
)
=>
{
idx
=
idx
+
1
val
aliasE
=
AliasExpression
(
child
,
s
"_src$idx"
)
...
...
typesystem/src/main/scala/org/apache/hadoop/metadata/query/Resolver.scala
View file @
47594923
...
...
@@ -85,18 +85,20 @@ object FieldValidator extends PartialFunction[Expression, Expression] {
def
isDefinedAt
(
x
:
Expression
)
=
true
def
isSrc
(
e
:
Expression
)
=
e
.
isInstanceOf
[
ClassExpression
]
||
e
.
isInstanceOf
[
TraitExpression
]
def
validateQualifiedField
(
srcDataType
:
IDataType
[
_
])
:
PartialFunction
[
Expression
,
Expression
]
=
{
case
FieldExpression
(
fNm
,
fInfo
,
Some
(
child
))
if
child
.
children
==
Nil
&&
child
.
dataType
==
srcDataType
=>
case
FieldExpression
(
fNm
,
fInfo
,
Some
(
child
))
if
(
child
.
children
==
Nil
&&
child
.
dataType
==
srcDataType
)
=>
FieldExpression
(
fNm
,
fInfo
,
None
)
case
fe
@FieldExpression
(
fNm
,
fInfo
,
Some
(
child
))
if
child
.
children
==
Nil
=>
case
fe
@FieldExpression
(
fNm
,
fInfo
,
Some
(
child
))
if
isSrc
(
child
)
=>
throw
new
ExpressionException
(
fe
,
s
"srcType of field doesn't match input type"
)
case
hasFieldUnaryExpression
(
fNm
,
child
)
if
child
.
dataType
==
srcDataType
=>
hasFieldLeafExpression
(
fNm
)
case
hF
@hasFieldUnaryExpression
(
fNm
,
child
)
=>
case
hF
@hasFieldUnaryExpression
(
fNm
,
child
)
if
isSrc
(
child
)
=>
throw
new
ExpressionException
(
hF
,
s
"srcType of field doesn't match input type"
)
case
isTraitUnaryExpression
(
fNm
,
child
)
if
child
.
dataType
==
srcDataType
=>
isTraitLeafExpression
(
fNm
)
case
iT
@isTraitUnaryExpression
(
fNm
,
child
)
=>
case
iT
@isTraitUnaryExpression
(
fNm
,
child
)
if
isSrc
(
child
)
=>
throw
new
ExpressionException
(
iT
,
s
"srcType of field doesn't match input type"
)
}
...
...
typesystem/src/main/scala/org/apache/hadoop/metadata/query/TypeUtils.scala
View file @
47594923
...
...
@@ -79,6 +79,13 @@ object TypeUtils {
import
scala.language.existentials
case
class
FieldInfo
(
dataType
:
IDataType
[
_
],
attrInfo
:
AttributeInfo
,
reverseDataType
:
IDataType
[
_
]
=
null
)
{
def
isReverse
=
reverseDataType
!=
null
override
def
toString
:
String
=
{
if
(
reverseDataType
==
null
)
{
s
"""FieldInfo("${dataType.getName}", "${attrInfo.name}")"""
}
else
{
s
"""FieldInfo("${dataType.getName}", "${attrInfo.name}", "${reverseDataType.getName}")"""
}
}
}
/**
...
...
typesystem/src/test/scala/org/apache/hadoop/metadata/query/ExpressionTest.scala
View file @
47594923
...
...
@@ -109,7 +109,7 @@ class ExpressionTest extends BaseTest {
@Test
def
testBackReference
:
Unit
=
{
val
e
=
QueryProcessor
.
validate
(
_class
(
"DB"
).
as
(
"db
"
).
field
(
"Table"
).
where
(
id
(
"db
"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
))))
_class
(
"DB"
).
as
(
"db
1"
).
field
(
"Table"
).
where
(
id
(
"db1
"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
))))
println
(
e
)
}
...
...
@@ -127,8 +127,8 @@ class ExpressionTest extends BaseTest {
@Test
def
testJoinAndSelect1
:
Unit
=
{
val
e
=
QueryProcessor
.
validate
(
_class
(
"DB"
).
as
(
"db
"
).
field
(
"Table"
).
as
(
"tab"
).
where
((
id
(
"db
"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
))
.
and
(
id
(
"db
"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
)))).
select
(
id
(
"db
"
).
field
(
"name"
).
as
(
"dbName"
),
_class
(
"DB"
).
as
(
"db
1"
).
field
(
"Table"
).
as
(
"tab"
).
where
((
id
(
"db1
"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
))
.
and
(
id
(
"db
1"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
)))).
select
(
id
(
"db1
"
).
field
(
"name"
).
as
(
"dbName"
),
id
(
"tab"
).
field
(
"name"
).
as
(
"tabName"
))
)
println
(
e
)
...
...
@@ -136,31 +136,31 @@ class ExpressionTest extends BaseTest {
@Test
def
testJoinAndSelect2
:
Unit
=
{
val
e
=
QueryProcessor
.
validate
(
_class
(
"DB"
).
as
(
"db
"
).
field
(
"Table"
).
as
(
"tab"
).
where
((
id
(
"db
"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
))
.
or
(
id
(
"db"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
))))
.
select
(
id
(
"db"
).
field
(
"name"
).
as
(
"dbName"
),
id
(
"tab"
).
field
(
"name"
).
as
(
"tabName"
))
_class
(
"DB"
).
as
(
"db
1"
).
field
(
"Table"
).
as
(
"tab"
).
where
((
id
(
"db1
"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
))
.
or
(
id
(
"db
1
"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
))))
.
select
(
id
(
"db
1
"
).
field
(
"name"
).
as
(
"dbName"
),
id
(
"tab"
).
field
(
"name"
).
as
(
"tabName"
))
)
println
(
e
)
}
@Test
def
testJoinAndSelect3
:
Unit
=
{
val
e
=
QueryProcessor
.
validate
(
_class
(
"DB"
).
as
(
"db
"
).
field
(
"Table"
).
as
(
"tab"
).
where
((
id
(
"db
"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
))
.
and
(
id
(
"db"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
)))
.
or
(
id
(
"db"
).
hasField
(
"owner"
)))
.
select
(
id
(
"db"
).
field
(
"name"
).
as
(
"dbName"
),
id
(
"tab"
).
field
(
"name"
).
as
(
"tabName"
))
_class
(
"DB"
).
as
(
"db
1"
).
field
(
"Table"
).
as
(
"tab"
).
where
((
id
(
"db1
"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
))
.
and
(
id
(
"db
1
"
).
field
(
"name"
).
`=`
(
string
(
"Reporting"
)))
.
or
(
id
(
"db
1
"
).
hasField
(
"owner"
)))
.
select
(
id
(
"db
1
"
).
field
(
"name"
).
as
(
"dbName"
),
id
(
"tab"
).
field
(
"name"
).
as
(
"tabName"
))
)
println
(
e
)
}
@Test
def
testJoinAndSelect4
:
Unit
=
{
val
e
=
QueryProcessor
.
validate
(
_class
(
"DB"
)
as
"db"
join
"Table"
as
"tab"
where
(
id
(
"db"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
)
and
(
id
(
"db"
)
`.`
"name"
`=`
string
(
"Reporting"
)
)
or
(
id
(
"db"
)
hasField
"owner"
)
_class
(
"DB"
)
as
"db
1
"
join
"Table"
as
"tab"
where
(
id
(
"db
1
"
).
field
(
"createTime"
)
+
int
(
1
)
>
int
(
0
)
and
(
id
(
"db
1
"
)
`.`
"name"
`=`
string
(
"Reporting"
)
)
or
(
id
(
"db
1
"
)
hasField
"owner"
)
)
select
(
id
(
"db"
)
`.`
"name"
as
"dbName"
,
id
(
"tab"
)
`.`
"name"
as
"tabName"
id
(
"db
1
"
)
`.`
"name"
as
"dbName"
,
id
(
"tab"
)
`.`
"name"
as
"tabName"
)
)
println
(
e
)
...
...
typesystem/src/test/scala/org/apache/hadoop/metadata/query/GremlinTest.scala
View file @
47594923
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