Fork me on GitHub
#datalevin
<
2023-08-22
>
kenny18:08:20

Is :xform supported on pull joins?

kenny18:08:41

From https://github.com/juji-io/datalevin/blob/c55574a8749eb5e4f787840301cede7b7f3f58dd/test/datalevin/test/pull_api.cljc#L547-L557, it seems like it should be, but I am not seeing it apply.

(defn effect
  [x]
  (prn x)
  (:effect x))
=> user/effect

;; Actual
(d/pull db
    '[{[:statement/effect :xform user/effect] [:effect]}]
    31)
=> #:statement{:effect {:effect :allow}}

;; Expected
(d/pull db
  '[{[:statement/effect :xform user/effect] [:effect]}]
  31)
{:effect :allow}
=> #:statement{:effect :allow}

kenny18:08:48

Interestingly, it actually will resolve the user/effect function. If I pass an unresolvable symbol, I get the expected “Cannot resolve symbol” error.

dvingo13:08:55

looks like it doesn't work if cardinality is one,

(d/pull
  (d/db-with (d/empty-db (str (java.nio.file.Files/createTempDirectory nil (into-array java.nio.file.attribute.FileAttribute [])))
               {:statement/effect
                {:db/valueType :db.type/ref
                 :db/cardinality :db.cardinality/many}})
    [{:statement/effect {:effect :allow}}])
  [{[:statement/effect :xform (fn [x] (prn x) x)] [:effect]}]
  1)
;; [{:effect :allow}]
=> #:statement{:effect [{:effect :allow}]}
vs:
(d/pull
  (d/db-with (d/empty-db (str (java.nio.file.Files/createTempDirectory nil (into-array java.nio.file.attribute.FileAttribute [])))
               {:statement/effect
                {:db/valueType :db.type/ref
                 :db/cardinality :db.cardinality/one}})
    [{:statement/effect {:effect :allow}}])
  [{[:statement/effect :xform (fn [x] (prn x) x)] [:effect]}]
  1)
=>  #:statement{:effect {:effect :allow}}
maybe this cond is exiting in an earlier branch for cardinality/one vs many? https://github.com/juji-io/datalevin/blob/c55574a8749eb5e4f787840301cede7b7f3f58dd/src/datalevin/pull_api.cljc#L121

Huahai14:08:36

Could you file an issue ?

Huahai00:10:27

This is fixed

😎 1