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
0cf62fd8
Commit
0cf62fd8
authored
Oct 23, 2018
by
apoorvnaik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2520: Introduce JanusGraphTraversal to deprecate use of GremlinScriptEngine
parent
92775315
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
410 additions
and
17 deletions
+410
-17
pom.xml
graphdb/api/pom.xml
+5
-0
AtlasGraph.java
.../java/org/apache/atlas/repository/graphdb/AtlasGraph.java
+14
-7
AtlasGraphTraversal.java
.../apache/atlas/repository/graphdb/AtlasGraphTraversal.java
+91
-0
AtlasGraphTraversalSource.java
...e/atlas/repository/graphdb/AtlasGraphTraversalSource.java
+40
-0
AtlasJanusGraph.java
...pache/atlas/repository/graphdb/janus/AtlasJanusGraph.java
+19
-0
AtlasJanusGraphTraversal.java
...as/repository/graphdb/janus/AtlasJanusGraphTraversal.java
+232
-0
GremlinQuery.java
...ry/src/main/java/org/apache/atlas/query/GremlinQuery.java
+9
-10
No files found.
graphdb/api/pom.xml
View file @
0cf62fd8
...
@@ -46,6 +46,11 @@
...
@@ -46,6 +46,11 @@
<groupId>
org.codehaus.jettison
</groupId>
<groupId>
org.codehaus.jettison
</groupId>
<artifactId>
jettison
</artifactId>
<artifactId>
jettison
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.tinkerpop
</groupId>
<artifactId>
gremlin-core
</artifactId>
<version>
3.3.3
</version>
</dependency>
</dependencies>
</dependencies>
...
...
graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java
View file @
0cf62fd8
...
@@ -17,18 +17,17 @@
...
@@ -17,18 +17,17 @@
*/
*/
package
org
.
apache
.
atlas
.
repository
.
graphdb
;
package
org
.
apache
.
atlas
.
repository
.
graphdb
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.groovy.GroovyExpression
;
import
org.apache.atlas.type.AtlasType
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.groovy.GroovyExpression
;
import
org.apache.atlas.type.AtlasType
;
/**
/**
* Represents a graph.
* Represents a graph.
*
*
...
@@ -144,6 +143,14 @@ public interface AtlasGraph<V, E> {
...
@@ -144,6 +143,14 @@ public interface AtlasGraph<V, E> {
AtlasGraphQuery
<
V
,
E
>
query
();
AtlasGraphQuery
<
V
,
E
>
query
();
/**
/**
* Start a graph traversal
* @return
*/
AtlasGraphTraversal
<
AtlasVertex
,
AtlasEdge
>
V
(
Object
...
vertexIds
);
AtlasGraphTraversal
<
AtlasVertex
,
AtlasEdge
>
E
(
Object
...
edgeIds
);
/**
* Creates an index query.
* Creates an index query.
*
*
* @param indexName index name
* @param indexName index name
...
...
graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphTraversal.java
0 → 100644
View file @
0cf62fd8
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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
.
atlas
.
repository
.
graphdb
;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal
;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
;
import
org.apache.tinkerpop.gremlin.structure.Graph
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.BiPredicate
;
public
abstract
class
AtlasGraphTraversal
<
V
extends
AtlasVertex
,
E
extends
AtlasEdge
>
extends
DefaultGraphTraversal
{
protected
AtlasGraph
atlasGraph
;
// For anonymous/inner traversal
public
AtlasGraphTraversal
()
{
}
public
AtlasGraphTraversal
(
final
AtlasGraph
atlasGraph
,
final
Graph
graph
)
{
super
(
graph
);
this
.
atlasGraph
=
atlasGraph
;
}
public
AtlasGraphTraversal
(
final
AtlasGraph
atlasGraph
,
final
GraphTraversalSource
traversalSource
)
{
super
(
traversalSource
);
this
.
atlasGraph
=
atlasGraph
;
}
public
abstract
AtlasGraphTraversal
startAnonymousTraversal
();
public
abstract
List
<
V
>
getAtlasVertexList
();
public
abstract
Set
<
V
>
getAtlasVertexSet
();
public
abstract
Map
<
String
,
Collection
<
V
>>
getAtlasVertexMap
();
public
abstract
List
<
E
>
getAtlasEdgeList
();
public
abstract
Set
<
E
>
getAtlasEdgeSet
();
public
abstract
Map
<
String
,
E
>
getAtlasEdgeMap
();
public
abstract
TextPredicate
textPredicate
();
public
interface
TextPredicate
{
/**
* Whether the text contains a given term as a token in the text (case insensitive)
*/
BiPredicate
contains
();
/**
* Whether the text contains a token that starts with a given term (case insensitive)
*/
BiPredicate
containsPrefix
();
/**
* Whether the text contains a token that matches a regular expression
*/
BiPredicate
containsRegex
();
/**
* Whether the text starts with a given prefix (case sensitive)
*/
BiPredicate
prefix
();
/**
* Whether the text matches a regular expression (case sensitive)
*/
BiPredicate
regex
();
}
}
graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphTraversalSource.java
0 → 100644
View file @
0cf62fd8
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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
.
atlas
.
repository
.
graphdb
;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
;
import
org.apache.tinkerpop.gremlin.structure.Graph
;
import
org.apache.tinkerpop.gremlin.structure.Transaction
;
public
interface
AtlasGraphTraversalSource
<
V
extends
AtlasVertex
,
E
extends
AtlasEdge
>
{
// Concrete implementations need to have graph and graphTraversal source
Graph
getGraph
();
GraphTraversalSource
getGraphTraversalSource
();
AtlasGraphTraversal
<
V
,
E
>
startAnonymousTraversal
();
AtlasGraphTraversal
<
V
,
E
>
V
(
final
Object
...
vertexIds
);
AtlasGraphTraversal
<
V
,
E
>
E
(
final
Object
...
edgesIds
);
Transaction
tx
();
void
close
()
throws
Exception
;
}
graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraph.java
View file @
0cf62fd8
...
@@ -29,6 +29,7 @@ import org.apache.atlas.repository.graphdb.AtlasEdge;
...
@@ -29,6 +29,7 @@ import org.apache.atlas.repository.graphdb.AtlasEdge;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraphManagement
;
import
org.apache.atlas.repository.graphdb.AtlasGraphManagement
;
import
org.apache.atlas.repository.graphdb.AtlasGraphQuery
;
import
org.apache.atlas.repository.graphdb.AtlasGraphQuery
;
import
org.apache.atlas.repository.graphdb.AtlasGraphTraversal
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery
;
import
org.apache.atlas.repository.graphdb.AtlasSchemaViolationException
;
import
org.apache.atlas.repository.graphdb.AtlasSchemaViolationException
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
...
@@ -40,7 +41,9 @@ import org.apache.commons.configuration.Configuration;
...
@@ -40,7 +41,9 @@ import org.apache.commons.configuration.Configuration;
import
org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine
;
import
org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine
;
import
org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer
;
import
org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer
;
import
org.apache.tinkerpop.gremlin.process.traversal.P
;
import
org.apache.tinkerpop.gremlin.process.traversal.P
;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal
;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
;
import
org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep
;
import
org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath
;
import
org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath
;
import
org.apache.tinkerpop.gremlin.structure.Edge
;
import
org.apache.tinkerpop.gremlin.structure.Edge
;
import
org.apache.tinkerpop.gremlin.structure.Element
;
import
org.apache.tinkerpop.gremlin.structure.Element
;
...
@@ -127,6 +130,22 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
...
@@ -127,6 +130,22 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
}
}
@Override
@Override
public
AtlasGraphTraversal
<
AtlasVertex
,
AtlasEdge
>
V
(
final
Object
...
vertexIds
)
{
AtlasGraphTraversal
traversal
=
new
AtlasJanusGraphTraversal
(
this
,
getGraph
().
traversal
());
traversal
.
getBytecode
().
addStep
(
GraphTraversal
.
Symbols
.
V
,
vertexIds
);
traversal
.
addStep
(
new
GraphStep
<>(
traversal
,
Vertex
.
class
,
true
,
vertexIds
));
return
traversal
;
}
@Override
public
AtlasGraphTraversal
<
AtlasVertex
,
AtlasEdge
>
E
(
final
Object
...
edgeIds
)
{
AtlasGraphTraversal
traversal
=
new
AtlasJanusGraphTraversal
(
this
,
getGraph
().
traversal
());
traversal
.
getBytecode
().
addStep
(
GraphTraversal
.
Symbols
.
E
,
edgeIds
);
traversal
.
addStep
(
new
GraphStep
<>(
traversal
,
Vertex
.
class
,
true
,
edgeIds
));
return
traversal
;
}
@Override
public
AtlasEdge
<
AtlasJanusVertex
,
AtlasJanusEdge
>
getEdge
(
String
edgeId
)
{
public
AtlasEdge
<
AtlasJanusVertex
,
AtlasJanusEdge
>
getEdge
(
String
edgeId
)
{
Iterator
<
Edge
>
it
=
getGraph
().
edges
(
edgeId
);
Iterator
<
Edge
>
it
=
getGraph
().
edges
(
edgeId
);
Edge
e
=
getSingleElement
(
it
,
edgeId
);
Edge
e
=
getSingleElement
(
it
,
edgeId
);
...
...
graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphTraversal.java
0 → 100644
View file @
0cf62fd8
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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
.
atlas
.
repository
.
graphdb
.
janus
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraphTraversal
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
;
import
org.apache.tinkerpop.gremlin.structure.Edge
;
import
org.apache.tinkerpop.gremlin.structure.Graph
;
import
org.apache.tinkerpop.gremlin.structure.Vertex
;
import
org.janusgraph.core.attribute.Text
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.BiPredicate
;
public
class
AtlasJanusGraphTraversal
extends
AtlasGraphTraversal
<
AtlasJanusVertex
,
AtlasJanusEdge
>
{
private
List
resultList
;
private
Set
resultSet
;
public
AtlasJanusGraphTraversal
()
{
}
public
AtlasJanusGraphTraversal
(
final
AtlasGraph
<
AtlasJanusVertex
,
AtlasJanusEdge
>
atlasGraph
,
final
GraphTraversalSource
traversalSource
)
{
super
(
atlasGraph
,
traversalSource
);
}
public
AtlasJanusGraphTraversal
(
final
AtlasGraph
atlasGraph
,
final
Graph
graph
)
{
super
(
atlasGraph
,
graph
);
}
@Override
public
AtlasGraphTraversal
startAnonymousTraversal
()
{
return
new
AtlasJanusGraphTraversal
();
}
@Override
public
List
<
AtlasJanusVertex
>
getAtlasVertexList
()
{
List
list
=
getResultList
();
List
<
AtlasJanusVertex
>
ret
;
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
// toList called after groupBy will return a single map element list
if
(
list
.
size
()
==
1
&&
list
.
get
(
0
)
instanceof
Map
)
{
ret
=
Collections
.
emptyList
();
}
else
{
ret
=
new
ArrayList
<>(
list
.
size
());
for
(
Object
o
:
list
)
{
if
(
o
instanceof
Vertex
)
{
ret
.
add
(
GraphDbObjectFactory
.
createVertex
((
AtlasJanusGraph
)
atlasGraph
,
(
Vertex
)
o
));
}
}
}
}
else
{
ret
=
Collections
.
emptyList
();
}
return
ret
;
}
@Override
public
Set
<
AtlasJanusVertex
>
getAtlasVertexSet
()
{
Set
set
=
getResultSet
();
Set
<
AtlasJanusVertex
>
ret
;
if
(
CollectionUtils
.
isNotEmpty
(
set
))
{
ret
=
new
HashSet
<>(
set
.
size
());
for
(
Object
o
:
set
)
{
if
(
o
instanceof
Vertex
)
{
ret
.
add
(
GraphDbObjectFactory
.
createVertex
((
AtlasJanusGraph
)
atlasGraph
,
(
Vertex
)
o
));
}
}
}
else
{
ret
=
Collections
.
emptySet
();
}
return
ret
;
}
@Override
public
Map
<
String
,
Collection
<
AtlasJanusVertex
>>
getAtlasVertexMap
()
{
List
list
=
getResultList
();
Map
<
String
,
Collection
<
AtlasJanusVertex
>>
ret
;
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
ret
=
new
HashMap
<>(
list
.
size
());
if
(
list
.
size
()
==
1
&&
list
.
get
(
0
)
instanceof
Map
)
{
Map
aMap
=
(
Map
)
list
.
get
(
0
);
for
(
Object
key
:
aMap
.
keySet
())
{
if
(!(
key
instanceof
String
))
{
continue
;
}
Object
value
=
aMap
.
get
(
key
);
if
(
value
instanceof
List
)
{
Collection
<
AtlasJanusVertex
>
values
=
new
ArrayList
<>();
for
(
Object
o
:
(
List
)
value
)
{
if
(
o
instanceof
Vertex
)
{
values
.
add
(
GraphDbObjectFactory
.
createVertex
((
AtlasJanusGraph
)
atlasGraph
,
(
Vertex
)
o
));
}
}
ret
.
put
((
String
)
key
,
values
);
}
}
}
}
else
{
ret
=
Collections
.
emptyMap
();
}
return
ret
;
}
@Override
public
List
<
AtlasJanusEdge
>
getAtlasEdgeList
()
{
List
list
=
getResultList
();
List
<
AtlasJanusEdge
>
ret
;
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
if
(
list
.
size
()
==
1
&&
list
.
get
(
0
)
instanceof
Map
)
{
ret
=
Collections
.
emptyList
();
}
else
{
ret
=
new
ArrayList
<>(
list
.
size
());
for
(
Object
o
:
list
)
{
if
(
o
instanceof
Edge
)
{
ret
.
add
(
GraphDbObjectFactory
.
createEdge
((
AtlasJanusGraph
)
atlasGraph
,
(
Edge
)
o
));
}
}
}
}
else
{
ret
=
Collections
.
emptyList
();
}
return
ret
;
}
@Override
public
Set
<
AtlasJanusEdge
>
getAtlasEdgeSet
()
{
Set
set
=
getResultSet
();
Set
<
AtlasJanusEdge
>
ret
;
if
(
CollectionUtils
.
isNotEmpty
(
set
))
{
ret
=
new
HashSet
<>(
set
.
size
());
for
(
Object
o
:
set
)
{
if
(
o
instanceof
Edge
)
{
ret
.
add
(
GraphDbObjectFactory
.
createEdge
((
AtlasJanusGraph
)
atlasGraph
,
(
Edge
)
o
));
}
}
}
else
{
ret
=
Collections
.
emptySet
();
}
return
ret
;
}
@Override
public
Map
<
String
,
AtlasJanusEdge
>
getAtlasEdgeMap
()
{
return
null
;
}
@Override
public
TextPredicate
textPredicate
()
{
return
new
JanusGraphPredicate
();
}
public
static
class
JanusGraphPredicate
implements
TextPredicate
{
@Override
public
BiPredicate
<
Object
,
Object
>
contains
()
{
return
Text
.
CONTAINS
;
}
@Override
public
BiPredicate
<
Object
,
Object
>
containsPrefix
()
{
return
Text
.
CONTAINS_PREFIX
;
}
@Override
public
BiPredicate
<
Object
,
Object
>
containsRegex
()
{
return
Text
.
CONTAINS_REGEX
;
}
@Override
public
BiPredicate
<
Object
,
Object
>
prefix
()
{
return
Text
.
PREFIX
;
}
@Override
public
BiPredicate
<
Object
,
Object
>
regex
()
{
return
Text
.
REGEX
;
}
}
private
List
getResultList
()
{
if
(
resultList
==
null
)
{
resultList
=
toList
();
}
return
resultList
;
}
private
Set
getResultSet
()
{
if
(
resultSet
==
null
)
{
resultSet
=
toSet
();
}
return
resultSet
;
}
}
repository/src/main/java/org/apache/atlas/query/GremlinQuery.java
View file @
0cf62fd8
...
@@ -6,9 +6,9 @@
...
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* with the License. You may obtain a copy of the License at
*
<p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
http://www.apache.org/licenses/LICENSE-2.0
*
<p>
*
* Unless required by applicable law or agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
package
org
.
apache
.
atlas
.
query
;
package
org
.
apache
.
atlas
.
query
;
public
class
GremlinQuery
{
public
class
GremlinQuery
{
private
final
String
queryStr
;
private
final
String
queryStr
;
private
final
boolean
hasSelect
;
private
final
boolean
hasSelect
;
...
@@ -27,12 +26,11 @@ public class GremlinQuery {
...
@@ -27,12 +26,11 @@ public class GremlinQuery {
this
.
hasSelect
=
hasSelect
;
this
.
hasSelect
=
hasSelect
;
}
}
public
boolean
hasSelectList
()
{
return
this
.
hasSelect
;
}
public
String
queryStr
()
{
public
String
queryStr
()
{
return
queryStr
;
return
queryStr
;
}
}
}
public
boolean
hasSelectList
()
{
return
hasSelect
;
}
}
\ No newline at end of file
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