Fork me on GitHub
#datomic
<
2016-09-20
>
kurt-yagram07:09:00

Is it possible with pull to pull all attributes only one level deep? Having a tree like data, , which contains many components, using pull, pulls the whole tree (which makes sense). However, I'd like to pull only one level deep. I could use attribute names, but since there may be a lot of them and the pull shouldn't depend on the knowledge of all attributes, I'd rather have a pull of one level deep. This is not recursion I'm after: it's not about friends of friends of friends-relationships. Taking that analogy, it's more a friends of one or more of of friends/mother/father/nephews/nieces/... of, well, that depends on if it's a friend of a friend, or a friend of a mother, or a friend of a father and so on.

ethangracer13:09:35

@kurt-yagram you could write a query that returned the attributes that you were looking for, i.e.:

‘[:find [?attr1 ?attr2 ?attr3] 
  :in $ ?e 
  :where [?e :entity/attribute ?attr1] [?e :entity/attribute ?attr2] [?e :entity/attribute ?attr3]]
It wouldn’t be in a map, but it would be guaranteed to only go one level deep

bahulneel14:09:52

@kurt-yagram what about:

(into {} (d/q '[:find ?an ?v :in $ ?e :where [?e ?a ?v] [?a :db/ident ?an]] db eid))

bahulneel14:09:50

remembering that the schema is queryable is something that keeps coming up over and over again for me

ethangracer14:09:53

only downside of the above is it returns one ID for ref many fields

ethangracer14:09:03

but it gets really close

bahulneel14:09:34

I think you could write a rule to fix that

ethangracer14:09:34

ah, because of the into

ethangracer14:09:38

that’s the only reason

ethangracer14:09:43

if you do a merge-with it’ll work

bahulneel14:09:46

maybe a reduce

kurt-yagram14:09:00

@bahulneel yeah, I think something like that may work

ethangracer14:09:37

@bahulneel you’re right, a reduce is easier

bahulneel14:09:30

This works

(->> eid
     (d/q '[:find ?an ?v
            :in $ ?e
            :where
            [?e ?a ?v]
            [?a :db/ident ?an]]
          db)
     (reduce (fn [m [k v]]
               (update m k (fn [o]
                             (cond
                               (nil? o) v
                               (sequential? v) (conj o v)
                               :else [o v]))))
             {}))

bahulneel14:09:49

Although if there's only one in a many you'll only get one

devth14:09:11

I just switched from dev storage to sql and now I'm trying to figure out how much disk space I should give the transactor(s). The docs only say it's used as temp storage. Does it need much? Does it need to be fast / ssd? Only relevant docs I could find were from the config samples:

# Data directory is used for dev: and free: storage, and
# as a temporary directory for all storages.
# data-dir=data

bahulneel14:09:10

@ethangracer this would work properly:

(->> eid
     (d/q '[:find ?an ?v ?c
            :in $ ?e
            :where
            [?e ?a ?v]
            [?a :db/ident ?an]
            [?a :db/cardinality ?c]]
          db)
     (reduce (fn [m [k v c]]
               (update m k (fn [o]
                             (if (= :db.cardinality/many c)
                               (if o
                                 (conj o v)
                                 [v])
                               v))))
             {}))

ethangracer14:09:26

@bahulneel looks right but isn’t quite working for me

ethangracer14:09:31

anyway it’s a fun idea

ethangracer14:09:41

definitely doable, just some nuance to figure out

bahulneel14:09:32

I didn't have a dataset handy to test it on, but the idea is there.

bahulneel15:09:29

@ethangracer ok so I forgot to get the ident of the cardinality the query part should be:

'[:find ?an ?v ?cn
 :in $ ?e
 :where
 [?e ?a ?v]
 [?a :db/ident ?an]
 [?a :db/cardinality ?c]
 [?c :db/ident ?cn]]

marshall15:09:37

@devth Datomic doesn’t need a lot of space. Faster certainly wouldn’t hurt.

marshall15:09:48

it’s used for local temp/swap

devth15:09:17

Ok, so e.g. a 10gb local ssd would be enough? Should it be persistent or can it be lost when a transactor fails and gets brought up elsewhere?

marshall15:09:35

more than enough. doesn’t need to be persistent

devth15:09:47

@marshall awesome, thanks!

ethangracer15:09:57

awesome, @kurt-yagram the solution above from @bahulneel is far better than mine 🙂