Search in sources :

Example 11 with AtlasGraphQuery

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

the class GraphQueryTest method testWithinStep.

@Test
public void testWithinStep() 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"));
    q.in("size15", toList("18", "15", "16"));
    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 12 with AtlasGraphQuery

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

the class AtlasGraphUtilsV1 method findByGuid.

public static AtlasVertex findByGuid(String guid) {
    AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance().query().has(Constants.GUID_PROPERTY_KEY, guid);
    Iterator<AtlasVertex> results = query.vertices().iterator();
    AtlasVertex vertex = results.hasNext() ? results.next() : null;
    return vertex;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery)

Example 13 with AtlasGraphQuery

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

the class AtlasGraphUtilsV1 method findBySuperTypeAndPropertyName.

public static AtlasVertex findBySuperTypeAndPropertyName(String typeName, String propertyName, Object attrVal) {
    AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance().query().has(Constants.SUPER_TYPES_PROPERTY_KEY, typeName).has(Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()).has(propertyName, attrVal);
    Iterator<AtlasVertex> results = query.vertices().iterator();
    AtlasVertex vertex = results.hasNext() ? results.next() : null;
    return vertex;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery)

Example 14 with AtlasGraphQuery

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

the class GraphRepoMapperScaleTest method searchWithOutIndex.

private void searchWithOutIndex(String key, String value) {
    AtlasGraph graph = TestUtils.getGraph();
    long start = System.currentTimeMillis();
    int count = 0;
    try {
        AtlasGraphQuery query = graph.query().has(key, ComparisionOperator.EQUAL, value);
        Iterable<AtlasVertex> result = query.vertices();
        for (AtlasVertex ignored : result) {
            count++;
        }
    } finally {
        System.out.println("Search on [" + key + "=" + value + "] returned results: " + count + ", took " + (System.currentTimeMillis() - start) + " ms");
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

Example 15 with AtlasGraphQuery

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

the class GraphRepoMapperScaleTest method searchWithIndex.

private void searchWithIndex(String key, ComparisionOperator op, Object value, int expectedResults) {
    AtlasGraph graph = TestUtils.getGraph();
    long start = System.currentTimeMillis();
    int count = 0;
    try {
        AtlasGraphQuery query = graph.query().has(key, op, value);
        Iterable<AtlasVertex> itrble = query.vertices();
        for (AtlasVertex ignored : itrble) {
            count++;
        }
    } finally {
        System.out.println("Search on [" + key + "=" + value + "] returned results: " + count + ", took " + (System.currentTimeMillis() - start) + " ms");
        Assert.assertEquals(count, expectedResults);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

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