Fork me on GitHub
#datomic
<
2023-03-16
>
jasonjckn05:03:41

Is there a way to determine if a transactor is in standby ? i was thinking if 4334 is closed but it health checks/9999 ok but i’m worried the devil is in the details . ( In an automated way from the peer — of course i could view logs. )

jdkealy19:03:16

I have a query I'm trying to work but it doesn't quite make sense to me... I have an attr :session/students which is just a many ref Then I have a component called :session/student_sessions which has :student_session/student I'd like to find all upcoming sessions which have student_sessions that don't match the student roster. I've tried

(d/q
          '[:find ?e
            :in $ ?now ?future
            :where
            [?e :session/start_time ?st]
            [(> ?st ?now)]
            [(< ?st ?future)]
            (not [?e :session/cancelled true])
            [?e :session/students ?students]
            [?e :session/student_sessions ?sss]
            (not [?sss :student_session/student ?students])
            ] (db/_d) now date)
But it seems to just be matching any session that has more than one student.

favila19:03:36

This is all ?e where at least one ?sss lacks the ?student.

favila19:03:51

you want where no ?sss has the ?student? (i.e. the student has no sessions?)

jdkealy19:03:04

I want at least one session/student that is not in the :session/student_sessions => :student_session/student list

jdkealy19:03:08

This is what i end up having to do and it takes much longer

(->> (d/q
          '[:find ?e
            :in $ ?now ?future
            :where
            [?e :session/start_time ?st]
            [(> ?st ?now)]
            [(< ?st ?future)]
            (not [?e :session/cancelled true])
            [?e :session/students ?students]
            [?e :session/student_sessions ?sss]
            (not [?sss :student_session/student ?students])
            ] (db/_d) now date)
         (map first )
         (map db/by-id)
         (filter (fn [e]
                   (not=
                    (->> e :session/student_sessions  (map (fn [e]
                                                             (-> e
                                                                 :student_session/student
                                                                 :db/id
                                                                 ))) set)
                    (->> e :session/students (map :db/id) set))))
         (map :db/id))

favila19:03:28

you want to know sessions where a student in the session lacks any student_session?

favila19:03:54

the not needs to cover the last two clauses to get that

favila19:03:08

'[:find ?e
  :in $ ?now ?future
  :where
  [?e :session/start_time ?st]
  [(> ?st ?now)]
  [(< ?st ?future)]
  (not [?e :session/cancelled true])
  [?e :session/students ?student]
  (not-join [?e ?student]
            [?e :session/student_sessions ?sss]
            [?sss :student_session/student ?student])
  ]

favila19:03:06

which you can read as “if

[?e :session/student_sessions ?sss]
            [?sss :student_session/student ?student]
produces any results, drop the corresponding row(s) that match the ?e ?student join”

favila19:03:31

what you had was like (not-join [?sss ?student] [?sss :student_session/student ?student]) , which will drop if there is any ?sss that lacks the student, which is probably usually true, unless the student is taking every class offered

jdkealy19:03:39

oh wait... yes this works

jdkealy19:03:32

you're amazing 🙂

Brett Rowberry21:03:01

I have a really nice solution for getting data from PostgreSQL to Snowflake via Fivetran replication. How do people do this for Datomic Server or Cloud?

Henrique Prange23:03:28

You can use the Log API and the tx-range function to retrieve all transaction data in chronological order from Datomic Server or Cloud. You can fetch the required data from the log by specifying the desired range of transactions. You can use it to develop a connector integrating Datomic with Snowflake that continuously polls the transaction log for new updates and transforms it into a format that Snowflake supports. https://docs.datomic.com/cloud/time/log.html

Brett Rowberry04:03:24

> continuously polls the transaction log for new updates and transforms it into a format that Snowflake supports Yes, that sounds like what I’m after!