2
votes

I have a vertex with following properties:

Name - Type - Cardinality

prop_1 - String - Single

prop_2 - String - Set

When I return the value-map of above vertex, the values are not returned in proper format.

  • Using valueMap().by(unfold()) returns prop_1 correctly as single String value but only returns the first element of prop_2 which is Set of String.
  • Using simply valueMap() returns prop_1 as array of String and all values of prop_2 as array of String

I know that if I explicitly mention single cardinality properties to be unfolded,I can get the result I want but the gremlin query we are using is generic (dynamically generated) is used for different vertices with different properties and this the properties cannot be explicitly mentioned in return statements.

Is there a way to return the single and set carinality properties to be returned with correct data type representation?

1

1 Answers

2
votes

You can do it base on the number of values in the property.

(this may cause inconsistency with a set value that contains only 1 value...)

g.V().valueMap().by(choose(
      count(local).is(eq(1)),
      unfold()
      identity()
    ))

example https://gremlify.com/@noam621/b9