Expecting java.lang.ArrayList/java.lang.List instead of java.lang.String. Where am I going wrong?
Solution:Jump to 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)....18 Replies
Might be
next()
causing the issue there... what do you get if you use toList()
instead? or next(n)
would return n results in a list.Can't use
toList()
because even if the property value is a String it is going to convert it to ArrayList
And this is the error if I use next(n)
n would be a number. As in, n=3 to return 3 of the next results in a list.
I don't quite understand what your desired outcome is here. Do you want the result returned as a list or as a string?
Or as a "stringified" list?
I want it to return its respective Data Type . In the query I've added a List to a property
language
and a String
to a property name
. My expectations are if its language
it should return ArrayList
and if its name
it should return String
g.addV('domain').property('language', ['English', 'Hindi']).property('name', 'aim').next()
Perhaps this is some oddity with Janusgraph, then. As TinkerGraph in Gremlin Console does just as you would expect:
What was your create query?
g.addV('domain').property('language', ['English', 'Hindi']).property('name', 'aim').next()
This is the query i usedI'm confused. I've done the same thing
I've restarted the JanusGraph Server and followed the below steps
@triggan What are the prerequisites to be followed before executing the query?
you can't store
List
in JanusGraph i don't think. it's not a supported type: https://docs.janusgraph.org/v0.3/basics/schema/#property-key-data-type if you set Cardinality.LIST
then it looks like JansuGraph will coerce a
List to multiproperties which is why
value() returns a string (i.e. the first multiproperty)
```gremlin> g = TinkerFactory.createTheCrew().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:14], standard]
gremlin> g.V(1).valueMap()
==>[name:[marko],location:[san diego,santa cruz,brussels,santa fe]]
gremlin> g.V(1).properties('location').value().next()
==>san diego
gremlin> g.V(1).properties('location').value()
==>san diego
==>santa cruz
==>brussels
==>santa fe
gremlin> g.V(1).map(properties('location').value().fold())
==>[san diego,santa cruz,brussels,santa fe]
```
so, if you want them as a
List you could
fold()` them up as shown in that last traversalHow was
location
created ? Since I'm getting an error while creatingyou just call
property()
with the same key for each "location" yout want to add:"
or, again, it looked like when you set the schema to use LIST
cardinality it coerced the list automatically for you to multiproperties.......
https://docs.janusgraph.org/schema/advschema/#multi-propertiesI've restarted the janusgraph server and ran these
that is the expected output. same as what i demonstrated when calling
next()
in my example. i get one result of type String
Let me brief out about my problem statement. I want to create a vertex which has property values of different data types [ex: List, String ,Map] . When I retrieve a vertex, alter gremlin command such that it returns its data type.
Based on the data type i need to perform some operations from the code.
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. ....Thank you @spmallette