Need help with the Max Accumulator

I have a query that returns a set of vertices and I want to get the Max value of the Primary Keys which in this case should be “7”. Here’s a list of the vertices:
image

I tried using:

MaxAccum<UINT> @@maxAccum;

But couldn’t get the correct syntax so I ended up with this:

However, the value of @@maxAccum = 3 which doesnt make sense to me. Can someone please explain why its “3” and not “7” as expected?

Thank you

Here’s the Json returned from this query:
[
{
“@@maxAccum”: “3”
},
{
“Items”: [
{
“v_id”: “7”,
“v_type”: “ConceptItem”,
“attributes”: {
“name”: “Vintage Old Flatbed”,
“description”: “”
}
},
{
“v_id”: “2”,
“v_type”: “ConceptItem”,
“attributes”: {
“name”: “Beached 67 150”,
“description”: “”
}
},
{
“v_id”: “4”,
“v_type”: “ConceptItem”,
“attributes”: {
“name”: “Ford in the Fog”,
“description”: “”
}
},
{
“v_id”: “5”,
“v_type”: “ConceptItem”,
“attributes”: {
“name”: “Kicks on Route 66”,
“description”: “”
}
},
{
“v_id”: “3”,
“v_type”: “ConceptItem”,
“attributes”: {
“name”: “Dog in Truck”,
“description”: “”
}
},
{
“v_id”: “6”,
“v_type”: “ConceptItem”,
“attributes”: {
“name”: “Farmhand”,
“description”: “”
}
},
{
“v_id”: “1”,
“v_type”: “ConceptItem”,
“attributes”: {
“name”: “58 Ford Truck in Desert”,
“description”: “”
}
}
]
}
]

MaxAccum on a vertex gives you the maximum hash (internal vertex id), which isn’t what you want.

Instead try a MaxAccum , and add the id itself.

In the schema you’ll need to have the “id as attribute” set on the Concept vertex so GSQL can see the id directly.

1 Like

Once you make the change suggested by Rik to expose the id as an attribute , its easy

MaxAccum @@maxAccum;

then in the query:

ACCUM @@maxAccum += t.id;

Thank you rik and markmegerian. All clear now.