Search in sources :

Example 16 with GraphResultSet

use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.

the class GraphTraversalITBase method should_handle_subgraph_grap_binary.

/**
 * Ensures that a traversal that returns a sub graph can be retrieved.
 *
 * <p>The subgraph is all members in a knows relationship, thus is all people who marko knows and
 * the edges that connect them.
 */
@Test
public void should_handle_subgraph_grap_binary() {
    Assumptions.assumeThat(isGraphBinary()).isTrue();
    GraphResultSet rs = session().execute(newInstance(graphTraversalSource().E().hasLabel("knows").subgraph("subGraph").cap("subGraph")));
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(1);
    String graph = results.get(0).as(String.class);
    assertThat(graph).contains("vertices:3").contains("edges:2");
}
Also used : AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test)

Example 17 with GraphResultSet

use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.

the class GraphTraversalITBase method should_use_edge_id_as_parameter.

/**
 * Ensures that a previously returned {@link Edge}'s {@link Edge#id()} can be used as an input to
 * {@link
 * org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource#E(Object...)} to
 * retrieve the {@link Edge} and that the returned {@link Edge} is the same.
 *
 * @test_category dse:graph
 */
@Test
public void should_use_edge_id_as_parameter() {
    GraphTraversal<Edge, Edge> query = graphTraversalSource().E().has("weight", 0.2f);
    GraphResultSet resultSet = session().execute(newInstance(query));
    List<GraphNode> results = resultSet.all();
    assertThat(results.size()).isEqualTo(1);
    Edge created = results.get(0).asEdge();
    if (isGraphBinary()) {
        Map<Object, Object> properties = session().execute(newInstance(query.elementMap("weight", "software", "person"))).one().asMap();
        assertThatContainsProperties(properties, "weight", 0.2f);
        assertThatContainsLabel(properties, Direction.IN, "software");
        assertThatContainsLabel(properties, Direction.OUT, "person");
    } else {
        assertThat(created).hasProperty("weight", 0.2f).hasInVLabel("software").hasOutVLabel("person");
    }
    if (isGraphBinary()) {
        Map<Object, Object> inProperties = session().execute(newInstance(graphTraversalSource().E(created.id()).inV().elementMap("name", "lang"))).one().asMap();
        assertThatContainsProperties(inProperties, "name", "lop", "lang", "java");
    } else {
        resultSet = session().execute(newInstance(graphTraversalSource().E(created.id()).inV()));
        results = resultSet.all();
        assertThat(results.size()).isEqualTo(1);
        Vertex lop = results.get(0).asVertex();
        assertThat(lop).hasLabel("software").hasProperty("name", "lop").hasProperty("lang", "java");
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 18 with GraphResultSet

use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.

the class GraphTraversalITBase method should_resolve_path_with_labels.

/**
 * Validates that when traversing a path and labeling all of the elements during the traversal
 * that the output elements are properly labeled.
 *
 * @test_category dse:graph
 */
@Test
public void should_resolve_path_with_labels() {
    GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").has("name", "marko").as("a").outE("knows").as("b").inV().as("c", "d").outE("created").as("e", "f", "g").inV().as("h").path()));
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(2);
    for (GraphNode result : results) {
        Path path = result.asPath();
        validatePathObjects(path);
        assertThat(path.labels()).hasSize(5);
        assertThat(path).hasLabel(0, "a").hasLabel(1, "b").hasLabel(2, "c", "d").hasLabel(3, "e", "f", "g").hasLabel(4, "h");
    }
}
Also used : Path(org.apache.tinkerpop.gremlin.process.traversal.Path) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test)

Example 19 with GraphResultSet

use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.

the class GraphTraversalITBase method should_return_zero_results.

/**
 * Ensures a traversal that yields no results is properly retrieved and is empty.
 *
 * @test_category dse:graph
 */
@Test
public void should_return_zero_results() {
    if (isGraphBinary()) {
        assertThatThrownBy(() -> session().execute(newInstance(graphTraversalSource().V().hasLabel("notALabel")))).isInstanceOf(InvalidQueryException.class).hasMessageContaining("Unknown vertex label 'notALabel'");
    } else {
        GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("notALabel")));
        assertThat(rs.all().size()).isZero();
    }
}
Also used : AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) InvalidQueryException(com.datastax.oss.driver.api.core.servererrors.InvalidQueryException) Test(org.junit.Test)

Example 20 with GraphResultSet

use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.

the class GraphTraversalITBase method should_resolve_path_with_some_labels.

/**
 * Validates that when traversing a path and labeling some of the elements during the traversal
 * that the output elements are properly labeled.
 *
 * @test_category dse:graph
 */
@Test
public void should_resolve_path_with_some_labels() {
    GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").has("name", "marko").as("a").outE("knows").inV().as("c", "d").outE("created").as("e", "f", "g").inV().path()));
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(2);
    for (GraphNode result : results) {
        Path path = result.asPath();
        validatePathObjects(path);
        assertThat(path.labels()).hasSize(5);
        assertThat(path).hasLabel(0, "a").hasNoLabel(1).hasLabel(2, "c", "d").hasLabel(3, "e", "f", "g").hasNoLabel(4);
    }
}
Also used : Path(org.apache.tinkerpop.gremlin.process.traversal.Path) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test)

Aggregations

GraphResultSet (com.datastax.dse.driver.api.core.graph.GraphResultSet)22 Test (org.junit.Test)22 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)18 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)17 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)8 FluentGraphStatement (com.datastax.dse.driver.api.core.graph.FluentGraphStatement)4 GraphStatement (com.datastax.dse.driver.api.core.graph.GraphStatement)4 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)4 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)4 SocialTraversalSource (com.datastax.dse.driver.api.core.graph.SocialTraversalSource)3 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)2 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)2 InvalidQueryException (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException)2 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Map (java.util.Map)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2 FluentGraphStatement.newInstance (com.datastax.dse.driver.api.core.graph.FluentGraphStatement.newInstance)1 TinkerGraphAssertions.assertThat (com.datastax.dse.driver.api.core.graph.TinkerGraphAssertions.assertThat)1