Fork me on GitHub
#xtdb
<
2020-10-29
>
emil0r22:10:23

Any way to use an or in a datalog query in crux?

dominicm22:10:17

Or is supported, yeah. So are rules.

emil0r22:10:20

Right… falls under predicates. Slightly tricky to do an or clause

dominicm22:10:05

No, don't think it falls under predicates. There's first class or support

emil0r22:10:38

That one works for me

emil0r22:10:29

That one breaks

emil0r22:10:45

There are no clear examples in the docs from what I can see how an or clause would look like

Jacob O'Bryant22:10:08

You might need to use or-join, e.g.

(or-join [?e s1 s2]
  [?e :data/sex s1]
  [?e :data/sex s2])

emil0r22:10:37

Is this documented?

Jacob O'Bryant22:10:44

Kind of--the https://www.opencrux.com/reference/queries.html has a link to the https://github.com/juxt/crux/blob/master/crux-test/test/crux/query_test.clj which you can search for or, or-join, not etc. I think I saw it mentioned that those features are undocumented so far because they're still considered experimental (someone correct me if I'm wrong).

emil0r22:10:49

OK. Thanks for the heads up

Jacob O'Bryant22:10:44

anecdotally, I have found that avoiding or/`or-join` when possible has made my queries significantly faster, fyi

Jacob O'Bryant22:10:42

e.g. sometimes I'll separate a query into two separate queries, where each query has one branch of the or

emil0r22:10:48

Looks like it didn’t like the references to the args sent in

emil0r22:10:59

Putting in strings instead made the query work

emil0r22:10:44

OK. Having predicates available directly into queries seems much more exciting though