sap13n
sap13n
ATApache TinkerPop
Created by sap13n on 6/12/2023 in #questions
Aggregating vertices with set-cardinality properties
I am aggregating traversed vertices that have both single and set-cardinality properties. When capturing the vertex using elementMap() it assumes a single-cardinality for all properties and only considers the last element in the set when building the map. However, when trying to use valueMap(true).by(unfold()) (as described in this SO reply: https://stackoverflow.com/a/75225994/3516889) It just gives the last property value in the set. query using valueMap(true).by(unfold()) (1):
g.V()
.hasLabel('SampleContainer')
.filter(properties('samples').count().is(P.gte(2))) // only consider vertices with 2 samples or more
.limit(100)
.valueMap(true).by(unfold())
g.V()
.hasLabel('SampleContainer')
.filter(properties('samples').count().is(P.gte(2))) // only consider vertices with 2 samples or more
.limit(100)
.valueMap(true).by(unfold())
Query 1 returns only the first-added sample:
{<T.id: 1>: '8ac3ec3b-ffbd-8734-83c0-9f7f7bdbd468', <T.label: 4>: 'SampleContainer', 'name': 'SomeName', 'samples': 'first'}
{<T.id: 1>: '8ac3ec3b-ffbd-8734-83c0-9f7f7bdbd468', <T.label: 4>: 'SampleContainer', 'name': 'SomeName', 'samples': 'first'}
Query Using elementMap() (2):
g.V()
.hasLabel('SampleContainer')
.filter(properties('samples').count().is(P.gte(2))) // only consider vertices with 2 samples or more
.limit(100)
.elementMap()
g.V()
.hasLabel('SampleContainer')
.filter(properties('samples').count().is(P.gte(2))) // only consider vertices with 2 samples or more
.limit(100)
.elementMap()
Query 2 returns only the last-added sample:
{<T.id: 1>: '8ac3ec3b-ffbd-8734-83c0-9f7f7bdbd468', <T.label: 4>: 'SampleContainer', 'name': 'SomeName', 'samples': 'second'}
{<T.id: 1>: '8ac3ec3b-ffbd-8734-83c0-9f7f7bdbd468', <T.label: 4>: 'SampleContainer', 'name': 'SomeName', 'samples': 'second'}
What I need is the following result:
{<T.id: 1>: '8ac3ec3b-ffbd-8734-83c0-9f7f7bdbd468', <T.label: 4>: 'SampleContainer', 'name': 'SomeName', 'samples': [ 'first', 'second'] }
{<T.id: 1>: '8ac3ec3b-ffbd-8734-83c0-9f7f7bdbd468', <T.label: 4>: 'SampleContainer', 'name': 'SomeName', 'samples': [ 'first', 'second'] }
I tried playing with local() but I can't seem to get a proper map of the elements with a set-cardinality property. Appreciate your help!
15 replies