Apache TinkerPopAT
Apache TinkerPop2y ago
31 replies
Aiman

Expecting java.lang.ArrayList/java.lang.List instead of java.lang.String. Where am I going wrong?

gremlin> :remote connect tinkerpop.server conf/remote.yaml session
Jun 19, 2024 6:04:36 PM org.yaml.snakeyaml.internal.Logger warn
WARNING: Failed to find field for org.apache.tinkerpop.gremlin.driver.Settings.serializers
18:04:37 INFO  org.apache.tinkerpop.gremlin.driver.Connection.<init> - Created new connection for ws://localhost:8182/gremlin
18:04:37 INFO  org.apache.tinkerpop.gremlin.driver.ConnectionPool.<init> - Opening connection pool on Host{address=localhost/127.0.0.1:8182, hostUri=ws://localhost:8182/gremlin} with core size of 1
==>Configured localhost/127.0.0.1:8182-[f353f6b1-f0b6-4b21-b928-1fd772211169]
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182]-[f353f6b1-f0b6-4b21-b928-1fd772211169] - type ':remote console' to return to local mode
gremlin>  g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[inmemory:[127.0.0.1]], standard]
gremlin>
gremlin> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@1f373aaf
gremlin> maker = mgmt.makePropertyKey('language')
==>org.janusgraph.graphdb.types.StandardPropertyKeyMaker@40921f9d
gremlin> maker.dataType(String.class)
==>org.janusgraph.graphdb.types.StandardPropertyKeyMaker@40921f9d
gremlin> maker.cardinality(LIST)
==>org.janusgraph.graphdb.types.StandardPropertyKeyMaker@40921f9d
gremlin> maker.make()
==>language
gremlin> mgmt.commit()
==>null
gremlin> g.addV('domain').property('language', ['English', 'Hindi']).property('name', 'aim').next()
==>v[4104]
gremlin> g.V(4104).properties('language').value().next().getClass()
==>class java.lang.String
Solution
A few things you should know based on your needs:
1. with JanusGraph you can't store
Map
or
List
so that may be a blocker for you
2. multi-properties aren't
List
- they are multiple values stored under the same property key, so those semantics may be a blocker for you
3. Gremlin has no steps that can help you detect a type. Whatever type detection you would do, it would have to happen in the client application (technically what you are doing when you call
next()
and
class
) which may be a blocker for you.
4. Using just Gremlin It's hard to detect if you are using multiproperties or not because it has no knowledge of the schema. Maybe you could consult JanusGraph for the schema for the types. Counting properties of a key doesn't really work either because you could have a key with just one property and it still could be a multiproperty (with just one value).

I suppose you could:
1. try a different graph that lets you natively store a
List
or a
Map
. TinkerGraph does that but it's just an in-memory graph and may not suit your needs
2. store the type as a property value. i would think that you know the type when you are setting it with
property()
step, just add another
property('type', 'LIST')
along side it.
3. ....
Was this page helpful?