He attribute of an universal vertex type variable cannot be accessed

Hello Reader, Thanks for reading it!

I have just started with TigerGraph. I have a very question but I am not able to resolve it.

I want to add the marks of the students until their total crosses to 50. I have written the code but getting the below error.
subs = SELECT a FROM Start:a ACCUM @@Results +=a;
FOREACH i IN @@Results DO

if c<50 THEN @@Results_fin +=i; end;
if c<50 THEN c +=i.score; end;

END;

Error: Error: The attribute of an universal vertex type variable cannot be accessed.

How can I add the scores here?

Thanks in Advance!

1 Like

I guess you define @@Results like SetAccum<vertex> @@Results.
You can try to define @@Results like SetAccum<vertex<your_vertex_type>> @@Results.

You should be more specific on what you are trying to do.

For instance, what are the vertex types and attributes? Where are the student scores being stored?
Your example doesnt really make much sense, and its not clear what c is for or what @@Results is for.

You will get great suggestions if you clarify your problem a bit better

1 Like

Is there any other way? I want to make my function more generic

@canbax One suggestion is checking out the Graph Data Science Library. Many algorithms (queries) are built to run universally on any graph solution. You can take the code logic and apply those concepts to your solution. gsql-graph-algorithms/algorithms at master · tigergraph/gsql-graph-algorithms · GitHub

One example from the many there (note that v_type and e_type are passed as parameters allowing you to apply the same logic to any graph schema):

CREATE QUERY tg_kcore(STRING v_type, STRING e_type, INT k_min = 0, INT k_max = -1, BOOL print_accum = TRUE, 
  STRING result_attr = "", STRING file_path = "", BOOL print_all_k = FALSE, BOOL show_shells=FALSE)  SYNTAX V1 { 
  
/* An implementation of Algorithm 2 in
 * Scalable K-Core Decomposition for Static Graphs Using a Dynamic Graph Data Structure,
 * Tripathy et al., IEEE Big Data 2018.
 
 This query is only supported for a single edge type at the moment (8/13/20)
 */
  SumAccum<INT> @sum_deg;        // The number of edges v has to active vertices.
  SumAccum<INT> @sum_core;       // The core level of vertex v
  FILE f(file_path);
  INT k;             			    
  k = k_min;				      
	
  active = {v_type};
  active = SELECT v 
           FROM active:v // Initialize @deg 
	   POST-ACCUM v.@sum_deg += v.outdegree(e_type);
  
  Q = active;
  WHILE active.size() > 0 AND (k_max == -1 OR k < k_max) DO
      deleted = SELECT v 
                FROM active:v
                WHERE v.@sum_deg <= k
                ACCUM v.@sum_core += k;
  
      active = active MINUS deleted;
      IF deleted.size() > 0 THEN                // "Remove adjacent edges"         
          U = SELECT u 
              FROM deleted:u -(e_type:e)- :v
	      ACCUM  v.@sum_deg += -1;  // Actually, reduce degree of vertices
      ELSE IF show_shells THEN 
          // Show vertices which did not satisfy kcore condition at a value of k 
          shells = Q MINUS active;
          PRINT k, shells; 
      END;
      
      IF active.size() > 0 THEN
          Q = active;
      END;
        
      //show all vertices which satisfied the condition at k.
      IF print_all_k THEN 
          PRINT k, Q as members;
      END;
      k = k + 1;
	
  END;
  IF file_path != "" THEN
      f.println("Vertex", "Core");
  END;
  
  IF file_path != "" OR result_attr != "" THEN
      Seed = {v_type};
      Seed = SELECT s 
             FROM Seed:s
             POST-ACCUM
                 IF file_path != "" THEN 
		     f.println(s, s.@sum_core) 
		 END,
                 IF result_attr != "" THEN 
		     s.setAttr(result_attr, s.@sum_core) 
		 END;
  END;
  
  IF print_accum THEN
      PRINT k, Q.size() as core_size, Q as max_core;
  END;	
}
2 Likes

Thank you, John. It is unrelated but I tried to use gsql-graph-algorithms/tg_jaccard_nbor_ss.gsql at master · tigergraph/gsql-graph-algorithms · GitHub on tgcloud solution. I get the below error message

(47, 13) Error: Edge similarity_edge_type’s valid FROM vertex types don’t cover all vertex types, so a universal vertex type expression cannot be used here.

In some posts, I see related messages Add the number of common neighbors between two vertices as an attribute to the edge between the same vertices - #6 by luyilun32661 INSERT INTO a vertex They all say “give a specific vertext type” as a solution