Skip to content

Instantly share code, notes, and snippets.

@refset
Last active September 13, 2021 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refset/357699aeeb59d605f0d005bf65f672aa to your computer and use it in GitHub Desktop.
Save refset/357699aeeb59d605f0d005bf65f672aa to your computer and use it in GitHub Desktop.
av-scan.clj
(let [n (xt/start-node {})
_ (xt/await-tx n (xt/submit-tx n [[::xt/put {:xt/id 0 :k 0}]
[::xt/put {:xt/id 1 :k 0}]
[::xt/put {:xt/id 2 :k 0}]
[::xt/put {:xt/id 3 :k 1}]
[::xt/put {:xt/id 4 :k 2}]
[::xt/put {:xt/id 5 :k 2}]
[::xt/put {:xt/id 6 :k 3}]]))]
(with-open [r (xt/open-q (xt/db n)
'{:find [v]
:where [[_ :k v]]})]
(take 10 (iterator-seq r)))
;;=> ([0] [0] [0] [1] [2] [2] [3])
;; ideally this might just return a scan over AV, but XT isn't doing that today (2021-09-11)
;; it is potentially a optimisation/heuristic we could support in future
;; raw access to AV is possible anyway though
(with-open [db (xt/open-db n)]
(with-open [is (db/open-index-snapshot (:index-store db))]
(doall (map xtdb.codec/decode-value-buffer (take 10 (xtdb.db/av is :k nil))))))
;;=> (0 1 2 3)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment