friend
edge between two nodes may have a Boolean property of
close
friendship. Facets can also be used as weights
for edges.
Though you may find yourself leaning towards facets many times, they should not
be misused. It wouldnβt be correct modeling to give the friend
edge a facet
date_of_birth
. That should be an edge for the friend. However, a facet like
start_of_friendship
might be appropriate. Facets are however not first class
citizen in Dgraph like predicates.
Facet keys are strings and values can be string
, bool
, int
, float
and
dateTime
. For int
and float
, only 32-bit signed integers and 64-bit floats
are accepted.
The following mutation is used throughout this section on facets. The mutation
adds data for some peoples and, for example, records a since
facet in mobile
and car
to record when Alice bought the car and started using the mobile
number.
First we add some schema.
name
, mobile
and car
of Alice gives the same result as without
facets.
@facets(facet-name)
is used to query facet data. For Alice the
since
facet for mobile
and car
are queried as follows.
@facets
.
<>
when
querying. This is similar to predicates. See
Predicates i18n for more info.
<>
βs:
orderasc
and orderdesc
are
not allowed as alias as they have special meaning. Apart from that anything else
can be set as alias.
Here we set car_since
, close_friend
alias for since
, close
facets
respectively.
friend
is an edge with facet close
. It was set to true for
friendship between Alice and Bob and false for friendship between Alice and
Charlie.
A query for friends of Alice.
close
with @facets(close)
.
friend
, facets go to the corresponding child under the key
edge|facet. In the above example you can see that the close
facet on the edge
between Alice and Bob appears with the key friend|close
along with Bobβs
results.
car
and it has a facet since
, which, in the results, is part of
the same object as Bob under the key car|since. Also, the close
relationship
between Bob and Alice is part of Bobβs output object. Charlie does not have
car
edge and thus only UID facets.
@facets(<facetname>)
to the
query.
AND
, OR
and NOT
.
rating
which is a facet.
close
and relative
.
int
and float
can be assigned to variables and thus the
values propagate.
Alice, Bob and Charlie each rated every movie. A value variable on facet
rating
maps movies to ratings. A query that reaches a movie through multiple
paths sums the ratings on each path. The following sums Alice, Bob and Charlieβs
ratings for the three movies.
r
is a map from movies to the sum of ratings on edges in the
query reaching the movie. Hence, the following does not correctly calculate the
average ratings for Alice and Bob individually --- it calculates 2 times the
average of both Alice and Bobβs ratings.