This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-12
Channels
- # announcements (76)
- # babashka (10)
- # beginners (39)
- # biff (2)
- # calva (51)
- # chlorine-clover (8)
- # cider (6)
- # clj-kondo (15)
- # clj-on-windows (13)
- # cljdoc (26)
- # cljs-dev (8)
- # clojure (196)
- # clojure-austin (17)
- # clojure-europe (36)
- # clojure-nl (4)
- # clojure-spec (8)
- # clojure-uk (2)
- # clojurescript (18)
- # community-development (4)
- # conjure (1)
- # core-typed (38)
- # cursive (5)
- # datalevin (17)
- # datomic (25)
- # docker (1)
- # events (2)
- # interop (2)
- # jobs (4)
- # kaocha (28)
- # lsp (22)
- # nyc (1)
- # off-topic (10)
- # pedestal (1)
- # portal (22)
- # re-frame (22)
- # react (10)
- # shadow-cljs (19)
- # spacemacs (7)
- # tools-deps (11)
- # vim (14)
- # xtdb (7)
The https://docs.xtdb.com/language-reference/datalog-queries/#find-aggregate say: > You can specify an aggregate function to apply to at most one logic variable. But then...
(let [n (xt/start-node {})]
(->> [{:xt/id 9878
:foo 1
:bar 1}
{:xt/id 9999
:foo 1
:bar 2}]
(map (fn [doc] [::xt/put doc]))
(xt/submit-tx n)
(xt/await-tx n))
(xt/q
(xt/db n)
'{:find [(sum foo) (sum bar)]
:where [
[x :foo foo]
[x :bar bar]]}))
; => #{[2 3]}
Looks like you can apply the sum
aggregate to more than one logical variable. Am I misunderstanding something or is this an error in the docs?Hey, IIRC I think this is instead alluding to the fact that you couldn't have (sum foo bar)
(a rather contrived example purely to demonstrate the difference!). That said, given the new projection expression feature in the beta release, maybe the statement in the docs is now invalid/confusing :thinking_face:
Hi, i am little bit stomped and would appreciate help. I'd like to make a query to use as kind of a fuzzy search across multiple attributes for given entity. So i team entity example
{
:team/external-id "123",
:team/name "The Little Bocks",
:team/aliases ["The Little Bocks"],
:xt/id #uuid "aa703f55-08fd-4149-bbf9-439db48f97f4"}
i'd like to have a query where i pass it term ro
and it returns this team -> solved using predicate function
but i would also like if i put aa703f
-> to get this entity because it matches id using same predicate function.
I tried having :where clauses like
[(or
[e :team/name n]
[e :xt/id id])
[(ns/basic-search n ?term)]
[(ns/basic-search id ?term)]]
But this throws an error
Or requires same logic variables: [[:term [:triple {:e e, :a :team/name, :v n}]] [:term [:triple {:e e, :a :xt/id, :v id}]]]
Because it makes sense.
So i am using wrong tool here. Can query like this even be made?
What should i be using in order to have this flexibility ?Hey, I think what you are describing you're after would look something like this (assuming you're using the -beta3
release at least - otherwise you may need some dummy variables):
[(or-join [e ?term]
(and [e :team/name n]
[(ns/basic-search n ?term)])
(and [e :xt/id id]
[(ns/basic-search id ?term)]))]
But just to confirm in case it isn't clear - this approach would imply a full scan of the database unless you add extra clauses (e.g. to constrain e
first), and therefore may not scale effectively as the data volumes increase.Woah that was super fast response! Thanks a lot for this!! I do have constraints it should cut down search to ~150 entities so i think it's alright. It should remain This is the version i am using
com.xtdb/xtdb-core {:mvn/version "1.19.0"}
i didn't see any -beta3 releases on github?
Am i missing something?
Btw query works as expected thanks a lot!Excellent, you're very welcome! βΊοΈ
-beta3
isn't shown on GitHub as we want to avoid cluttering up the official view of releases, but the beta artefacts are available via Maven, see details here https://discuss.xtdb.com/t/ann-1-21-0-beta3s-out/77 (which is currently linked to via the http://xtdb.com banner)