Fork me on GitHub
#xtdb
<
2021-04-11
>
mac20:04:24

Is there an equivalent to group by in crux or an approach to achieving the same effect?

refset21:04:12

Yep 🙂 you can use aggregates to do this: https://opencrux.com/reference/21.04-1.16.0/queries.html#find-aggregate For example, this TPC-H uses group-by in the original SQL: https://github.com/juxt/crux/blob/9c7771e2fc40807592bd8dba65b21b1e9e18e8a2/crux-sql/test/crux/tpch_test.clj#L35-L56 And after we translated it to Datalog, see how it is now implicitly defined by use of aggregates in the :find https://github.com/juxt/crux/blob/9073b6ff85ffe49019026f41a7b0e01831da349e/crux-test/src/crux/fixtures/tpch.clj#L118-L142

mac07:04:13

Thanks, would this permit me to group docs into vectors?

refset08:04:36

Probably, although I'm struggling to think of an example(!), do you have one to hand? (feel free to DM me if it's sensitive)

refset08:04:38

If necessary you can use a predicate, subquery or custom aggregate to achieve pretty much anything