This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-13
Channels
- # announcements (1)
- # babashka (29)
- # beginners (64)
- # calva (4)
- # cider (5)
- # cljs-dev (3)
- # cljsrn (2)
- # clojure (100)
- # clojure-australia (2)
- # clojure-conj (7)
- # clojure-dev (9)
- # clojure-europe (31)
- # clojure-germany (1)
- # clojure-nl (2)
- # clojure-uk (13)
- # clojured (2)
- # clojurescript (62)
- # community-development (2)
- # conjure (1)
- # cursive (21)
- # datomic (39)
- # events (2)
- # fulcro (7)
- # graalvm (24)
- # graalvm-mobile (11)
- # holy-lambda (3)
- # jobs (7)
- # lsp (15)
- # malli (26)
- # music (1)
- # nyc (2)
- # off-topic (18)
- # reagent (23)
- # reitit (5)
- # remote-jobs (1)
- # shadow-cljs (2)
- # tools-deps (26)
- # vim (6)
- # xtdb (17)
Hi there, question - can I destructure a map id in Crux? Say I have
:crux.db/id {:measurement-name "asw"
:classification :classification/moderate}
How would I go about getting only :classification
in a pull
query/some other method?in a query you can have a clause like [(get ?e :classification) ?class]
and then you can use ?class
like any other logic var, join, return etc.
right great that would work - always forget that ?e
will be the entity id and not the entire entity, thank you!
I tried with get
and sometimes you really want to do the destructuring in the pull
...it feels like more of a projection to me.
I am thinking about a subquery but I would definitely be open for a better idea
That's uncanny timing...I wrote an "idea" note on the project board like 5m before you sent this saying "extend pull syntax to traverse nested data"
I am unsure about the ergonomics of combining pull
and get
and subqueries as a workaround though. I guess some kind of construct
capability would make that kind of thing more plausible, as in https://github.com/Swirrl/matcha#construct
Hey @U899JBRPF thanks something like this
(crux/submit-tx node
[[:crux.tx/put
{:crux.db/id "asw"
:cohesic/type :measurement
:measurement/display-name "ASW"
:measurement/classified-ranges #{{:measurement-name "asw"
:classification :classification/normal}
{:measurement-name "asw"
:classification :classification/mild}}}]])
and then
(crux/submit-tx node [[:crux.tx/put
{:crux.db/id {:measurement-id "asw"
:classification :classification/normal}
:cohesic/type :classified-range}]])
(crux/submit-tx node [[:crux.tx/put
{:crux.db/id {:measurement-id "asw"
:classification :classification/mild}
:cohesic/type :classified-range}]])
I would like to get the measurement display name and all its :classification
within it.
follows my attempt(crux/q
(crux/db node)
'{:find [(pull ?measurement [:measurement/display-name
{:measurement/classified-ranges
[:crux.db/id
:classification/range]}])]
:in [?measurement-id]
:where [[?measurement :cohesic/type :measurement]
[(== ?measurement ?measurement-id)]]}
"asw")
but I don't have a way to go nested into crux.db/id
This is closer
(crux/q
(crux/db node)
'{:find [?display-name ?class ?range]
:keys [display-name classification range]
:in [?measurement-id]
:where [[?measurement :cohesic/type :measurement]
[(== ?measurement ?measurement-id)]
[?measurement :measurement/display-name ?display-name]
[?measurement :measurement/classified-ranges ?class-range]
[(get ?class-range :classification) ?class]
[?class-range :classification/range ?range]]}
"asw")
;;=>
#{{:display-name "ASW", :classification :classification/moderate, :range {:lower 15, :upper 17}}
{:display-name "ASW",
:classification :classification/severe,
:range {:lower 18, :upper 9223372036854775807}}
{:display-name "ASW",
:classification :classification/normal,
:range {:lower -9223372036854775808, :upper 11}}
{:display-name "ASW", :classification :classification/mild, :range {:lower 12, :upper 14}}}
but it seems to have dropped the notion of measurement entity and display name is everywhereit makes sense, the moment I abandon the pull
join I am actually abandoning the entity I am working against and start going nested
thanks for the example. Could you live with simply repeating the :classification
and :measurement
AVs as top-level AVs? (as well as keeping them in the ID map)
@U899JBRPF side question, do you have any input around LMDB? Would there be any notable difference with my dataset size?
Sorry, I somehow missed seeing this thread. LMDB is a fine choice, and it will be perceptibly faster for (uncached) reads and slower for writes at pretty much any scale, I think
We have more limited production experience with LMDB, but everything anecdotally suggests it's very low-maintenance
I tried with get
and sometimes you really want to do the destructuring in the pull
...it feels like more of a projection to me.
I am thinking about a subquery but I would definitely be open for a better idea