Fork me on GitHub
#datomic
<
2023-03-02
>
icemanmelting14:03:37

Hi guys, if I have an entity that references another entity with a cardinality of many, how can I match multiple references in the same query (and clause), to make sure that a parent entity actually, for sure, references all those child entities? {:book/chapters [[:chapter/id 1] [:chapter/id 2] [:chapter/id 3]]} How would the query look like, where I want to make sure that a book has chapter 1 and 3?

favila15:03:54

Another option is subqueries or calling a function that does the check

favila15:03:35

E.g.

[:find ?book
  :in $ ?chapter-ids
  :where
  [(count ?chapter-ids) ?ch-count]
  [?book :book/chapters]
  [(q '[:find ?chapter-id
        :in $ ?book [?chapter-id ...]
        :where
        [?book :book/chapters ?ch]
        [?ch :chapter/id ?chapter-id]] $ ?book ?chapter-ids)
   ?found-chapters]
  [(count ?found-chapters) ?found-ch-count]
  [(= ?ch-count ?found-ch-count)]]

favila15:03:46

or you can do it in the query result:

favila15:03:50

(let [chapters #{1 2 3}]
  (-> (d/q '[:find ?book (set ?chapter-id)
             :in $ [?chapter-id ...]
             :where
             [(count ?chapter-ids) ?ch-count]
             [?book :book/chapters ?ch]
             [?ch :chapter/id ?chapter-id]]
           db chapters)
      (filter (fn [[_ chapters-found]] (= chapters chapters-found)))))

favila15:03:59

(probably faster with count than set comparison)

icemanmelting18:03:19

Thanks, I ended up using the subquery with counts

icemanmelting18:03:27

another tool for my belt 😄

icemanmelting14:03:30

Another thing is related to filters, I am using Datomic on prem, and it seems that in the documentation, d/filter is supported, but my client doesn’t seem to contain that function. Any other way of filtering the database to get the data that corresponds to a single owner? Like it is described here: https://youtu.be/7lm3K8zVOdY?t=1059

joshkh15:03:55

we recently upgraded to Datomic Cloud 990-9202 and shortly after started seeing these alerts in CloudWatch, which we haven’t seen before:

{
    "Msg": "Message too large for CloudWatch Logs",
    "Type": "Alert"
}
is this something to worry about? thanks!

jaret17:03:57

Hi @U0H46T23C, so before 990-9202 we discovered that if a cast log message via Cloudwatch API Message exceeds the Cloudwatch limit of 262144 bytes, the log API call fails and the InvalidParameterException and was silently dropped. With 990-9202 we JSONified the messages and if its too large to be logged we replaced it with this body. So the fact you are seeing this means you have something you are casting which has a large result that exceeds the byte limit above. This can be unintentional or intentional. For example, we found these messages were missing from cast because we had a test that just returned a large result and after a certain point we stopped seeing it in the log. I hope this helps, but you should take a look at your cast messages to determine if any of them are possibly returning large results.