© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Apache TinkerPopAT
Apache TinkerPop•2y ago•
7 replies
Johan

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?
Solution
elementMap()
elementMap()
assumes that cardinality for each key is single and if it is list then only the first item encountered will be returned.
To get all property values
valueMap()
valueMap()
step can be used instead.
gremlin> g.V(1).property("address", "a1").property(list, "address", "a2")
==>v[1]
gremlin> g.V(1).valueMap()
==>[address:[a1,a2],name:[marko],age:[29]]
gremlin> g.V(1).elementMap()
==>[id:1,label:person,address:a2,name:marko,age:29]
gremlin> g.V(1).property("address", "a1").property(list, "address", "a2")
==>v[1]
gremlin> g.V(1).valueMap()
==>[address:[a1,a2],name:[marko],age:[29]]
gremlin> g.V(1).elementMap()
==>[id:1,label:person,address:a2,name:marko,age:29]
Jump to solution
Apache TinkerPop banner
Apache TinkerPopJoin
Apache TinkerPop is an open source graph computing framework and the home of the Gremlin graph query language.
1,376Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Aggregating vertices with set-cardinality properties
Apache TinkerPopATApache TinkerPop / questions
3y ago
Easiest Way to Get List Cardinality Properties As a List?
Apache TinkerPopATApache TinkerPop / questions
3y ago
search for vertices where multiple properties
Apache TinkerPopATApache TinkerPop / questions
3y ago
How will i add unique values to the vertices or edge properties in Neptune
Apache TinkerPopATApache TinkerPop / questions
2y ago