Fork me on GitHub
#datomic
<
2020-06-18
>
Ramon Rios07:06:34

Shoot, how should i start with free version instead?

dazld11:06:46

do you need persistence, or just want to play around?

dazld11:06:20

using an in-memory db is the easiest way to start playing with it, i think

souenzzo12:06:54

(d/connect "datomic:") 🙂

Ramon Rios12:06:05

I need to play around. Will use in a project and i want to have a hands on experience

Ramon Rios12:06:11

Thank you all : )

joshkh13:06:40

following up on a question i asked the other day, i am trying to pass the result of a query through a serialization library, and i am having trouble making sense of an error. upon def'ing the result i can see that it is a clojure.lang.PersistentVector

(def result (d/q ... db)
=> #'my-ns/result

(type result)
=> clojure.lang.PersistentVector
and a postwalk through the data structure shows only core java/clojure classes
(clojure.lang.PersistentVector
 clojure.lang.PersistentHashMap
 clojure.lang.MapEntry
 clojure.lang.Keyword
 clojure.lang.PersistentArrayMap
 java.lang.String
 java.lang.Boolean) 
however, when i pass result to the serialization library, i get a NotSerializableException for datomic.client.impl.shared.Db.
(sp/set bc "testkey" 120 result)
Execution error (NotSerializableException) 
at java.io.ObjectOutputStream/writeObject0 (ObjectOutputStream.java:1185).
datomic.client.impl.shared.Db
how is the datomic.client.impl.shared.Db class related to the result of the query?

favila13:06:45

Maybe metadata? Maybe your walking isn’t looking at every object?

favila13:06:04

what is your query and result? have you tried bisecting the result?

joshkh13:06:00

everything works as expected if i copy and paste the contents of result back in to the repl, so there's definitely something going on with the object itself

favila13:06:35

that sounds like metadata. does your serializer serialize metadata?

joshkh13:06:59

it does indeed. and the query result vector does have a nav protocol:

(meta result)
=>
#:clojure.core.protocols{nav #object[clojure.core$partial$fn__5839 0x613ebeb5 "clojure.core$partial$fn__5839@613ebeb5"]}

joshkh13:06:11

also, i wasn't able to remove the metadata from result :thinking_face:

joshkh13:06:00

(meta (vary-meta result dissoc clojure.core.protocols/nav))
=>
#:clojure.core.protocols{nav #object[clojure.core$partial$fn__5839 0x613ebeb5 "clojure.core$partial$fn__5839@613ebeb5"]}

favila13:06:17

it’s a keyword not a symbol

favila13:06:43

why not (with-meta result nil)?

joshkh13:06:15

yes, why not is a good question. thanks for the tip. 😉

favila13:06:50

there could still be metadata on nested objects. I didn’t know the client lib made results navigable and I don’t know how it works

favila13:06:17

this seems like something better solved in your serializer if possible

favila13:06:45

can it be customized or operate in meta/non-meta preserving modes?

joshkh13:06:03

favila, once again, thanks for your help. i shrugged off the metadata earlier when i saw only the nav protocol. but sure enough stripping it away solved the problem

joshkh13:06:17

(top level metadata, that is)

joshkh13:06:42

i actually need support for my own metadata so this works for me

favila14:06:04

“only the nav protocol” these are always live objects (functions) so I don’t expect them to be serializable ever

joshkh15:06:42

agreed, and i did find that while stripping the top level metadata worked in my one example, other query results had nested metadata that could not be serialised (as you suspected). for now it is a hobby project, so a simple postwalk to remove all metadata works with the least amount of effort, but i will explore the serialization library for a more solid solution.

ivana14:06:19

hello, can anyone explain me what I have to do to make this query work?

{:find '[[?e ...]]
 :in '[$ ?date-from ?date-to]
 :args [db date-from date-to]
 :where '[[?e :logistic/driver ?d]
          [?e :logistic/delivery-date ?date]
          (not [?d :driver/external? true])
          [(get-else $ ?e :logistic/completed #inst "2000") ?completed-date]
          (or
           (and [?e :logistic/state :logistic.state/incomplete]
                [(<= ?completed-date ?date-to)])
           [?e :logistic/state :logistic.state/active]
           (and (or [?e :logistic/state :logistic.state/completed]
                    [?e :logistic/state :logistic.state/failed])
                [(<= ?date-from ?completed-date)]
                [(<= ?completed-date ?date-to)]))]}

ivana14:06:20

the error is on or clause Assert failed: All clauses in 'or' must use same set of vars

ivana15:06:28

Moved all the and/or clauses to external function, and it works. I have no idea about theirs magic inside datomic

favila15:06:25

this has to do with whether a var should be unified with the outside of the rule or not

favila15:06:39

you can control this by using or-join and and-join instead and being explicit

favila15:06:21

invisibly, or is creating a rule, and each rule must unify to the same set of vars outside the rule

favila15:06:34

if you don’t specify the vars, it looks inside the rule to determine it

favila15:06:51

you’ll notice each clause of your or uses a different, non-overlapping set of vars

ivana15:06:23

Thanks. But it seems too complicated for me, looks like much simplier is to use an external function with predictable behavior...

Drew Verlee16:06:39

Is there a way to get datomic change log updates via some notification?

marshall16:06:41

@drewverlee you can subscribe to the Announcements topic on the datomic forum

Drew Verlee16:06:22

great thanks!