The presentation introduces you to DGraph and explains about the data types, indexes, edges, facets and type of mutation using RDF Triples or JSON. Also, take through the GQL+/- functions, filters, connectives, reverse edges, facets and complex graph queries for DGraph using GQL+/-.
2. Agenda
● Brief Introduction to DGraph
● Data types in DGraph
● Indexes in DGraph
● Edges and Facets
● Mutation with RDF triples v/s JSON
● GQL+/- Functions
● GQL+/- Filters and Connectives
● GQL+/- with Reverse Edges, Facets and their Filters
3. Brief Introduction to DGraph
● DGraph is a scalable, distributed, highly available
and fast graph database.
● RDF Triple - Triple is any statement in form of
SPO, i.e. "subject/predicate/object", every part of
the triple has a URI associated with it.
● Schema - types of the predicates that are stored by
the DGraph.
● Mutation - Adding, deleting or updating data in
DGraph, Can be done using RDF triples or JSON.
● GQL+/- is based on Facebook’s GraphQL with
some addition and removal of features to get the
best feature rich language fit for graph databases.
4. Data Types in DGraph
● Following data types are supported by DGraph -
○ default
○ int
○ float
○ string
○ bool
○ dateTime
○ geo
○ password
5. Indexes in DGraph
● Data Type: int, float, bool and geo have only a default index
i.e. with tokenizers named int, float, bool and geo.
● For DateTime, there are 4 indexes, year (default), month, day
and hour.
● For String, following are the indexes:
Dgraph function Required index / tokenizer Notes
eq hash, exact, term, or fulltext The most performant index for eq is hash. Only use term or fulltext if you
also require term or full text search. If you’re already using term, there is
no need to use hash or exact as well.
le, ge, lt, gt exact Allows faster sorting.
allofterms, anyofterms term Allows searching by a term in a sentence.
alloftext, anyoftext fulltext Matching with language specific stemming and stopwords.
regexp trigram Regular expression matching. Can also be used for equality checking.
6. Edges and Facets
● A graph is comprised of “nodes” and “edges”. A node is
useless by itself, and a graph only makes sense when there
are a collection of nodes with edges connecting them.
● Edge - is a property which connects nodes / entities.
● Reverse Edges - The graph edges are unidirectional, but
sometimes modeling requires reverse edges, which is
specified in the schema using @reverse. The reverse edge of
anEdge is ~anEdge.
● Facets - are attributes over the edge in DGraph. Facets can
also be used as weights for edges.
● Note: Facets are however not first class citizen in Dgraph like
predicates.
7. Mutation with RDF Triples v/s JSON
● Adding predicate / property to a node / entity using RDF:
<_:node> <predicate> <value> .
● Adding predicate / property to a node / entity using JSON:
{“uid” : ”node”, “predicate”: “value”}
● Connecting nodes / entities with edge using RDF:
<_:node1> <edgeName> <_:node2> .
● Connecting nodes / entities with edge using JSON:
{“uid” : ”node1”, “edgeName”: {“uid” : ”node2”} }
● Adding facets on the edge using RDF:
<_:node1> <edgeName> <_:node2> (<predicate>=<value>) .
● Adding facets on the edge using JSON:
{“uid” : ”node1”, “edgeName”: {“uid” : ”node2”, “edgeName|predicate” : “value”} }
8. GQL+/- Functions
● Functions allow filtering based on properties of nodes or variables. Functions can
be applied in the query root or in filters.
● Note: Functions can only be applied to indexed predicates.
There are many functions in GQL+/-, the most basic or frequently used and important
ones are -
● has - Determines if a node has a particular predicate / property.
● uid - Filters nodes at the current query level to only nodes in the given set of UIDs
● eq - EqualsTo, filters all the nodes having the predicate and its value equals to the
passed one.
● In-equality - le, lt, ge, gt - LessThan, lessThan EqualTo, GreaterThan,
GreaterThan EqualTo - filters all the nodes having the predicate and its value as
per the function passed accordingly.
9. ● Filters are used to have multiple functions to fetch the desired
result only.
● Within @filter multiple functions can be used with boolean
connectives.
● Connectives: And, Or, Not - join multiple filters and can be
built into arbitrarily complex filters, eg.
○ A OR NOT B
● Note: NOT binds more tightly than AND which binds more
tightly than OR.
GQL+/- Filters and Connectives
10. ● Reverse Edge - are useful for backward traversing, i.e. when
we need to go back to node1 from node2 instead of from
node1 to node2.
● All Facets - to fetch / retrieve facets i.e. key value pairs
existing on the edge, we need to add @facets, which will fetch
all the predicates with value existing on the edge.
● Specific Facets - to fetch single or set of Facets, we can pass
like @facets(predicate1, …….., predicateN)
● Filters on Facets: function can be added over facets to fetch
specific data only like @facets(eq(predicate1, value)).
GQL+/- with Reverse Edge,
Facets & Filters