Remove Duplicates from Results

I want to get a single predicate which is a string and look at how it is used in a type. All I want is to see a list of all the options where it is used.

GraphQL Schema

type MyType{
  ...
  status: String
}

GraphQL query

queryMyType @cascade {
  status
}

Or with DQL

queryMyType(func:has(MyType.status)) {
  status:MyType.status
}

This works, but as you can imagine if a bunch of them have the same status then it lists it multiple times. If there are only 10 use cases across 10K uses, I only want the 10, not the 10K. I do not care about any of the uids, I only want the list of unique statuses.

Note: This would be equivalent to the SQL: DISTINCT

1 Like

Given a graph that looks like this:

A -> M{status: 1, uid: 0xa}
B -> M{status: 1, uid: 0xb}

are they really distinct statuses? Perhaps the graph-ness should be taken into account and when inserting the UID of distinct status messages should be kept?

1 Like

Why not use @groupby?
Here are the DQL docs for it.
Maybe use it with @remote type in GraphQL API with @custom DQL.

2 Likes

There are when viewed from the user perspective as the end result:

{"data":{"queryMyType":[{"status":1},{"status":1}]}}

That is probably what I was looking for.

Kind of funny, conversing right now about how to do traditional GROUP BY with Dgraph to return data from separate trees. Talking about turning the traditional method around because we can get the groups and their data in one call instead of getting their groups and then getting the data in each group with it’s own query. More brain-washing to stop thinking traditional relational database logic. @chewxy, still thinking of the best answer to your question on how to switch from rDBs to graphDBs.

1 Like