datahike

https://datahike.io/, Join the conversation at https://discord.com/invite/kEBzMvb, history for this channel is available at https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/datahike
grounded_sage 2020-03-10T19:14:29.018800Z

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)

grounded_sage 2020-03-10T19:56:12.021300Z

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) 

grounded_sage 2020-03-11T19:10:37.029700Z

This is the one I am working on. The one below was just sharing my enjoyment for datalog 🙂 @whilo

grounded_sage 2020-03-11T19:11:04.029900Z

Also above this one was another attempt to do an or join with an or pull kind of

whilo 2020-03-11T19:11:19.030100Z

This still has only one branch (the and one).

grounded_sage 2020-03-11T19:12:00.030300Z

I may have others where there is more.

grounded_sage 2020-03-11T19:12:16.030500Z

Like I have one dataset and I want to effectively enrich it with whatever else I can find.

grounded_sage 2020-03-11T19:18:13.030700Z

@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

whilo 2020-03-12T18:57:37.031900Z

(or-join [bindings ...] clause1 clause2) is how you define the alternative between clause1 and clause2.

grounded_sage 2020-03-10T21:07:05.023600Z

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)