datahike
datahike copied to clipboard
Datahike's as-of behavior does not match that of Datomic for number inputs
Problem
Differences with Datomic article states that as-of has no differences from Datomic, but the behavior is actually different.
Datomic defines a time-point for as-of as one of:
- a Datomic transaction id. Use a transaction id when you want a database as of a specific transaction.
- a Datomic point in time. Use with, e.g., the basis-t value of the
:db-afterreturned by derefing the future returned bytransact.- an instant in time (a java.util.Date). An instant should be used when you have a wall clock time for the database you want but do not have a transaction id or basis-t value, as an instant is not as precise as Datomic's t or tx values.
Datahike defines time-point as:
Date (you may use either java.util.Date or Epoch Time as long).
The difference in behavior is in how number inputs are treated: Datahike assumes it's epoch time, while Datomic assumes it's either transaction id or basis-t. It seems there is no notion of basis-t at all in Datahike, so that difference is understandable. Datahike supports transactions though, so I would expect it to handle passed transaction ids as time points of these transactions.
Repro
(let [uri "datahike:mem://as-of-tx-id-repro"
_ (d/create-database uri :initial-tx [{:db/ident :user/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}])
conn (d/connect uri)
alice-tx (:db/current-tx (:tempids (d/transact conn [{:user/name "Alice"}])))
db (d/db conn)]
(.-as_of_date (d/as-of db alice-tx)))
=> #inst "1970-01-07T05:07:50.914-00:00"
Expected output
Either as-of treats tx ids in the same way as Datomic, or Differences with Datomic article states that as-of behavior is different for longs.
Actual output
as-of treats long time points as epoch time while claiming there is no difference to Datomic in Differences with Datomic article.