This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-18
Channels
- # aws (1)
- # aws-lambda (1)
- # beginners (48)
- # boot (15)
- # cider (3)
- # cljs-dev (4)
- # cljsrn (4)
- # clojure (241)
- # clojure-chicago (1)
- # clojure-dusseldorf (12)
- # clojure-greece (41)
- # clojure-italy (3)
- # clojure-russia (16)
- # clojure-spec (7)
- # clojure-uk (34)
- # clojurescript (88)
- # community-development (9)
- # cursive (8)
- # data-science (55)
- # datomic (40)
- # devops (1)
- # emacs (20)
- # fulcro (19)
- # graphql (3)
- # hoplon (46)
- # luminus (11)
- # lumo (4)
- # off-topic (27)
- # onyx (26)
- # other-languages (25)
- # pedestal (2)
- # powderkeg (6)
- # re-frame (11)
- # reagent (4)
- # ring-swagger (17)
- # rum (4)
- # shadow-cljs (103)
- # spacemacs (14)
- # specter (6)
- # unrepl (21)
- # yada (1)
Can we get when an eid is created using entity
?
Or the only way is to use q
and get the :db/txInstant
?
@boldaslove156 unless the entity is a transaction, the latter
thanks! @potetm
@uwo so yo don’t have the value, you just want to find entities that share values for an attribute? you could group entities by values
(->> (group-by :v (seq (d/datoms db :aevt :ns/key)))
(map (fn [[v datoms]]
[v (map #(d/entity db (:e %)) datoms)]))
(into {}))
hehe. I was wondering if this was something that is expressible in datalog. I had thought of just dropping into sequence fns
datalog = bound values. you said not to bind it. [:find ?e ?v :where [?e :attr ?v]] otherwise 😛 group-by ?v ofc
@robert-stuttaford 😄 thanks
so is there anything wrong with this kind of query
[:find ?t1 ?t2 ?y
:where
[?e1 :movie/title ?t1]
[?e1 :movie/year ?y]
[?e2 :movie/year ?y]
[?e2 :movie/title ?t2]
[(not= ?e1 ?e2)]]
it doesn’t smell right to me, but I can’t say why. totally legit?not totally getting the point of the query? you want every possible pair of titles in a year?
you can use !=
(native operator, not clojure function) and maybe the query engine can use that info
basically my colleagues are trying to express a query like “find all entities that have the same value for attribute X and different values for attribute Y” and are writing queries like the above
And I’m the colleague 🙂 So imagine you have a bunch of Address entities with city, state, and zip (etc), and you want to query for “Show me all cities with more than one zip code,” how would you query for that?
(->> (d/q '[:find (count-distinct ?zip) ?c
:where
[?addr :city ?c]
[?addr :zip ?zip]]
db)
(remove (fn [[zipcount]] (== zipcount 1))))
Pure datalog without aggregation is the approach you have been doing. It looks like a self-join
(d/q '[:find ?c
:where
[?a1 :city ?c]
[?a2 :city ?c]
[(!= ?a1 ?a2)]
[?a1 :zip ?zip1]
[?a2 :zip ?zip2]
[(!= ?zip1 ?zip2)]]
db)
not sure which would be faster. Depends on how smart the query optimizer is about short-circuiting vs how fast it is simply to aggregate everything
Cool, thanks for the examples, I’m a longtime SQL coder just getting past the “Learn Datalog Today” stage so this is very helpful.
@U09R86PA4 My actual query is different from the simple example I gave, so I had to modify your queries to fit. The one with aggregation finished in about 1 sec, and the “self-join” I killed after about 8 minutes of running at 700% CPU.
you could use aggregation @manutter51
I have a bunch of data which is time-stamped. I want to count every occurance of a data-point, grouped by the day/month of the timestamp. Whats the datalog way to go about that?
@marshall, thanks, but how do I got about disregarding all information except date and month ?
Right. Then when I query [?x ?y] I only get one result and it doesnt allow [?x ?y] ..., or [?x ?y ...]. How do I get a list of filtered results ?
@marshall hi! I have a quick question on Datomic Cloud: will the pricing include a license to use? and around how much it will cost?
@laujensen I'll have to try a couple things. I might do the aggregations in app code and/or use nested or multiple queries depending on the data size. I'll try to get back to you tomorrow