Query doesn't give output

Hi, I have these queries according to TG documentation:

CREATE QUERY tg_shortest_ss_no_wt (VERTEX source, SET<STRING> v_type, SET<STRING> e_type, 
  INT output_limit = -1, BOOL print_accum =TRUE, STRING result_attr ="", STRING file_path ="",
  BOOL display_edges =FALSE) {
/*
Single-source shortest path algorithm, with unweighted edges.
From the source vertex, finds the unweighted shortest path (number of hops, INT value)
 source: start vertex                         print_accum: print JSON output
 v_type: vertex types to traverse             result_attr: INT attr to store results to
 e_type: edge types to traverse               file_path: file to write CSV output to
 output_limit: max #vertices to output        display_edges: output edges for visualization
*/

  FILE f(file_path);
  MinAccum<INT> @min_dis;
  OrAccum @or_visited;
  ListAccum<VERTEX> @path_list;
  SetAccum<EDGE> @@edge_set;

  ##### Initialization  #####
  Source = {source};
  Source = SELECT s 
           FROM Source:s
	   ACCUM s.@or_visited += true, 
	         s.@min_dis = 0,
		 s.@path_list = s; 
  ResultSet = {source};

  ##### Calculate distances and paths #####
  WHILE(Source.size()>0) DO
      Source = SELECT t
	       FROM Source:s -(e_type:e)-> v_type:t
	       WHERE t.@or_visited == false
	       ACCUM t.@min_dis += s.@min_dis + 1,
	             t.@path_list = s.@path_list + [t],
	             t.@or_visited += true
      ORDER BY getvid(t);
      ResultSet = ResultSet UNION Source;
  END;

  IF file_path != "" THEN
      f.println("Vertex_ID","Distance","Shortest_Path");
  END;

  ResultSet = SELECT s 
              FROM ResultSet:s 
              POST-ACCUM 
                  IF result_attr != "" 
		      THEN s.setAttr(result_attr, s.@min_dis) 
		  END,
                  IF file_path != "" THEN 
		      f.println(s, s.@min_dis, s.@path_list)
		  END;
  
  IF print_accum THEN
      IF output_limit >= 0 THEN
          ResultSet = SELECT s 
	              FROM ResultSet:s 
		      LIMIT output_limit;
      END;
      PRINT ResultSet[ResultSet.@min_dis, ResultSet.@path_list];
      IF display_edges THEN
          ResultSet = SELECT s 
	              FROM ResultSet:s -(e_type:e)-> v_type:t
                      ACCUM @@edge_set += e;
          PRINT @@edge_set;
      END;
  END;    
}

CREATE QUERY tg_all_pairs_shortest(SET<STRING> v_type, SET<STRING> e_type, STRING result_attr = "", STRING file_path = "")
{
  Start = {v_type};
  Result = SELECT s FROM Start:s 
        POST-ACCUM
          tg_shortest_ss_no_wt(s, v_type, e_type, -1, TRUE,
          result_attr, file_path, FALSE);
}

After installing them, if I RUN QUERY tg_shortest_ss_no_wt with a specific starting vertex, it gives a json output. However, when I RUN QUERY tg_all_pairs_shortest, it doesn’t give out anything. Does anyone know how to fix it? Thank you very much.

Accumulators have to be defined in each query. In the tg_all_pairs_shortest query, you might be missing accumulators when using POST-ACCUM

Hi Phuong,

You’re missing a PRINT statement from the tg_all_pairs_shortest query.

You can add PRINT Result; as a final line in your query and it will return the Result vertex-set.

Running a query from within another query will not return the PRINT statements from the inner query. Additionally, it doesn’t look like the tg_shortest_ss_no_wt query has a RETURN statement so it isn’t actually returning any data to the parent query (ts_all_pairs_shortest).

You can add RETURN ResultSet; to the end of the tg_shortest_ss_no_wt query and that will allow it to feed back into the tg_all_pairs_shortest query so that it can be PRINTed.

1 Like

Hi Kristine,

Thank you for your reply. I think the main problem is like @Dan_Barkus mentioned, that my tg_shortest_ss_no_wt doesn’t have a RETURN output which resulted in that I can’t use accumulator later in tg_all_pairs_shortest.

1 Like

Hi @Dan_Barkus,

Thank you for your reply. I made it works. :slight_smile:

1 Like