Fork me on GitHub

The 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/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:


Thanks @U899JBRPF. That clears it up for me.

πŸ‘Œ 1

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
  [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!

πŸ™Œ 1

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 (which is currently linked to via the banner)

πŸ™Œ 1