Update Vertex from Max value of attached Vertext Attributes

My model is: vF -HAS_vH - vH

Where vH has an attribute W and vF has an attribute maxW

I want to update the attribute maxW in vF with the Max value from W in the attached Vertices.

Can someone point me in the right direction?

Thanks!

Frank

Hi @fjblau ,

In this case, you should be able to utilize the maxAccum to gather the maximum W value from vH. After that, you can utilize something like the setAttr function to update the value of maxW in a POST-ACCUM clause.

So, you can do something like the following. The following query assumes that the type of W and maxW is FLOAT, but you can have it as other types too.

CREATE QUERY update_maxW() {
    MaxAccum<FLOAT> @maximum_W;

    all_vF = {vF.*};

    all_vF = SELECT s
        FROM vF:s -(HAS_vH:e)- vH:t
        ACCUM
            s.@maximum_W += t.maxW
        POST-ACCUM (s)
            s.setAttr("maxW", s.@maximum_W)
    ;
}

Note: the values would be updated after the update_maxW query finishes executing. You shouldn’t assume that the maxW attribute is updated while the update_maxW query is running.

I hope this helps!

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph

When I run that with my attributes, I get:

task VertexActionTask_1131failed: no UpdateAttribute defined, throw error

Hi @fjblau,

What version of TigerGraph are you currently using?

I tried running that in my own environment (TG Cloud 3.10.1), and I get the issue IF I run the query in interpreted mode.

Can you try installing the query first before running the installed query?

Best,
Supawish Limprasert (Jim)
Solution Engineer, TigerGraph

Hi,

I also agree with jim thank you so much for sharing this information.

I am just curious as to why you would ever want to do this.

The power of having accumulators and the ACCUM clause is that you can very efficiently calculate this maximum value any time you run the query using your ACCUM clause but without updating the attribute in the POST-ACCUM clause. By updating an attribute, you have introduced issues relating to the attribute value not being in synch with the live value, and then having to decide how often to run the update query. It just seems like creating more issues without solving anything.

Can you explain what this scheme of updating an attribute achieves that cannot be achieved with just an ACCUM ?