Skip to content

Issues with k shortest path handling #3504

@campoy

Description

@campoy

There are three different issues that could be improved on calls to shortest.

Variables should be accepted (#1243)

A quick example of why this should be accepted.

{
  sp as var (func: eq(name@en, "Steven Spielberg")) @filter(has(director.film))
  jg as var (func: eq(name@en, "Jeff Goldblum")) @filter(has(director.film))
    
  p as shortest(from: uid(sp), to: uid(jq)) {
     ...predicates...
  }
    
  path(func: uid(p)) {
    uid
    name@.
  }     	     
}

Currently we need to specify which predicates to consider

This is most probably due for performance issues, but it makes it really hard to find random connections from A to B.

For instance, consider the query above and try to guess which predicates should go where ...predicates....

After a while, and with @danielmai's help, we ended up figuring out it was:

    director.film
    starring
    performance.actor

Multiple shortest queries overwrite the resulting path

Calls to shortest produce an output under _path_. Unfortunately, this means that if you have multiple calls to shortest the results will overwrite each other and only one will eventually be sent back in the response.

See this example:

{
  p as shortest(from: 0x22f1e0, to: 0x82ec65) {
    director.film
    starring
    performance.actor
  }

  q as shortest(from: 0x22f1e0, to: 0x5092b) {
    director.film
    starring
    performance.actor
  }
        
  path1(func: uid(p)) {
    uid
    name@.
  }    
 	     
  path2(func: uid(q)) {
    uid
    name@.
  }    
}

The output will contain a single _path_ corresponding to the last call to shortest.

{
  "extensions": {
    "server_latency": {
      "parsing_ns": 45165,
      "processing_ns": 114340665,
      "encoding_ns": 935863
    },
    "txn": {
      "start_ts": 22728120
    }
  },
  "data": {
    "path1": [
      {
        "uid": "0x22f1e0",
        "name@.": "Steven Spielberg"
      },
      {
        "uid": "0x22ca64",
        "name@.": "The Lost World: Jurassic Park"
      },
      {
        "uid": "0xf50c"
      },
      {
        "uid": "0x82ec65",
        "name@.": "Jeff Goldblum"
      }
    ],
    "path2": [
      {
        "uid": "0x22f1e0",
        "name@.": "Steven Spielberg"
      },
      {
        "uid": "0x51cd20",
        "name@.": "Bridge of Spies"
      },
      {
        "uid": "0x398f09"
      },
      {
        "uid": "0x5092b",
        "name@.": "Tom Hanks"
      }
    ],
    "_path_": [
      {
        "director.film": [
          {
            "starring": [
              {
                "performance.actor": [
                  {
                    "uid": "0x5092b"
                  }
                ],
                "uid": "0x398f09"
              }
            ],
            "uid": "0x51cd20"
          }
        ],
        "uid": "0x22f1e0"
      }
    ]
  }
}

Metadata

Metadata

Assignees

Labels

area/querylangIssues related to the query language specification and implementation.area/querylang/algosRelated to graph algorithms, such as k-shortest path.exp/expertDeeply technical issue not recommended to beginners.kind/enhancementSomething could be better.priority/P2Somehow important but would not block a release.status/acceptedWe accept to investigate/work on it.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions