Processing sorted vertices

I have a query that returns a selection of vertices associated with a parent record… what I need to do is process the child records in date order and create a NEXT edge between them… since I have a date string that should sort them them that way…

Here is my code:

CREATE QUERY test() for graph cust {

ListAccum<STRING> @@edgeList;
ListAccum<VERTEX<hscode>> @@vertexList;
		
  INT edgeCount;
	INT iter;
	iter=0;
	#STRING x;
	#STRING y;
	
  start = {parcel.*};

  s = SELECT h
	    FROM start:v-(HAS_EVENT:e)-hscode:h
      WHERE v.parcelId == "199559693"
	    POST-ACCUM @@vertexList += h
	    ORDER BY h.DateStr ASC;
	    
WHILE (iter < @@vertexList.size()-1) DO
  print @@vertexList.get(iter), @@vertexList.get(iter+1);
  INSERT INTO NEXT VALUES (@@vertexList.get(iter), @@vertexList.get(iter+1));
  iter = iter + 1;
End;


	}

But the sort doesn’t seem to process them all in the right order… am I missing something? Is there sort of “sorted accumulator” that exists for this purpose?

Thanks,

Frank

In your query populating the list happens first and order by happens the next. Beside parallelly populating a list doesn’t guarantee the order.

To have an ordered list, please consider using HeapAccum.

https://docs.tigergraph.com/dev/gsql-ref/querying/accumulators#heapaccum

Thanks.

using:

TYPEDEF TUPLE<STRING eventId, STRING dateStr> events;

and

HeapAccum(@@vertexList.size(), dateStr ASC) @@eventList;

I am getting the errors:

(23, 49) Error: no viable alternative at input ‘HeapAccum(@@vertexList.size(), dateStr asc’
(23, 49) Error: no viable alternative at input ‘(@@vertexList.size(), dateStr asc’

Seems you have defined those in line 23, please try to move the variable definition part to the beginning of the query.

Since in GSQL, the variable definition session always comes before all the query logic.