Fork me on GitHub
#xtdb
<
2022-02-13
>
match3719:02:00

when I have a collection input variable being used in not clause, seems it only check one value in the collection. Below query still returns entities with attribute :tag8 with value tag8-9. If I change the arg to only has tag8-9, results exclude those. Appreciate for suggestions! Example query:

(xt/q (xt/db node) '{:find  [(pull v? [*]) tag8?]  :in  [ [arg-tag8s-0 ...] ]  :where  [[v? :x/type :v]  [(get-attr v? :v/tag8 "") [tag8? ...]] (not  [v? :v/tag8 arg-tag8s-0])]   :limit 10}  ["tag8-8" "tag8-9"])

dvingo03:02:05

I played around with this for a minute and I think there are two issues: one is query will return a document if it has tags that do not overlap with the input vector (instead of checking for all), and the second issue is that it seems :limit 10 changes the semantics of the query somehow. I changed the input to pass a set and am checking directly with a predicate. So this query returns all documents that contain none of the supplied tags:

(xt/submit-tx xtdb-node (mapv #(do [::xt/put %])
                            [{:xt/id 1 :x/type :v :v/tag8 ["tag8-8" "tag8-9"]}
                             {:xt/id 2 :x/type :v :v/tag8 ["not-tag8-8" "another"]}
                             {:xt/id 3 :x/type :v :v/tag8 ["not-tag8-8" "second-tag"]}] ) )

  (xt/q (xt/db xtdb-node) '{:find  [v?]
                            :in    [arg-tag8s-0]
                            :where [[v? :x/type :v]
                                    [v? :v/tag8 ?tags]
                                    (not [(contains? arg-tag8s-0 ?tags)])]
                            ;:limit 10
                            }
    #{"tag8-8" "tag8-9"})
=> #{[3] [2]}
if you include the :limit 10 however I get:
=> [[2] [2] [3] [3]]
which is still not 1 at least. I am not sure if that helps at all, but hope it does

match3704:02:00

Thanks! my doc's attribute :v/tag8 is actually a string instead of a vector. I'll play more and paste results here.

👍 1