Search in sources :

Example 21 with AtlasGraphQuery

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

the class GraphBackedMetadataRepositoryTest method getTableEntityVertex.

@GraphTransaction
AtlasVertex getTableEntityVertex() {
    AtlasGraph graph = TestUtils.getGraph();
    AtlasGraphQuery query = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, ComparisionOperator.EQUAL, TestUtils.TABLE_TYPE);
    Iterator<AtlasVertex> results = query.vertices().iterator();
    // returning one since guid should be unique
    AtlasVertex tableVertex = results.hasNext() ? results.next() : null;
    if (tableVertex == null) {
        Assert.fail();
    }
    return tableVertex;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 22 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 {
    Titan1Graph graph = getTitan1Graph();
    AtlasVertex<Titan1Vertex, Titan1Edge> v1 = createVertex(graph);
    v1.setProperty("name", "Fred");
    v1.setProperty("size15", "15");
    v1.setProperty("typeName", "Person");
    AtlasVertex<Titan1Vertex, Titan1Edge> v2 = createVertex(graph);
    v2.setProperty("name", "George");
    v2.setProperty("size15", "16");
    v2.setProperty("typeName", "Person");
    AtlasVertex<Titan1Vertex, Titan1Edge> v3 = createVertex(graph);
    v3.setProperty("name", "Jane");
    v3.setProperty("size15", "17");
    v3.setProperty("typeName", "Person");
    AtlasVertex<Titan1Vertex, Titan1Edge> v4 = createVertex(graph);
    v4.setProperty("name", "Bob");
    v4.setProperty("size15", "18");
    v4.setProperty("typeName", "Person");
    AtlasVertex<Titan1Vertex, Titan1Edge> 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 23 with AtlasGraphQuery

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

the class GraphQueryTest method testQueryThatCannotRunInMemory.

@Test
public <V, E> void testQueryThatCannotRunInMemory() 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 = graph.query();
    q.has("name", ComparisionOperator.NOT_EQUAL, "George");
    q.has("size15", "15");
    graph.commit();
    //pause to let the index get updated
    pause();
    assertQueryMatches(q, v1, v3, v4);
}
Also used : AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) Test(org.testng.annotations.Test)

Example 24 with AtlasGraphQuery

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

the class GraphQueryTest method testQueryResultsReflectPropertyAdd.

@Test
public <V, E> void testQueryResultsReflectPropertyAdd() throws AtlasException {
    AtlasGraph<V, E> graph = getGraph();
    AtlasVertex<V, E> v1 = createVertex(graph);
    v1.setProperty("name", "Fred");
    v1.setProperty("size15", "15");
    v1.addProperty(TRAIT_NAMES, "trait1");
    v1.addProperty(TRAIT_NAMES, "trait2");
    AtlasVertex<V, E> v2 = createVertex(graph);
    v2.setProperty("name", "Fred");
    v2.addProperty(TRAIT_NAMES, "trait1");
    AtlasVertex<V, E> v3 = createVertex(graph);
    v3.setProperty("size15", "15");
    v3.addProperty(TRAIT_NAMES, "trait2");
    AtlasGraphQuery query = getGraphQuery();
    query.has("name", "Fred");
    query.has(TRAIT_NAMES, "trait1");
    query.has("size15", "15");
    assertQueryMatches(query, v1);
    //make v3 match the query
    v3.setProperty("name", "Fred");
    v3.addProperty(TRAIT_NAMES, "trait1");
    assertQueryMatches(query, v1, v3);
    v3.removeProperty(TRAIT_NAMES);
    assertQueryMatches(query, v1);
    v3.addProperty(TRAIT_NAMES, "trait2");
    assertQueryMatches(query, v1);
    v1.removeProperty(TRAIT_NAMES);
    assertQueryMatches(query);
    graph.commit();
    assertQueryMatches(query);
}
Also used : AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) Test(org.testng.annotations.Test)

Example 25 with AtlasGraphQuery

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);
}
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