This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-05
Channels
- # aws (12)
- # babashka (30)
- # beginners (294)
- # calva (98)
- # clj-on-windows (3)
- # clojure (48)
- # clojure-europe (31)
- # clojure-italy (8)
- # clojure-nl (2)
- # clojure-uk (11)
- # clojurescript (58)
- # conjure (1)
- # events (1)
- # fulcro (35)
- # graalvm-mobile (2)
- # jobs (8)
- # lsp (11)
- # malli (25)
- # off-topic (33)
- # pathom (24)
- # pedestal (1)
- # polylith (15)
- # re-frame (7)
- # reitit (10)
- # releases (8)
- # remote-jobs (2)
- # sci (3)
- # shadow-cljs (79)
- # spacemacs (10)
- # sql (17)
- # tools-deps (17)
- # vim (4)
- # xtdb (11)
Hi there, I would I unify against a set?
I am trying to use contains?
but it does not seem to work ... maybe because I am using it as predicate?
(crux/q
(crux/db node)
'{:find [(pull ?range [:crux.db/id {:reference-range-set/_ranges [:crux.db/id :reference-range-set/state]}])]
:keys [reference-range]
:where [[?range :reference-range/classifications ?cs]
(contains? ?cs :classification/normal)]})
:reference-range/classifications
contains a set
this is the data
[:crux.tx/put
{:crux.db/id {:measurement-name "ASW"}
:cohesic/type :reference-range
:reference-range/mean 10
:reference-range/standard-deviation 1
:reference-range/classifications #{{:classification :classification/borderline
:range [:< 11]}
{:classification :classification/mild
:range [12 14]}
{:classification :classification/moderate
:range [15 17]}
{:classification :classification/severe
:range [:>= 18]}}}]
this also returns an empty set of results
(crux/q
(crux/db node)
'{:find [(pull ?range [:crux.db/id {:reference-range-set/_ranges [:crux.db/id :reference-range-set/state]}])]
:keys [reference-range]
:where [[?range :reference-range/classifications ?cs]
[?cs :classification classification/normal]]})
Hi - the contains?
predicate needs to sit inside a one-element vector (indicating a clause), as in
(crux/q
(crux/db node)
'{:find [(pull ?range [:crux.db/id {:reference-range-set/_ranges [:crux.db/id :reference-range-set/state]}])]
:keys [reference-range]
:where [[?range :reference-range/classifications ?cs]
[(contains? ?cs :classification/normal)]]})
this second version you suggested won't work because Crux's Datalog doesn't index beyond the top level of attribute-value (i.e. the maps in the set are opaque values that can't be traversed with triples clauses - you can do things with get
/ get-in
if needed though, or you could given the maps their own IDs and submit them independently)
(crux/q
(crux/db node)
'{:find [(pull ?range [:crux.db/id {:reference-range-set/_ranges [:crux.db/id :reference-range-set/state]}])]
:keys [reference-range]
:where [[?range :reference-range/classifications ?cs]
[?cs :classification classification/normal]]})
Oh I see now, yeah I was thinking that I was missing something quite fundamental there 😄 Thanks a lot @U899JBRPF
FWIW that contains?
example also returns an empty set
cause I have to check the :classification
key for equality
ahh, sorry, yeah I got confused there but something like this would work without having to submit nested docs
(crux/q
(crux/db node)
'{:find [(pull ?range [:crux.db/id {:reference-range-set/_ranges [:crux.db/id :reference-range-set/state]}])]
:keys [reference-range]
:where [[?range :reference-range/classifications ?cs]
[(get ?cs :classification) ?c]
[(= ?c :classification/normal)]]})