Search in sources :

Example 1 with AtlasGraphQuery

use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.

the class AtlasGraphUtilsV1 method typeHasInstanceVertex.

public static boolean typeHasInstanceVertex(String typeName) throws AtlasBaseException {
    AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance().query().has(Constants.TYPE_NAME_PROPERTY_KEY, AtlasGraphQuery.ComparisionOperator.EQUAL, typeName);
    Iterator<AtlasVertex> results = query.vertices().iterator();
    boolean hasInstanceVertex = results != null && results.hasNext();
    if (LOG.isDebugEnabled()) {
        LOG.debug("typeName {} has instance vertex {}", typeName, hasInstanceVertex);
    }
    return hasInstanceVertex;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery)

Example 2 with AtlasGraphQuery

use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.

the class GraphQueryTest method testSimpleOrQuery.

@Test
public void testSimpleOrQuery() throws AtlasException {
    Titan0Graph graph = getTitan0Graph();
    AtlasVertex<Titan0Vertex, Titan0Edge> v1 = createVertex(graph);
    v1.setProperty("name", "Fred");
    v1.setProperty("size15", "15");
    AtlasVertex<Titan0Vertex, Titan0Edge> v2 = createVertex(graph);
    v2.setProperty("name", "Fred");
    AtlasVertex<Titan0Vertex, Titan0Edge> v3 = createVertex(graph);
    v3.setProperty("size15", "15");
    graph.commit();
    AtlasVertex<Titan0Vertex, Titan0Edge> v4 = createVertex(graph);
    v4.setProperty("name", "Fred");
    v4.setProperty("size15", "15");
    AtlasVertex<Titan0Vertex, Titan0Edge> v5 = createVertex(graph);
    v5.setProperty("name", "George");
    v5.setProperty("size15", "16");
    AtlasGraphQuery q = graph.query();
    AtlasGraphQuery inner1 = q.createChildQuery().has("name", "Fred");
    AtlasGraphQuery inner2 = q.createChildQuery().has("size15", "15");
    q.or(toList(inner1, inner2));
    assertQueryMatches(q, v1, v2, v3, v4);
    graph.commit();
    //pause to let the indexer get updated (this fails frequently without a pause)
    pause();
    assertQueryMatches(q, v1, v2, v3, v4);
}
Also used : AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) Test(org.testng.annotations.Test)

Example 3 with AtlasGraphQuery

use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.

the class GraphQueryTest method testCombinationOfAndsAndOrs.

@Test
public void testCombinationOfAndsAndOrs() throws AtlasException {
    Titan0Graph graph = getTitan0Graph();
    AtlasVertex<Titan0Vertex, Titan0Edge> v1 = createVertex(graph);
    v1.setProperty("name", "Fred");
    v1.setProperty("size15", "15");
    v1.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v2 = createVertex(graph);
    v2.setProperty("name", "George");
    v2.setProperty("size15", "16");
    v2.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v3 = createVertex(graph);
    v3.setProperty("name", "Jane");
    v3.setProperty("size15", "17");
    v3.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v4 = createVertex(graph);
    v4.setProperty("name", "Bob");
    v4.setProperty("size15", "18");
    v4.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v5 = createVertex(graph);
    v5.setProperty("name", "Julia");
    v5.setProperty("size15", "19");
    v5.setProperty("typeName", "Manager");
    AtlasGraphQuery q = getGraphQuery();
    q.has("typeName", "Person");
    //initially match
    AtlasGraphQuery inner1a = q.createChildQuery();
    AtlasGraphQuery inner1b = q.createChildQuery();
    inner1a.has("name", "Fred");
    inner1b.has("name", "Jane");
    q.or(toList(inner1a, inner1b));
    AtlasGraphQuery inner2a = q.createChildQuery();
    AtlasGraphQuery inner2b = q.createChildQuery();
    AtlasGraphQuery inner2c = q.createChildQuery();
    inner2a.has("size15", "18");
    inner2b.has("size15", "15");
    inner2c.has("size15", "16");
    q.or(toList(inner2a, inner2b, inner2c));
    assertQueryMatches(q, v1);
    graph.commit();
    //let the index update
    pause();
    assertQueryMatches(q, v1);
}
Also used : AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) Test(org.testng.annotations.Test)

Example 4 with AtlasGraphQuery

use of org.apache.atlas.repository.graphdb.AtlasGraphQuery in project incubator-atlas by apache.

the class GraphQueryTest method testWithinStepWhereGraphIsStale.

@Test
public void testWithinStepWhereGraphIsStale() throws AtlasException {
    Titan0Graph graph = getTitan0Graph();
    AtlasVertex<Titan0Vertex, Titan0Edge> v1 = createVertex(graph);
    v1.setProperty("name", "Fred");
    v1.setProperty("size15", "15");
    v1.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v2 = createVertex(graph);
    v2.setProperty("name", "George");
    v2.setProperty("size15", "16");
    v2.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v3 = createVertex(graph);
    v3.setProperty("name", "Jane");
    v3.setProperty("size15", "17");
    v3.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v4 = createVertex(graph);
    v4.setProperty("name", "Bob");
    v4.setProperty("size15", "18");
    v4.setProperty("typeName", "Person");
    AtlasVertex<Titan0Vertex, Titan0Edge> v5 = createVertex(graph);
    v5.setProperty("name", "Julia");
    v5.setProperty("size15", "19");
    v5.setProperty("typeName", "Manager");
    AtlasGraphQuery q = getGraphQuery();
    q.has("typeName", "Person");
    //initially match
    q.in("name", toList("Fred", "Jane"));
    graph.commit();
    //let the index update
    pause();
    assertQueryMatches(q, v1, v3);
    //make v3 no longer match the query.  Within step should filter out the vertex since it no longer matches.
    v3.setProperty("name", "Janet");
    assertQueryMatches(q, v1);
}
Also used : AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) Test(org.testng.annotations.Test)

Example 5 with AtlasGraphQuery

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);
}
Also used : AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) Test(org.testng.annotations.Test)

Aggregations

AtlasGraphQuery (org.apache.atlas.repository.graphdb.AtlasGraphQuery)29 Test (org.testng.annotations.Test)18 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)11 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)3 HashMap (java.util.HashMap)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)1 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)1 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)1 AttributeValueMap (org.apache.atlas.util.AttributeValueMap)1 IndexedInstance (org.apache.atlas.util.IndexedInstance)1