use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.
the class GraphBackedMetadataRepository method getEntityList.
@Override
@GraphTransaction
public List<String> getEntityList(String entityType) throws RepositoryException {
if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving entity list for type={}", entityType);
}
AtlasGraphQuery query = getGraph().query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, entityType);
Iterator<AtlasVertex> results = query.vertices().iterator();
if (!results.hasNext()) {
return Collections.emptyList();
}
ArrayList<String> entityList = new ArrayList<>();
while (results.hasNext()) {
AtlasVertex vertex = results.next();
entityList.add(GraphHelper.getGuid(vertex));
}
return entityList;
}
use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.
the class GraphHelper method getVerticesForPropertyValues.
/**
* Finds the Vertices that correspond to the given property values. Property
* values that are not found in the graph will not be in the map.
*
* @return propertyValue to AtlasVertex map with the result.
*/
public Map<String, AtlasVertex> getVerticesForPropertyValues(String property, List<String> values) {
if (values.isEmpty()) {
return Collections.emptyMap();
}
Collection<String> nonNullValues = new HashSet<>(values.size());
for (String value : values) {
if (value != null) {
nonNullValues.add(value);
}
}
//create graph query that finds vertices with the guids
AtlasGraphQuery query = graph.query();
query.in(property, nonNullValues);
Iterable<AtlasVertex> results = query.vertices();
Map<String, AtlasVertex> result = new HashMap<>(values.size());
//each vertex should go in the result list.
for (AtlasVertex vertex : results) {
if (vertex.exists()) {
String propertyValue = vertex.getProperty(property, String.class);
if (LOG.isDebugEnabled()) {
LOG.debug("Found a vertex {} with {} = {}", string(vertex), property, propertyValue);
}
result.put(propertyValue, vertex);
}
}
return result;
}
use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.
the class GraphQueryTest method testQueryDoesNotMatchRemovedVertices.
@Test
public <V, E> void testQueryDoesNotMatchRemovedVertices() throws AtlasException {
AtlasGraph<V, E> graph = getGraph();
AtlasVertex<V, E> v1 = createVertex(graph);
v1.setProperty("name", "Fred");
v1.setProperty("size15", "15");
AtlasVertex<V, E> v2 = createVertex(graph);
v2.setProperty("name", "Fred");
AtlasVertex<V, E> v3 = createVertex(graph);
v3.setProperty("size15", "15");
AtlasVertex<V, E> v4 = createVertex(graph);
v4.setProperty("name", "Fred");
v4.setProperty("size15", "15");
graph.commit();
graph.removeVertex(v1);
AtlasGraphQuery q = getGraphQuery();
q.has("name", "Fred");
q.has("size15", "15");
assertQueryMatches(q, v4);
graph.commit();
assertQueryMatches(q, v4);
}
use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.
the class GraphQueryTest method testQueryMatchesAddedVertices.
@Test
public <V, E> void testQueryMatchesAddedVertices() throws AtlasException {
AtlasGraph<V, E> graph = getGraph();
AtlasVertex<V, E> v1 = createVertex(graph);
v1.setProperty("name", "Fred");
v1.setProperty("size15", "15");
AtlasVertex<V, E> v2 = createVertex(graph);
v2.setProperty("name", "Fred");
AtlasVertex<V, E> v3 = createVertex(graph);
v3.setProperty("size15", "15");
graph.commit();
AtlasVertex<V, E> v4 = createVertex(graph);
v4.setProperty("name", "Fred");
v4.setProperty("size15", "15");
AtlasGraphQuery q = getGraphQuery();
q.has("name", "Fred");
q.has("size15", "15");
assertQueryMatches(q, v1, v4);
graph.commit();
assertQueryMatches(q, v1, v4);
}
use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.
the class GraphQueryTest method testQueryDoesNotMatchUncommittedAddedAndRemovedVertices.
@Test
public <V, E> void testQueryDoesNotMatchUncommittedAddedAndRemovedVertices() throws AtlasException {
AtlasGraph<V, E> graph = getGraph();
AtlasVertex<V, E> v1 = createVertex(graph);
v1.setProperty("name", "Fred");
v1.setProperty("size15", "15");
AtlasVertex<V, E> v2 = createVertex(graph);
v2.setProperty("name", "Fred");
AtlasVertex<V, E> v3 = createVertex(graph);
v3.setProperty("size15", "15");
AtlasVertex<V, E> v4 = createVertex(graph);
v4.setProperty("name", "Fred");
v4.setProperty("size15", "15");
AtlasGraphQuery q = getGraphQuery();
q.has("name", "Fred");
q.has("size15", "15");
assertQueryMatches(q, v1, v4);
graph.removeVertex(v1);
assertQueryMatches(q, v4);
graph.commit();
assertQueryMatches(q, v4);
}
Aggregations