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
1d1531ef
Commit
1d1531ef
authored
Jan 19, 2015
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for raw search
parent
ea38da10
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
0 deletions
+89
-0
MetadataRepository.java
...apache/hadoop/metadata/repository/MetadataRepository.java
+11
-0
GraphBackedMetadataRepository.java
...adata/repository/graph/GraphBackedMetadataRepository.java
+54
-0
GraphBackedMetadataRepositoryTest.java
.../metadata/services/GraphBackedMetadataRepositoryTest.java
+24
-0
No files found.
repository/src/main/java/org/apache/hadoop/metadata/repository/MetadataRepository.java
View file @
1d1531ef
...
...
@@ -24,6 +24,7 @@ import org.apache.hadoop.metadata.service.Service;
import
org.apache.hadoop.metadata.storage.RepositoryException
;
import
java.util.List
;
import
java.util.Map
;
/**
* An interface for persisting metadata into a blueprints enabled graph db.
...
...
@@ -36,4 +37,14 @@ public interface MetadataRepository extends Service {
ITypedReferenceableInstance
getEntityDefinition
(
String
guid
)
throws
RepositoryException
;
List
<
String
>
getEntityList
(
String
entityType
)
throws
RepositoryException
;
/**
* Assumes the User is familar with the persistence structure of the Repository.
* The given query is run uninterpreted against the underlying Graph Store.
* The results are returned as a List of Rows. each row is a Map of Key,Value pairs.
* @param gremlinQuery
* @return
* @throws RepositoryException
*/
List
<
Map
<
String
,
String
>>
rawSearch
(
String
gremlinQuery
)
throws
RepositoryException
;
}
repository/src/main/java/org/apache/hadoop/metadata/repository/graph/GraphBackedMetadataRepository.java
View file @
1d1531ef
...
...
@@ -25,6 +25,7 @@ import com.tinkerpop.blueprints.Edge;
import
com.tinkerpop.blueprints.Graph
;
import
com.tinkerpop.blueprints.TransactionalGraph
;
import
com.tinkerpop.blueprints.Vertex
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.apache.hadoop.metadata.IReferenceableInstance
;
import
org.apache.hadoop.metadata.ITypedInstance
;
import
org.apache.hadoop.metadata.ITypedReferenceableInstance
;
...
...
@@ -47,6 +48,10 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
javax.inject.Inject
;
import
javax.script.Bindings
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptEngineManager
;
import
javax.script.ScriptException
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
...
...
@@ -153,6 +158,55 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
}
}
public
List
<
Map
<
String
,
String
>>
rawSearch
(
String
gremlinQuery
)
throws
RepositoryException
{
ScriptEngineManager
manager
=
new
ScriptEngineManager
();
ScriptEngine
engine
=
manager
.
getEngineByName
(
"gremlin-groovy"
);
Bindings
bindings
=
engine
.
createBindings
();
bindings
.
put
(
"g"
,
graphService
.
getTransactionalGraph
());
try
{
Object
o
=
engine
.
eval
(
gremlinQuery
,
bindings
);
if
(
!(
o
instanceof
List
))
{
throw
new
RepositoryException
(
String
.
format
(
"Cannot process gremlin result %s"
,
o
.
toString
()));
}
List
l
=
(
List
)
o
;
List
<
Map
<
String
,
String
>>
result
=
new
ArrayList
<>();
for
(
Object
r
:
l
)
{
Map
<
String
,
String
>
oRow
=
new
HashedMap
();
if
(
r
instanceof
Map
)
{
Map
<
Object
,
Object
>
iRow
=
(
Map
)
r
;
for
(
Map
.
Entry
e
:
iRow
.
entrySet
())
{
Object
k
=
e
.
getKey
();
Object
v
=
e
.
getValue
();
oRow
.
put
(
k
.
toString
(),
v
.
toString
());
}
}
else
if
(
r
instanceof
TitanVertex
)
{
Iterable
<
TitanProperty
>
ps
=
((
TitanVertex
)
r
).
getProperties
();
for
(
TitanProperty
tP
:
ps
)
{
String
pName
=
tP
.
getPropertyKey
().
getName
();
Object
pValue
=
((
TitanVertex
)
r
).
getProperty
(
pName
);
if
(
pValue
!=
null
)
{
oRow
.
put
(
pName
,
pValue
.
toString
());
}
}
}
else
if
(
r
instanceof
String
)
{
oRow
.
put
(
""
,
r
.
toString
());
}
else
{
throw
new
RepositoryException
(
String
.
format
(
"Cannot process gremlin result %s"
,
o
.
toString
()));
}
result
.
add
(
oRow
);
}
return
result
;
}
catch
(
ScriptException
se
)
{
throw
new
RepositoryException
(
se
);
}
}
@Override
public
List
<
String
>
getEntityList
(
String
entityType
)
throws
RepositoryException
{
LOG
.
info
(
"Retrieving entity list for type={}"
,
entityType
);
...
...
repository/src/test/java/org/apache/hadoop/metadata/services/GraphBackedMetadataRepositoryTest.java
View file @
1d1531ef
...
...
@@ -103,6 +103,30 @@ public class GraphBackedMetadataRepositoryTest extends RepositoryModuleBaseTest
Assert
.
assertEquals
(
entityList
.
size
(),
0
);
// as this is not implemented yet
}
@Test
(
enabled
=
false
)
public
void
testRawSearch1
()
throws
Exception
{
Referenceable
hrDept
=
createDeptEg1
(
ts
);
ClassType
deptType
=
ts
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
guid
=
repositoryService
.
createEntity
(
hrDept2
,
ENTITY_TYPE
);
// Query for all Vertices in Graph
Object
r
=
repositoryService
.
rawSearch
(
"g.V.toList()"
);
//System.out.println(r);
// Query for all Vertices of a Type
r
=
repositoryService
.
rawSearch
(
"g.V.filter{it.typeName == 'Department'}.toList()"
);
//System.out.println(r);
// Property Query: list all Person names
r
=
repositoryService
.
rawSearch
(
"g.V.filter{it.typeName == 'Person'}.'Person.name'.toList()"
);
//System.out.println(r);
}
/*
* Class Hierarchy is:
* Department(name : String, employees : Array[Person])
...
...
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