use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_return_zero_results_graphson_2.
/**
* Ensures a traversal that yields no results is properly retrieved and is empty, using GraphSON2
* and the TinkerPop transform results function.
*
* @test_category dse:graph
*/
@Test
public void should_return_zero_results_graphson_2() {
Assumptions.assumeThat(isGraphBinary()).isFalse();
GraphStatement simpleGraphStatement = ScriptGraphStatement.newInstance("g.V().hasLabel('notALabel')");
GraphResultSet rs = session().execute(simpleGraphStatement);
assertThat(rs.one()).isNull();
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_deserialize_vertex_id_as_map.
/**
* A sanity check that a returned {@link Vertex}'s id is a {@link Map}. This test could break in
* the future if the format of a vertex ID changes from a Map to something else in DSE.
*
* @test_category dse:graph
*/
@Test
public void should_deserialize_vertex_id_as_map() {
GraphResultSet resultSet = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").has("name", "marko")));
List<GraphNode> results = resultSet.all();
assertThat(results.size()).isEqualTo(1);
Vertex marko = results.get(0).asVertex();
if (isGraphBinary()) {
assertThat(((String) marko.id())).contains("marko");
assertThat(marko.label()).isEqualTo("person");
} else {
assertThat(marko).hasProperty("name", "marko");
@SuppressWarnings("unchecked") Map<String, String> id = (Map<String, String>) marko.id();
assertThat(id).hasSize(3).containsEntry("~label", "person").containsKey("community_id").containsKey("member_id");
}
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_handle_lambdas.
/**
* Validates that a traversal using lambda operations with anonymous traversals are applied
* appropriately and return the expected results.
*
* <p>Traversal that filters 'person'-labeled vertices by name 'marko' and flatMaps outgoing
* vertices on the 'knows' relationship by their outgoing 'created' vertices and then maps by
* their 'name' property and folds them into one list.
*
* <p><b>Note:</b> This does not validate lambdas with functions as those can't be interpreted and
* sent remotely.
*
* @test_category dse:graph
*/
@Test
public void should_handle_lambdas() {
// Find all people marko knows and the software they created.
GraphResultSet result = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").filter(__.has("name", "marko")).out("knows").flatMap(__.out("created")).map(__.values("name")).fold()));
// Marko only knows josh and vadas, of which josh created lop and ripple.
List<String> software = result.one().as(GenericType.listOf(String.class));
assertThat(software).containsOnly("lop", "ripple");
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_parse_tree.
/**
* Validates that a traversal returning a Tree structure is returned appropriately with the
* expected contents.
*
* <p>Retrieves trees of people marko knows and the software they created.
*
* @test_category dse:graph
*/
@Test
public void should_parse_tree() {
// Get a tree structure showing the paths from mark to people he knows to software they've
// created.
GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").out("knows").out("created").tree().by("name")));
List<GraphNode> results = rs.all();
assertThat(results.size()).isEqualTo(1);
// [{key=marko, value=[{key=josh, value=[{key=ripple, value=[]}, {key=lop, value=[]}]}]}]
GraphNode result = results.get(0);
@SuppressWarnings("unchecked") Tree<String> tree = result.as(Tree.class);
assertThat(tree).tree("marko").tree("josh").tree("lop").isLeaf();
assertThat(tree).tree("marko").tree("josh").tree("ripple").isLeaf();
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_handle_result_object_of_mixed_types.
/**
* Ensures that a traversal that returns a result of mixed types is interpreted as a {@link Map}
* with {@link Object} values. Also uses {@link
* org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#by(org.apache.tinkerpop.gremlin.process.traversal.Traversal)}
* with an anonymous traversal to get inbound 'created' edges and folds them into a list.
*
* <p>Executes a vertex traversal that binds label 'a' and 'b' to vertex properties and label 'c'
* to vertices that have edges from that vertex.
*
* @test_category dse:graph
*/
@Test
public void should_handle_result_object_of_mixed_types() {
// find all software vertices and select name, language, and find all vertices that created such
// software.
GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("software").as("a", "b", "c").select("a", "b", "c").by("name").by("lang").by(__.in("created").fold())));
List<GraphNode> results = rs.all();
assertThat(results.size()).isEqualTo(2);
// Ensure that we got 'lop' and 'ripple' for property a.
assertThat(results).extracting(m -> m.getByKey("a").as(Object.class)).containsOnly("lop", "ripple");
for (GraphNode result : results) {
// The row should represent a map with a, b, and c keys.
assertThat(ImmutableList.<Object>copyOf(result.keys())).containsOnlyOnce("a", "b", "c");
// 'e' should not exist, thus it should be null.
assertThat(result.getByKey("e")).isNull();
// both software are written in java.
assertThat(result.getByKey("b").isNull()).isFalse();
assertThat(result.getByKey("b").asString()).isEqualTo("java");
GraphNode c = result.getByKey("c");
assertThat(c.isList()).isTrue();
if (result.getByKey("a").asString().equals("lop")) {
if (isGraphBinary()) {
// should contain three vertices
Assertions.assertThat(c.size()).isEqualTo(3);
} else {
// 'c' should contain marko, josh, peter.
// Ensure we have three vertices.
assertThat(c.size()).isEqualTo(3);
List<Vertex> vertices = Lists.newArrayList(c.getByIndex(0).asVertex(), c.getByIndex(1).asVertex(), c.getByIndex(2).asVertex());
assertThat(vertices).extracting(vertex -> vertex.property("name").value()).containsOnly("marko", "josh", "peter");
}
} else {
if (isGraphBinary()) {
// has only one label
Assertions.assertThat(c.size()).isEqualTo(1);
} else {
// ripple, 'c' should contain josh.
// Ensure we have 1 vertex.
assertThat(c.size()).isEqualTo(1);
Vertex vertex = c.getByIndex(0).asVertex();
assertThat(vertex).hasProperty("name", "josh");
}
}
}
}
Aggregations