This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-09
Channels
- # aleph (1)
- # announcements (7)
- # asami (1)
- # beginners (44)
- # calva (54)
- # cherry (24)
- # cider (6)
- # clj-kondo (19)
- # cljsrn (27)
- # clojure (119)
- # clojure-europe (61)
- # clojure-gamedev (38)
- # clojure-germany (7)
- # clojure-nl (1)
- # clojure-norway (104)
- # clojure-portugal (4)
- # clojure-spec (4)
- # clojure-uk (1)
- # clojurescript (38)
- # cursive (18)
- # datomic (11)
- # emacs (9)
- # events (1)
- # fulcro (4)
- # holy-lambda (7)
- # introduce-yourself (7)
- # jobs (1)
- # malli (6)
- # off-topic (4)
- # pathom (4)
- # pedestal (16)
- # podcasts-discuss (1)
- # polylith (27)
- # portal (17)
- # releases (2)
- # shadow-cljs (46)
- # squint (1)
- # xtdb (9)
I'm seeing unexpected query results when using a recursive rule on data that forms a loop. Example repro in thread. Am I doing something incorrectly? Another casualty of https://github.com/xtdb/xtdb/issues/1569 🙂
(def n (xt/start-node {}))
(def data
[;; loop
{:xt/id 1 :text "1" :child 2}
{:xt/id 2 :text "2" :child 3}
{:xt/id 3 :text "3" :child 2}
;; non-loop
{:xt/id 4 :text "4" :child 5}
{:xt/id 5 :text "5" :child 6}
{:xt/id 6 :text "6"}])
(xt/submit-tx n (mapv #(vector ::xt/put %) data))
(def rules
'[[(follow p c)
[p :child c]]
[(follow p c)
[p :child i]
(follow i c)]])
(defn q [parent]
(xt/q (xt/db n)
{:find '[e]
:in '[p]
:where '[[e :text] (follow p e)]
:rules rules}
parent))
(q 4) ;; ✔ #{[5] [6]}
(q 1) ;; ❌ #{[1] [2] [3] [4] [5] [6]}, expected: 2, 3
;; same situation with bounded rule (follow [p c])
;; this works as expected, returns: 2,3
(xt/q (xt/db n)
{:find '[e]
:where '[(follow 1 e)]
:rules rules})
Hey again 🙂 thanks for raising this. Does the indirection workaround I suggested in the comments resolve it for you?
Are you saying hi to me or to your issue nemesis 😁 It works in the above example but didn't work in my system. Maybe because there were more rules in that query – I'll dig into that later.
https://gist.github.com/zeitstein/6182a270def0baa1c202c70930762d3d expanding on above, trying to repro what I'm seeing in my system (queries with lucene). In the example: • works as expected when recursive rule does not operate on loop data • but also works as expected on loop data when recursive rule has first arg bounded • indirection workaround works, except when recursive rule has both args bounded.
If i'm using an xt/id like this {:foo "bar"}
, {:foo "spam"}
, how do I find all records, where :foo
is the key in the xt/id?
I tried this, but it doesn't seem to work:
(xt/q db '{:find [?e]
:where
[[?e :xt/id]
[(= :foo (first ?e))]
]})
Yeah, that was my next solution. I'll probably just do that and stop playing around 🙂