Johan
Johan
ATApache TinkerPop
Created by Johan on 6/1/2024 in #questions
Does the TinkerGraph in-memory database support List cardinality properties for vertices?
It is my understanding that the following code should work:
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;

public class GremlinTest {

@Test
public void testGremlin() {
try (TinkerGraph graph = TinkerGraph.open()) {
GraphTraversalSource g = traversal().withEmbedded(graph);
g.addV("CH")
.property("key", "123")
.property("age", 20)
.property("gender", "male")
.property(VertexProperty.Cardinality.list, "address", "a street, a city")
.property(VertexProperty.Cardinality.list, "address", "b street, b city")
.next();
GraphTraversal<Vertex, Map<Object, Object>> traversal = g.V().hasLabel("CH").elementMap();
while (traversal.hasNext()) {
Map<Object, Object> node = traversal.next();
System.out.printf("%s", node);
}
}
}
}
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;

public class GremlinTest {

@Test
public void testGremlin() {
try (TinkerGraph graph = TinkerGraph.open()) {
GraphTraversalSource g = traversal().withEmbedded(graph);
g.addV("CH")
.property("key", "123")
.property("age", 20)
.property("gender", "male")
.property(VertexProperty.Cardinality.list, "address", "a street, a city")
.property(VertexProperty.Cardinality.list, "address", "b street, b city")
.next();
GraphTraversal<Vertex, Map<Object, Object>> traversal = g.V().hasLabel("CH").elementMap();
while (traversal.hasNext()) {
Map<Object, Object> node = traversal.next();
System.out.printf("%s", node);
}
}
}
}
The output when this is executed is:
{id=0, label=CH, address=b street, b city, gender=male, key=123, age=20}
{id=0, label=CH, address=b street, b city, gender=male, key=123, age=20}
However, I would expect its output to be something like this:
{id=0, label=CH, address=["a street, a city", "b street, b city"], gender=male, key=123, age=20}
{id=0, label=CH, address=["a street, a city", "b street, b city"], gender=male, key=123, age=20}
Does anyone know what I am doing wrong here?
8 replies