How to implement DISTINCT in a custom aggregate

We've built a custom aggregate (basically a special SUM) to handle one of our special cases which works well.

But we've found a situation where we need to be able to specify DISTINCT on the aggregate as we're getting double counting - we've confirmed using the builtin SUM (DISTINCT ?x).

There's nothing I can find that documents how to do that (lots of trial and error creating the custom aggregate in the first place :slight_smile: )

Any pointers would be much appreciated.

Hi Chris,

It looks like there's an issue with handling the DISTINCT keyword inside custom aggregates, do you also get a parsing error for that? I will open a support ticket.

For now it looks like your only option is to de-dup inside your aggregate, that is, inside the aggregate method if your class inherits from AbstractAggregate. This is sub-optimal, of course, since it'll use Java heap instead of Stardog's native data structures, like hash sets, which can spill data over to disk, so we'll need to look into that.

Thanks for letting us know,

Thanks Pavel - yes I do get a parse error if I try and use that keyword.
I'll investigate if it's worth trying to de-dup myself.
Might be easier to wait & see if you can support this in a later version of Stardog.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.