HAS_REFINEMENTS

HAS_REFINEMENTS computes whether a particular attribute has non-implicit refinements in the current navigation state.

The syntax of the HAS_REFINEMENTS function is:
HAS_REFINEMENTS(<attribute>)
where attribute is a Dgraph attribute (of any data type) in a collection.

In particular, HAS_REFINEMENTS determines if a specific attribute has the same value for every record in a group. If so, then the attribute should be able to return actual refinement values.

Return values

If attribute is an atomic (single-assign) type, the HAS_REFINEMENTS return behavior is:
  • If attribute is NULL for all rows in the group, HAS_REFINEMENTS returns NULL.
  • If attribute the same (non-NULL) value for all rows in the group, HAS_REFINEMENTS returns FALSE.
  • Otherwise (attribute is a mix of values, possibly but not necessarily including NULLs), HAS_REFINEMENTS returns TRUE.
If attribute is a set (multi-assign) type, the HAS_REFINEMENTS return behavior is:
  • If attribute is the same set for all rows in the group, HAS_REFINEMENTS returns FALSE. This includes the in which attribute is the empty set for all rows in the group.
  • Otherwise, HAS_REFINEMENTS returns TRUE.

Note that although HAS_REFINEMENTS tells you if a particular attribute has non-implicit refinements, it does not tell you what they actually are nor does it actually return the refinement values.

HAS_REFINEMENTS example

In this example, HAS_REFINEMENTS is used to determine whether the ACCT_FIRM attribute has available refinements:
RETURN Result AS
SELECT
  HAS_REFINEMENTS(ACCT_FIRM) AS Refs
FROM CorpData
GROUP

In this case, the query returns true, which means that the attribute has available non-implicit refinements.

Treating empty sets like NULLs

If you want HAS_REFINEMENTS to treat empty sets like NULLs, then you can add a per-aggregate WHERE clause to the HAS_REFINEMENTS aggregator, as in this example (x is a multi-assign attribute):
RETURN Result AS
SELECT
  HAS_REFINEMENTS(x) WHERE (x IS NOT EMPTY) AS Refs
FROM CorpData
GROUP
With this syntax, the HAS_REFINEMENTS return behavior is:
  • If x is the empty set for every row in the group, then HAS_REFINEMENTS(x) WHERE (x IS NOT EMPTY) is NULL.
  • If x is the same non-empty set value for every row in the group, then HAS_REFINEMENTS(x) WHERE (x IS NOT EMPTY) is FALSE.
  • Otherwise, x is a mix of different sets (possibly but not necessarily including the empty set), and HAS_REFINEMENTS(x) WHERE (x IS NOT EMPTY) is TRUE.

For more information on per-aggregate WHERE clauses, see Per-aggregation filters.