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
543f3a72
Commit
543f3a72
authored
Mar 14, 2015
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support navigation from an instance to a trait
parent
665165ed
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
102 additions
and
6 deletions
+102
-6
Expressions.scala
.../scala/org/apache/hadoop/metadata/query/Expressions.scala
+9
-1
GraphPersistenceStrategies.scala
...he/hadoop/metadata/query/GraphPersistenceStrategies.scala
+3
-2
GremlinQuery.scala
...scala/org/apache/hadoop/metadata/query/GremlinQuery.scala
+10
-0
Resolver.scala
...ain/scala/org/apache/hadoop/metadata/query/Resolver.scala
+4
-0
TypeUtils.scala
...in/scala/org/apache/hadoop/metadata/query/TypeUtils.scala
+8
-2
GremlinTest2.scala
...scala/org/apache/hadoop/metadata/query/GremlinTest2.scala
+63
-0
TypeSystem.java
...g/apache/hadoop/metadata/typesystem/types/TypeSystem.java
+5
-1
No files found.
repository/src/main/scala/org/apache/hadoop/metadata/query/Expressions.scala
View file @
543f3a72
...
@@ -406,7 +406,15 @@ object Expressions {
...
@@ -406,7 +406,15 @@ object Expressions {
val
children
=
if
(
child
.
isDefined
)
List
(
child
.
get
)
else
Nil
val
children
=
if
(
child
.
isDefined
)
List
(
child
.
get
)
else
Nil
lazy
val
dataType
=
{
lazy
val
dataType
=
{
val
t
=
if
(!
fieldInfo
.
isReverse
)
fieldInfo
.
attrInfo
.
dataType
()
else
fieldInfo
.
reverseDataType
val
t
=
{
if
(
fieldInfo
.
traitName
!=
null
)
{
typSystem
.
getDataType
(
classOf
[
TraitType
],
fieldInfo
.
traitName
)
}
else
if
(!
fieldInfo
.
isReverse
)
{
fieldInfo
.
attrInfo
.
dataType
()
}
else
{
fieldInfo
.
reverseDataType
}
}
elemType
(
t
)
elemType
(
t
)
}
}
override
lazy
val
resolved
:
Boolean
=
true
override
lazy
val
resolved
:
Boolean
=
true
...
...
repository/src/main/scala/org/apache/hadoop/metadata/query/GraphPersistenceStrategies.scala
View file @
543f3a72
...
@@ -67,8 +67,9 @@ trait GraphPersistenceStrategies {
...
@@ -67,8 +67,9 @@ trait GraphPersistenceStrategies {
def
traitNames
(
v
:
TitanVertex
)
:
java.util.List
[
String
]
def
traitNames
(
v
:
TitanVertex
)
:
java.util.List
[
String
]
def
edgeLabel
(
fInfo
:
FieldInfo
)
:
String
=
fInfo
match
{
def
edgeLabel
(
fInfo
:
FieldInfo
)
:
String
=
fInfo
match
{
case
FieldInfo
(
dataType
,
aInfo
,
null
)
=>
edgeLabel
(
dataType
,
aInfo
)
case
FieldInfo
(
dataType
,
aInfo
,
null
,
null
)
=>
edgeLabel
(
dataType
,
aInfo
)
case
FieldInfo
(
dataType
,
aInfo
,
reverseDataType
)
=>
edgeLabel
(
reverseDataType
,
aInfo
)
case
FieldInfo
(
dataType
,
aInfo
,
reverseDataType
,
null
)
=>
edgeLabel
(
reverseDataType
,
aInfo
)
case
FieldInfo
(
dataType
,
null
,
null
,
traitName
)
=>
traitLabel
(
dataType
,
traitName
)
}
}
def
fieldPrefixInSelect
:
String
def
fieldPrefixInSelect
:
String
...
...
repository/src/main/scala/org/apache/hadoop/metadata/query/GremlinQuery.scala
View file @
543f3a72
...
@@ -176,6 +176,16 @@ class GremlinTranslator(expr: Expression,
...
@@ -176,6 +176,16 @@ class GremlinTranslator(expr: Expression,
case
None
=>
step
case
None
=>
step
}
}
}
}
case
fe
@FieldExpression
(
fieldName
,
fInfo
,
child
)
if
fInfo
.
traitName
!=
null
=>
{
val
direction
=
"out"
val
edgeLbl
=
gPersistenceBehavior
.
edgeLabel
(
fInfo
)
val
step
=
s
"""$direction("$edgeLbl")"""
child
match
{
case
Some
(
e
)
=>
s
"${genQuery(e, inSelect)}.$step"
case
None
=>
step
}
}
case
c
@ComparisonExpression
(
symb
,
f
@FieldExpression
(
fieldName
,
fInfo
,
ch
),
l
)
=>
{
case
c
@ComparisonExpression
(
symb
,
f
@FieldExpression
(
fieldName
,
fInfo
,
ch
),
l
)
=>
{
ch
match
{
ch
match
{
case
Some
(
child
)
=>
case
Some
(
child
)
=>
...
...
repository/src/main/scala/org/apache/hadoop/metadata/query/Resolver.scala
View file @
543f3a72
...
@@ -65,6 +65,10 @@ class Resolver(srcExpr: Option[Expression] = None, aliases: Map[String, Expressi
...
@@ -65,6 +65,10 @@ class Resolver(srcExpr: Option[Expression] = None, aliases: Map[String, Expressi
if
(
fInfo
.
isDefined
)
{
if
(
fInfo
.
isDefined
)
{
return
new
FieldExpression
(
fieldName
,
fInfo
.
get
,
Some
(
child
))
return
new
FieldExpression
(
fieldName
,
fInfo
.
get
,
Some
(
child
))
}
}
val
tType
=
resolveAsTraitType
(
fieldName
)
if
(
tType
.
isDefined
)
{
return
new
FieldExpression
(
fieldName
,
FieldInfo
(
child
.
dataType
,
null
,
null
,
fieldName
),
Some
(
child
))
}
f
f
}
}
case
isTraitLeafExpression
(
traitName
,
classExpression
)
case
isTraitLeafExpression
(
traitName
,
classExpression
)
...
...
repository/src/main/scala/org/apache/hadoop/metadata/query/TypeUtils.scala
View file @
543f3a72
...
@@ -77,10 +77,16 @@ object TypeUtils {
...
@@ -77,10 +77,16 @@ object TypeUtils {
}
}
import
scala.language.existentials
import
scala.language.existentials
case
class
FieldInfo
(
dataType
:
IDataType
[
_
],
attrInfo
:
AttributeInfo
,
reverseDataType
:
IDataType
[
_
]
=
null
)
{
case
class
FieldInfo
(
dataType
:
IDataType
[
_
],
attrInfo
:
AttributeInfo
,
reverseDataType
:
IDataType
[
_
]
=
null
,
traitName
:
String
=
null
)
{
def
isReverse
=
reverseDataType
!=
null
def
isReverse
=
reverseDataType
!=
null
override
def
toString
:
String
=
{
override
def
toString
:
String
=
{
if
(
reverseDataType
==
null
)
{
if
(
traitName
!=
null
)
{
s
"""FieldInfo("${dataType.getName}", "$traitName")"""
}
else
if
(
reverseDataType
==
null
)
{
s
"""FieldInfo("${dataType.getName}", "${attrInfo.name}")"""
s
"""FieldInfo("${dataType.getName}", "${attrInfo.name}")"""
}
else
{
}
else
{
s
"""FieldInfo("${dataType.getName}", "${attrInfo.name}", "${reverseDataType.getName}")"""
s
"""FieldInfo("${dataType.getName}", "${attrInfo.name}", "${reverseDataType.getName}")"""
...
...
repository/src/test/scala/org/apache/hadoop/metadata/query/GremlinTest2.scala
0 → 100644
View file @
543f3a72
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.hadoop.metadata.query
import
com.thinkaurelius.titan.core.TitanGraph
import
org.apache.hadoop.metadata.query.Expressions._
import
org.apache.hadoop.metadata.typesystem.types.TypeSystem
import
org.junit.runner.RunWith
import
org.scalatest._
import
Matchers._
import
org.scalatest.junit.JUnitRunner
@RunWith
(
classOf
[
JUnitRunner
])
class
GremlinTest2
extends
FunSuite
with
BeforeAndAfterAll
{
var
g
:
TitanGraph
=
null
override
def
beforeAll
()
{
TypeSystem
.
getInstance
().
reset
()
QueryTestsUtils
.
setupTypes
g
=
QueryTestsUtils
.
setupTestGraph
}
override
def
afterAll
()
{
g
.
shutdown
()
}
val
STRUCT_NAME_REGEX
=
(
TypeUtils
.
TEMP_STRUCT_NAME_PREFIX
+
"\\d+"
).
r
def
validateJson
(
r
:
GremlinQueryResult
,
expected
:
String
=
null
)
:
Unit
=
{
val
rJ
=
r
.
toJson
if
(
expected
!=
null
)
{
val
a
=
STRUCT_NAME_REGEX
.
replaceAllIn
(
rJ
,
""
)
val
b
=
STRUCT_NAME_REGEX
.
replaceAllIn
(
expected
,
""
)
Assertions
.
assert
(
a
==
b
)
}
else
{
println
(
rJ
)
}
}
test
(
"testTraitSelect"
)
{
val
r
=
QueryProcessor
.
evaluate
(
_class
(
"Table"
).
as
(
"t"
).
join
(
"Dimension"
).
as
(
"dim"
).
select
(
id
(
"t"
),
id
(
"dim"
)),
g
)
validateJson
(
r
,
"{\n \"query\":\"Table as t.Dimension as dim select t as _col_0, dim as _col_1\",\n \"dataType\":{\n \"typeName\":\"\",\n \"attributeDefinitions\":[\n {\n \"name\":\"_col_0\",\n \"dataTypeName\":\"Table\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":true,\n \"reverseAttributeName\":null\n },\n {\n \"name\":\"_col_1\",\n \"dataTypeName\":\"Dimension\",\n \"multiplicity\":{\n \"lower\":0,\n \"upper\":1,\n \"isUnique\":false\n },\n \"isComposite\":false,\n \"isUnique\":false,\n \"isIndexable\":true,\n \"reverseAttributeName\":null\n }\n ]\n },\n \"rows\":[\n {\n \"$typeName$\":\"\",\n \"_col_1\":{\n \"$typeName$\":\"Dimension\"\n },\n \"_col_0\":{\n \"id\":\"3328\",\n \"$typeName$\":\"Table\",\n \"version\":0\n }\n },\n {\n \"$typeName$\":\"\",\n \"_col_1\":{\n \"$typeName$\":\"Dimension\"\n },\n \"_col_0\":{\n \"id\":\"4864\",\n \"$typeName$\":\"Table\",\n \"version\":0\n }\n },\n {\n \"$typeName$\":\"\",\n \"_col_1\":{\n \"$typeName$\":\"Dimension\"\n },\n \"_col_0\":{\n \"id\":\"6656\",\n \"$typeName$\":\"Table\",\n \"version\":0\n }\n }\n ]\n}"
)
}
}
\ No newline at end of file
typesystem/src/main/java/org/apache/hadoop/metadata/typesystem/types/TypeSystem.java
View file @
543f3a72
...
@@ -87,7 +87,11 @@ public class TypeSystem {
...
@@ -87,7 +87,11 @@ public class TypeSystem {
public
<
T
>
T
getDataType
(
Class
<
T
>
cls
,
String
name
)
throws
MetadataException
{
public
<
T
>
T
getDataType
(
Class
<
T
>
cls
,
String
name
)
throws
MetadataException
{
if
(
types
.
containsKey
(
name
))
{
if
(
types
.
containsKey
(
name
))
{
return
cls
.
cast
(
types
.
get
(
name
));
try
{
return
cls
.
cast
(
types
.
get
(
name
));
}
catch
(
ClassCastException
cce
)
{
throw
new
MetadataException
(
cce
);
}
}
}
/*
/*
...
...
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