This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-20
Channels
- # babashka (36)
- # beginners (26)
- # calva (1)
- # clj-kondo (10)
- # clojure (94)
- # clojure-europe (7)
- # clojure-uk (16)
- # clojurescript (5)
- # conjure (6)
- # data-science (8)
- # datomic (24)
- # events (1)
- # fulcro (11)
- # funcool (1)
- # graalvm (6)
- # malli (18)
- # nrepl (5)
- # off-topic (13)
- # parinfer (3)
- # reagent (3)
- # reitit (6)
- # shadow-cljs (14)
Hi, I've been trying do find a way to do a left join for last three days and I finally decided to ask for help 😅 How can I get all owners and their pets even if they don't currently have a pet?
[:find ?owner-name ?pet-name
:where [?owner :owner/name ?owner-name]
[?owner :owner/pets ?pet]
[?pet :pet/name ?pet-name]]
You could to use an or-join
[:find ?owner-name ?pet-name
:with ?data-point
:where [?owner :owner/name ?owner-name]
[?owner :owner/pets ?pet]
[?pet :pet/name ?pet-name]
(or-join [?owner-name ?pet-name ?data-point]
(and [(identity? ?owner-name) ?data-point)
(and [(identity? ?pet-name) ?data-point)]
I guess something like this should work, although I don't have datomic installed right now to confirm
find all owners and pull the results?
Is there a way to do it in "one trip" or am I making a conceptual mistake here?
@joaovitorfernandes2 as a rule of thumb, I suggest using where clauses for filtering and pull for pulling data (that may or may not exist)
[:find (pull ?owner [:owner/name {:owner/pets [:pet/name]}])
:where [?owner :owner/name _]]
So, you could use get-else
in the where clause to optionally find pets, but that only makes sense if you then want to filter with additional rules (e.g. if the owner has a pet, one of the pets names need to be "Rex")When you want conditional matching, you need to add a datalog rule (or one of the sugar syntaxes - e.g. or
)
Thank you so much! Yesterday I tried to use pull but I didn't knew I could nest maps in there! Again, thank you!
@joaovitorfernandes2 Technically, that is not a nested map, but the notation for doing a join. I recommend checking out the pull docs for the kinds of built-in features you can take advantage of: https://docs.datomic.com/on-prem/pull.html The syntax has been re-used in other libraries (e.g. it is the basis for https://github.com/edn-query-language/eql and used by libraries such as Fulcro and Pathom, among others)
@joaovitorfernandes2 I think you can use get-else
for this: https://docs.datomic.com/cloud/query/query-data-reference.html#get-else
The union happens on [?owner :owner/pets ?pet]
and get-else
doesn't support cardinality-many attributes 😣
I'm seeing some memcached/item-too-large
logs when integrating memcached (same with valcache), could I be missing some required config?
You have segments which are too large to cache. This is not configurable. Probably you have some large string or binary values
does retraction affect the storage of large strings in the segments or do those stay for good?
I'm going to try excising, though I remember reading that it's not made to reduce the size of stored data necessarily
It’s not, but if you have a too-large value that’s the only way to ensure it’s not written to segments again