Order of boolean conditions matters?

19 views
Skip to first unread message

Doug

unread,
Apr 9, 2020, 2:55:23 PM4/9/20
to gsql-users
Hi,

My schema is basically  Incident - instanceOf - AbstractIncident - connectedTo -> OtherThings 

The instanceOf edge is undirected, while connectedTo is directed and has an attribute of "incNumber"

I am trying to do a simple breath first search to get everything reachable from AbstractIncident.  

When the first commented out WHERE line is used, the code returns everything I expect BUT the Incident vertex and the instanceOf edge

INTERPRET QUERY () FOR GRAPH historicDelays {
  SetAccum<edge> @@edgeList;
  OrAccum @visited;
  allNodes = {};
  theinc = {};

  incs = {incident.*};
  theinc = SELECT v FROM incs:v WHERE v.incNumber == 377188 ;
  visitedNodes (ANY) = theinc;

  while visitedNodes.size() != 0 DO
    visitedNodes = SELECT s FROM visitedNodes-(:e)-:s
                   // WHERE s.@visited == false AND (e.incNumber == 377188 OR e.type == "instanceOf")
                   // WHERE s.@visited == false AND e.type == "instanceOf"
                   WHERE s.@visited == false AND (e.type == "instanceOf" OR e.incNumber == 377188)
                   ACCUM @@edgeList += e
                   POST-ACCUM s.@visited = true;
    allNodes = allNodes UNION visitedNodes;
  end;

  print allNodes.size() as TotalNodeCount;
  print allNodes[allNodes.type];
  print @@edgeList.size() as TotalEdgeCount;
  print @@edgeList;
}

The second WHERE was a test to make sure the data was setup like I'd expected.

Only the third WHERE line is working in that it returns all of the vertices reachable from AbstractIncident.  Am I doing something wrong, did I overlook something in the docs, or am I not understanding something about how this while loop works (internally)?  A breadth first search ought to get all the vertices.

Also, how can you get the print statement to output the composite key of a vertex (akin to how the type or user attributes can be)?

Thanks
Doug
 

Doug

unread,
Apr 12, 2020, 7:17:27 AM4/12/20
to gsql-users
Never mind.... I overlooked the part in the documentation that discusses the nuances of how edge searches work.  if you have multiple edge types, a where condition checking the edge type in combination with attributes, either ensure all edge types have the attribute - or explicitly check the edge type in combination with the right attribute. Example:

WHERE s.@visited == false AND ((e.type != "instanceOf" AND e.incNumber == 377188) OR e.type == "instanceOf")

I infer in the first version of this line, the search was hitting an edge of "instanceOf", seeing it does not have a incNumber attribute and so results in a False and the whole condition fails, due to boolean short-circuit evaluation (at least that's what makes sense)
Reply all
Reply to author
Forward
0 new messages