Tigergraph GSQL how to

Hi team I am stuck in one situation please help me out in this one

I have a segment vertex and different types of segment vertex separately, what I mean here is we don’t have Segment Vertex which is connected as an undirected edge to Segment Types, we have approx. 12 types of separate vertex in our schema , below image is a sub part of my schema

image

TYPEDEF Tuple <STRING label, STRING id>  custom_def;
  ListAccum<custom_def> @childSegments;
  SumAccum<INT>    @segmentCount;
  
  start = {segment_types.*};
  results = select s from start:s-(:ee)-:tt ACCUM s.@childSegments += custom_def(tt.label, tt.id) ORDER BY s.id ASC;

  #z = select s from results:s ACCUM 
  #foreach res in s.@childSegments DO
       #if res.outdegree() > 0 
          
       #End
  #end;

Output:

"results": [
      {
        "attributes": {
          "@childSegments": [
            {
              "id": "Purchased in the Past 1 year",
              "label": "Purchased in Past 1 year"
            },
            {
              "id": "Purchased in the Past 6 Months",
              "label": "Purchased in Past 6 Months"
            }],
             "id": "Purchase Transaction",
             "label": "Purchase Transactions"
      },
      {
        "attributes": {
          "@childSegments": [
            {
              "id": "Cart Abandoners",
              "label": "Cart Abandoners"
            }],
           "id": "Session Segments",
          "label": "Session Segments"
    }

So here the situation where i am stuck is I want count variable in @childSegments {
“id”: “Cart Abandoners”,
“label”: “Cart Abandoners”,
“count”: 45
}

i want count SUMACCUM@localaccumulator something like this. This is for Count the number of Profiles in that segment
Requirement: tt.outdegree() > 0 don’t want to pass the edge type Because some childSegments not connected directly to profile. some are categorical based etc.
If someone can guide me this logic in Global Accumulator array of objects this would be really helpful and improves my understanding towards GSQL an otherwise in the backend I need to take out the data from attributes object and store it into the parent object which will be very time consuming process of for loop.

Maybe I am missing something, but why not just use an accumulator to count them?


TYPEDEF Tuple <STRING label, STRING id>  custom_def;
  MapAccum <custom_def, INT> @childSegments;
  SumAccum<INT>    @segmentCount;
  
  start = {segment_types.*};
  results = select s from start:s-(:ee)-:tt ACCUM s.@childSegments += (custom_def(tt.label, tt.id) -> 1 ) 
ORDER BY s.id ASC;
1 Like

Hi thanks for your response
Actually I have a Parent vertex have segment_types which have multiple types of segment inside that, and segment_types is connected to their specific type vertex, means if PurchaseTransactionSegment in segment_type then this one is connected to their specific vertex purchase_transaction_segment, below is the sample image

image

and this one is a sub part image I have 15 vertex which is directly connected to
segment_type, and the question is in this I want the target connected edge count, price_segment vertex is further connected to customer, that customer count, How many customer count in that segment.

tt.outdegree() > 0 don’t want to pass the edge type Because some childSegments not connected directly to customer. some are categorical based segment etc

[
  {
    "results": [
      {
        "attributes": {
          "@childSegments": [
            {
              "id": "multiplePurchasesInThePast1Year",
              "label": "Multiple Purchases in Past 1 year",
              "total_count_of_customers": 20000
            },
            {
              "id": "purchasedInThePast1Year",
              "label": "Purchased in Past 1 year",
              "total_count_of_customers": 400000
            }
           ],
           "id": "purchaseTransaction",
          "label": "Purchase Transactions"
        },
        "v_id": "purchaseTransaction",
        "v_type": "segment_types"
        {
        "attributes": {
          "@childSegments": [
            {
              "id": "emailVisitors",
              "label": "Email Visitors",
              "total_count_of_customers":  12000
            },
            {
              "id": "researchers",
              "label": "Researchers",
             "total_count_of_customers":  8000
            }
          ],
          "@segmentCount": 0,
          "id": "sessionSegment",
          "label": "Sess Segments"
        },
        "v_id": "sessionSegment",
        "v_type": "segment_types"
      }
    ]
  }
]

I am not understanding the question here, can you please give more details, or at least show some specifics about the parent vertex and the edges and attributes?