Please support uid type for facet edge attributes

Moved from GitHub dgraph/4770

Posted by ChStark:

What you wanted to do

Modeling some entities as edges

Sometimes when modeling a domain on a graph database makes more sense that some entities are modeled as edges and not nodes, lets say the typical case of airports and flights, flights make more sense like edges since is connecting 2 node entities (airports) and the information they need is primitive like start times and end times, etc

Then if there is a need to include some extra information or pointers to another nodes, let’s say pilots, a whole refactor/export is needed.

What you actually did

Create a new type of node and refactor/export all the information just because I need to point one single attribute to a node

Why that wasn’t great, with examples

Its suppose that graph database should be flexible for schema evolution and changes, but this is not the case.

Any external references to support your case

If you go to ArangoDb’s docs you can see the make a clear distinction of this concept

And if you have the above distinction you can’t change easily between edges → nodes.

2 Likes

I think adding the type UID in facets is a valid request. Cuz it opens the possibility to do Hypergraphs. Ofcourse, the Hypergraph wouldn’t be “native” as facets aren’t first-class citizens. But it would be great for users who wanna explore the Hypergraph concepts.

What I have tried to reproduce here

{
  set {
    _:alice <name> "Alice" .
    _:alice <friend> _:bob (close=true, relative=false) .
    _:bob <name> "Bob" .
    _:charlie <name> "Charlie" .
  }
}

One thing to add is give blank nodes support in facets. e.g.:

{
  set {
    _:alice <name> "Alice" .
    _:alice <friend> _:bob (close=true, relative=false, Presentedby="_:charlie") .
    _:bob <name> "Bob" .
    _:charlie <name> "Charlie" .
  }
}

So what I did to add the UID was.

upsert {
  query {   
    q(func: uid(0x2735)) {
     v as uid
      name 
      friend @facets {
         b as uid
         name
      }
    }
  }

  mutation {
    set {
      uid(v) <friend> uid(b) (close=true, relative=false, Presentedby=0x2737) .
    }
  }
}

Also, another good way would be

upsert {
  query {
    
    CH as varg(func: eq(name, "Charlie"))
    
    q(func: uid(0x2735)) {
     v as uid
      name 
      friend @facets {
         b as uid
         name
      }
    }
  }

  mutation {
    set {
      uid(v) <friend> uid(b) (close=true, relative=false, Presentedby=uid(CH)) .
    }
  }
}

Worth to mention

Dgraph converts the UID to Hex. In my case it had converted 0x2737 to 10039

The Final Facet format with UID type.

{
   "data": {
      "q": [
         {
            "uid": "0x2735",
            "name": "Alice",
            "friend": [
               {
                  "name": "Bob",
                  "friend|Presentedby": {
                     "uid": "0x2737"
                  },
                  "friend|close": true,
                  "friend|relative": false
               }
            ]
         }
      ]
   }
}
1 Like

Our team is trying to create a hypergraph to represent repeated consistent relationships between nodes. I know we can do this in Neo4J, but cost is an issue here, especially since this is a PoC. A UID feature for the edge is essential - Is there any workaround for this right now? I guess we could create a node that is an ‘edge’, but it makes traversal strange.

@MichelDiz and team, did you give this issue any more thought?

In the RDF world, RDF-star is getting more traction, supporting a fuller range of values for edge properties / facets:

https://blog.liu.se/olafhartig/tag/rdf-star/
https://w3c.github.io/rdf-star/cg-spec/2021-04-13.html

As a possible workaround, could one have a convention such as #id that would somehow automatically retrieve linked nodes?

{ 
    id: Norway,
    yearOfIndependence: 1905,
    yearOfIndependence|source : "id#wikipedia" 
}

If facetValue.beginsWith(id#):

facetGetLinkedNode( func(id(wikipedia)) ) {
   id...
}

But I guess the more tricky part would be to keep this in sync if the ID/UID is removed/changed etc … Any ideas appreciated!

1 Like