Fork me on GitHub
#xtdb
<
2023-05-21
>
hifumi12310:05:48

I want to be able to get a vector out of an attribute that I assigned a vector. I have written the following code.

(xt/submit-tx node [[::xt/put {:xt/id (random-uuid)
                               :foo "bar"
                               :baz ["quux" "quux"]}]])
But the following query does not return a vector with two strings. Why not?
(xt/q (xt/db node) '{:find [?baz]
                     :where [[e :foo "bar"]
                             [(get-attr e :baz) ?baz]]})

refset12:05:52

Hey @U0479UCF48H all top-level collection values in the index are decomposed as if they were triples, so get-attr here can only return a set because positional information is not stored in the index. This means the only way to get the original vector out again is to use the entity API - you should be able to do this within the query like so:

(xt/q (xt/db node) '{:find [?baz]
                     :where [[e :foo "bar"]
                             [(xtdb.api/entity $ e) ?doc]
                             [(get ?doc :baz) ?baz]})

👍 3
thanks 2