Fork me on GitHub
#datomic
<
2019-11-15
>
onetom03:11:42

it seems i can't rename :db/id in pull expressions with the :as option:

(d/pull-many db '[[:db/id :as :eid]
                                       [:txn/merchant :as :XXX]]
                                  txns)
outputs:
[{:db/id 17592186045422}
 {:db/id 17592186045423}
 {:XXX {:db/id 17592186045418}, :db/id 17592186045424}
 {:XXX {:db/id 17592186045418}, :db/id 17592186045425}]
is that intentional? i can't find it documented in https://docs.datomic.com/on-prem/pull.html#as-option

matthavener16:11:27

I vaguely remember someone else talking about this a few months ago and a datomic rep said it was a known limitation or something

Luke Schubert12:11:41

is there a sane/performant way to accumulate a concept of a score in a datalog query?

Luke Schubert12:11:14

to get the idea of what I'm going for is given two people

Name | ArbitraryField | Id
Bob    | A123               | 1
Steve | B321                | 2
I want to be able to run a query for (Bob, B321) where Name gives x points and ArbitraryField gives y points on a match and both are returned

Luke Schubert13:11:12

I'm also fine with it returning something like

[[1 [:name]] [2 [:arbitrary-field]]

benoit15:11:56

Datomic works with set so you will have to associate the score to each result yourself with something of this shape:

(or-join [?name-q ?arbitrary-q ?id ?points]
         (and [?id :name ?name-q]
              [(ground x) ?points])
         (and [?id :arbitrary ?arbitrary-q]
              [(ground y) ?points]))

Luke Schubert15:11:50

ah that's exactly what I'm looking for, thanks

johnj15:11:26

Besides the UUID type, what other methods are there to generate unique natural numbers to store in a Long type without collisions? like the ones datomic generates (`:db/id`)

fjolne19:11:41

There’s not enough space for a universal uniqueness in 64 bits (that’s why all versions of UUIDs are 128 bit). Datomic likely uses the fact that all the new entity ids are generated sequentially (due to sequential transactor), so it could guarantee uniqueness via counters and/or clocks.

fjolne19:11:54

I’d go with tx function which uses aggr max / index lookup + ensure attr has an AVET index. This should yield an O(1) / O(log n) time complexity. Query first approach would require CAS.

fjolne20:11:12

And it would probably be more efficient to go down by negative ids, this way index lookup would require to realize only the head of the lazy index: (dec (first (index-range db :your/attr nil nil)))

fjolne20:11:41

Clock value (micro/nanoseconds) should also be ok in tx function due to sequentiality of txs (but not precalculated as tx data, as those are not sequential). IIRC they used it in Crux for :db/ids. And it probably worth mentioning that both approaches generate ids which are easy to guess by 3rd-party (not to say UUIDs are too hard to guess but still).

johnj17:11:32

insightful, thanks, taking notes

johnj15:11:37

could implement auto-increment as tx function or doing a query first but seems inefficient

dvingo19:11:40

Why not just use UUID?

hiredman23:11:21

there are squuids, which are more or less uuids, which datomic generates to be sort of sequential which is sort of like http://yellerapp.com/posts/2015-02-09-flake-ids.html