fluree / core

Fluree releases and public bug reports
0 stars 0 forks source link

Issues with `@reverse` in queries #62

Closed aaj3f closed 7 months ago

aaj3f commented 7 months ago

Description

There are some bugs with using @reverse to qualify object -> subject relationships in queries. It mostly works when used in a select clause, like so

{
  "@context": {
    "ex": "http://example.org/",
    "parent": { "@reverse": "ex:child" }
  },
  "from": ...,
  "select": {
    "ex:andrew": ["*", { "parent": ["*"] }]
  }
}

Except that it seems to currently capture ALL upstream refs, not just the ones on ex:child. So I'm seeing that if did:fluree:123 points to ex:andrew on ex:user, then did:fluree:123 is returned under this parent reverse property (even though the ref is on ex:user and not ex:child)

The other bug, though, is that I can't use reverse-property terms in the where clause. So if I wanted to use the same parent term, but search only for entities that had a "parent" (i.e. entities that were the object of ex:child I cannot do this:

{
  "@context": {
    "ex": "http://example.org/",
    "parent": { "@reverse": "ex:child" }
  },
  "from": ...,
  "where": {
    "@id": "?s",
    "parent": "?x"
  },
  "select": { "?s": ["*"] }
}

Fluree instead seems to simply treat parent as if it were ex:child and not the reverse property of ex:child (so it returns all entities w/ a value on ex:child as opposed to all entities that ARE THE VALUE OF ex:child)

Implementation Details

It is worth mentioning that it's important that we test for this being able to work on @type in particular. Nexus has a need to issue a reverse query specifically for entities that are the object reference of @type. So we should guarantee that this particular query works (e.g. to return in its result set all entities that are the reference value of @type)

{
  "@context": {
    "isTypeObject": { "@reverse": "@type" }
  },
  "from": ...,
  "where": {
    "@id": "?class",
    "isTypeObject": "?x"
  },
  "selectDistinct": "?class"
}