How do I do an or-join with an or pull. This FAILs but I’m sure it is something similar to this? The or in the pull expression doesn’t work I’m not sure how to do an optional pull.
(d/q '[:find (pull ?e [*]) (pull ?e1 [*]) (or (pull ?e2 [*]))
:where [?e :customer/address-id ?address-id]
[?e1 :address/address-id ?address-id]
(or-join [?address-id]
[?e2 :bank/address-id ?address-id])]
@conn)
Actually as much as I would like to know how to do an optional pull. This particular one I would also like to populate with default data when the values are missing.
(d/q '[:find (pull ?e [*]) (pull ?e1 [*]) ?name
:where
[?e :customer/address-id ?address-id]
[?e1 :address/address-id ?address-id]
(or-join [?address-id]
(and
[?e2 :bank/address-id ?address-id]
[(get-else $ ?e2 :bank/name "No Value") ?name]))]
@conn)
This is the one I am working on. The one below was just sharing my enjoyment for datalog 🙂 @whilo
Also above this one was another attempt to do an or join with an or pull kind of
This still has only one branch (the and
one).
I may have others where there is more.
Like I have one dataset and I want to effectively enrich it with whatever else I can find.
@whilo with the and
I’m not sure I fully undertsnad the or-join. It was basically there because I want to join the two which you can see with ?e2
(or-join [bindings ...] clause1 clause2) is how you define the alternative between clause1 and clause2.
I like how tight this other query became and that it saved me from having to do any excess work by doing a few pre-selecting joins. One thing I noticed is that when dropping the ?tr
matching and just having _
it caused significantly more processing. So I guess it helps to have something there for performance?
(d/q '[:find (pull ?tix [*]) ?date-time
:where
[_ :festival/festival-id ?festival-id]
[_ :event/festival-id ?festival-id]
[_ :event/event-id ?event-id]
[?tix :ticket/event-id ?event-id]
[?tix :ticket/transaction-id ?transaction-id]
[?tr :transaction/transaction-id ?transaction-id]
[?tr :transaction/datetime ?date-time]]
@conn)