Per clause working problem

Hi everyone,
I write a simple query to count unique products by the customer

CREATE QUERY recommend(/* Parameters here */) FOR GRAPH DATA{ 
  SumAccum<int> @product_cnt = 0 ;
  Others1 = 
  SELECT c1
  FROM customer:c1
  where c1.name!=""
  limit 20;
  
  Others2=SELECT c1
  FROM product:p-(transaction) - Others1:c1 
  PER(c1,p) 
  ACCUM c1.@product_cnt += 1;
  print Others2;

}

This is result, @product_cnt=0:

{
        "attributes": {
          "@bought": false,
          "@product_cnt": 0,
          "name": "23194432"
        },
        "v_id": "23194432",
        "v_type": "customer"
      }

When I remove PER clause this is result, @product_cnt=525:

{
        "attributes": {
          "@product_cnt": 525,
          "name": "23194432"
        },
        "v_id": "23194432",
        "v_type": "customer"
      }

Is there any problem in my code PER clause?

Hi Igenta,

I don’t think there is anything wrong with your code, but in a single-hop query, the PER clause with both vertex types is redundant. The version without PER will work correctly.

If the traversal was a 2-hop, such as:
FROM product:p-(transaction)-SomeOtherVertex:m - (SomeOtherEdge:e)-Others1:c1
you would see the same results with PER(c1,p) as you see in the single-hop without using PER

The Semantics section in the documentation gives a good description of the functionality.

Kudos to you for exploring the use of PER! It can be a useful tool to maximize performance of large queries.

I see why its redundant, but why would the result be zero? If its redundant and yields the same behavior with or without, then why isnt it returning 525 ?

I have the same question and have escalated internally. I’ll report back on the findings.