Fork me on GitHub
#datomic
<
2017-09-27
>
Ben Hammond10:09:40

I was hoping to pass a variable sample size in to datalog sample function. But it's not having it. Is there anything obvious I am doing wrong ?

(d/q '[:find (sample ?size ?id) .
       :in $ ?size
       :where [_ :myns/main-id ?id]]
     (d/db (d/connect "datomic:"))
     1024)

Ben Hammond10:09:14

java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number

Ben Hammond10:09:54

I could beat it to death with (defmacro

Ben Hammond10:09:25

but I'd rather not if I can avoid it

Ben Hammond10:09:47

perhaps its a hint that sample sizes are best hardcoded

dominicm12:09:35

(d/q (concat [:find] (list 'sample 1024 '?id) '[:where [_ :myns/main-id ?id])) 😂

souenzzo13:09:28

I installed one datomic function to run as a "transaction function" Then I "overinstalled" it. On (d/with db [[:my-fn]]) it runs the new version. On (d/transact conn [[:my-fn]]) runs the older version...

souenzzo13:09:45

(datomic+dynamo transactor)

favila14:09:43

@souenzzo you should get a reproducible test case and report to datomic

favila14:09:16

are you sure the new tx fn was actually transacted not d/with-ed?

souenzzo14:09:48

On (d/pull db '[*] :my-fn) I get the new version.

favila14:09:15

I'm asking if db isn't the result of other d/withs rather than directly from (d/db conn)

favila14:09:36

just double-checking

souenzzo14:09:33

I finded. requires behaves like to-many My wrong version was with 2 requires (one invalid require). Then I made a new one with just one require. But it still trying to import the wrong require

souenzzo14:09:22

(let [db-uri "datomic:"
      conn (do (d/create-database db-uri)
               (d/connect db-uri))
      fn-1 {:db/ident :my/fn
            :db/fn    (d/function {:lang     :clojure
                                   :requires '[[foo.bar] [datomic.api :as d]]
                                   :code     '(do "same-code")})}
      {db-1 :db-after} @(d/transact conn [fn-1])
      fn-2 {:db/ident :my/fn
            :db/fn    (d/function {:lang     :clojure
                                   :requires '[[datomic.api :as d]]
                                   :code     '(do "same-code")})}
      {db-2 :db-after} @(d/transact conn [fn-2])
      fn-3 {:db/ident :my/fn
            :db/fn    (d/function {:lang     :clojure
                                   :requires '[[datomic.api :as d]]
                                   :code     '(do "not-the-same")})}
      {db-3 :db-after} @(d/transact conn [fn-3])]
  {:fn-1 (:requires (:db/fn (d/entity db-1 :my/fn)))
   :fn-2 (:requires (:db/fn (d/entity db-2 :my/fn)))
   :bug? (= (:requires (:db/fn (d/entity db-1 :my/fn)))
            (:requires (:db/fn (d/entity db-2 :my/fn))))
   :fn-3 (:requires (:db/fn (d/entity db-3 :my/fn)))})
=>
{:fn-1 [[foo.bar] [datomic.api :as d]]
 :fn-2 [[foo.bar] [datomic.api :as d]]
 :bug? true
 :fn-3 [[datomic.api :as d]]}

favila15:09:34

@souenzzo tx-2 didn't actually do any work

favila15:09:38

look at the tx-data

favila15:09:02

that seems like a datomic bug to me

favila15:09:30

somehow the txor thinks the function hasn't changed, so no new datoms are asserted

favila15:09:56

the functions don't compare equal in clojure or using query comparator, so I'm not sure what's up

favila15:09:57

:lang also does not cause a change

favila15:09:23

checking each key now

souenzzo15:09:55

I'm trying to find/recover my password at http://receptive.io 😄

favila15:09:23

(let [db-uri "datomic:"
      conn   (do (d/delete-database db-uri)
                 (d/create-database db-uri)
                 (d/connect db-uri))
      {tx-1 :tx-data} @(d/transact conn [{:db/ident :my/fn
                                          :db/fn    (d/function {:lang     :clojure
                                                                 :requires '[[foo]]
                                                                 :code     '(do "same-code")})}])
      {tx-2 :tx-data} @(d/transact conn [{:db/ident :my/fn
                                          :db/fn    (d/function {:lang     :clojure
                                                                 :requires '[[bar]]
                                                                 :code     '(do "same-code")})}])]
  (assert (> (count tx-2) 1)))

favila15:09:25

smaller test case

favila15:09:24

:imports is also ignored

souenzzo15:09:40

It should just compare :code

favila15:09:35

I think the transactor, when comparing old and new fn values, is only looking at :lang and :code and ignoring :requires and :imports

favila15:09:37

this case also fails:

favila15:09:39

(let [db-uri "datomic:"
      conn   (do (d/delete-database db-uri)
                 (d/create-database db-uri)
                 (d/connect db-uri))
      {tx-1 :tx-data} @(d/transact conn [{:db/ident :my/fn
                                          :db/fn    (d/function {:lang     :clojure
                                                                 :imports  '[java.net.URI]
                                                                 :code     '(do "same-code")})}])
      {tx-2 :tx-data} @(d/transact conn [{:db/ident :my/fn
                                          :db/fn    (d/function {:lang     :clojure
                                                                 :imports  '[java.util.UUID]
                                                                 :code     '(do "same-code")})}])]
  (assert (> (count tx-2) 1)))

favila15:09:10

:params changes also seem fine

favila15:09:18

so :imports and :requires are ignored

favila15:09:23

that's the bug

souenzzo15:09:50

bug #2 - Can't login/recover my password in http://receptive.io

favila15:09:43

receptive isn't where you go, it's zendesk

favila15:09:51

receptive is for the feature requests

timgilbert18:09:02

Say, just out of curiosity has anybody managed to get datomic to run with localstack? https://github.com/localstack/localstack