Fork me on GitHub
#datomic
<
2019-02-11
>
Ben Hammond09:02:13

is it possible to query against an as-of db within a datalog query; something like

(d/q '[:find ?e ?attr-name ?v ?tx ?user-id ?product-initial ?ingested-at
       :in $ [[?e ?a ?v ?tx]]
       :where
       [?e :user/id ?user-id]
       [(d/asof $ ?tx) ?e :historical/product-initials ?product-initial]
       [?tx :db/txInstant ?ingested-at]
       [?a :db/ident ?attr-name]]
     datomic-db
    previously-found-datom)

favila13:02:21

No. All dbs must be :in parameters in datalog and cannot be bound dynamically.

favila13:02:43

You could however invoke a subquery with your dynamically made db

Ben Hammond09:02:46

do I have to pass the historical db as a parameter to the datalog?

Ben Hammond09:02:02

like

(d/q '[:find ?e ?attr-name ?v ?tx ?user-id ?product-initial ?ingested-at
       :in $current $historic [[?e ?a ?v ?tx]]
       :where
       [$current ?e :user/id ?user-id]
       [$historic ?e :historical/product-initials ?product-initial]
       [$current ?tx :db/txInstant ?ingested-at]
       [$current ?a :db/ident ?attr-name]]
     datomic-db
     (d/as-of datomic-db (:tx previously-found-datom))
     previously-found-datom)

steveb8n09:02:05

Q: I’m getting ready to add a circuit breaker into my Ions for http calls. I’m considering https://github.com/sunng87/diehard and https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-clj. Anyone got any experience with this pattern in Ions yet?

mpenet15:02:33

hystrix is somewhat deprecated I think fyi

Joe Lane15:02:22

Hystrix team seems to recommend https://github.com/resilience4j/resilience4j going forward.

dazld16:02:54

that looks pretty interesting - do you know of any open source CLJ projects that use it, to see what the integration looks like? especially things like retrying..

Joe Lane18:02:34

Just found it today, so unfortunately no.

steveb8n21:02:07

thanks. I didn’t know Hysterix was EOL

johanatan22:02:29

does anyone know why the following would only seem to return the first 3-tuple rather than all of them across time (when run against (d/history db):

(def price-history-for-underlying
  '[:find ?price ?time ?tx
    :in $ ?sym
    :where
    [?und :underlying/symbol ?sym ?tx]
    [?und :underlying/price ?price ?tx]
    [?q :quote/underlying ?und ?tx]
    [?q :quote/time ?time ?tx]])
do i need an aggregating function somewhere? (these two related entities are always inserted in the same call to transact and thus should always have the same ?tx across them).

johanatan22:02:34

[not only are these inserted in the same call to transact but the underlying entity is actually nested under the quote entity via it's underlying attribute (both maps)].

favila22:02:18

:find returns a set

johanatan22:02:22

[the one wrinkle is that there are many quotes with the same underlying value all transacted at once. but that should be fine as long as everything inside the collection of maps passed to transact receives the same tx-id]

favila22:02:41

if [?price ?time ?tx] is the same across all you will get only one item

johanatan22:02:46

yes, i'm getting a set of one 3-tuple rather than a set of many 3-tuples

favila22:02:23

if you include ?sym or ?q does it change?

favila22:02:13

you're also joining all ?tx which seems odd

favila22:02:22

unless you actually do transact all at once

johanatan22:02:28

i do actually transact all at once

johanatan22:02:43

what i want is for tx to be fixed to various points in time

johanatan22:02:56

ok, adding ?sym did not get many but adding ?q did

favila22:02:00

you want tx-time = time-of-record?

favila22:02:08

or domain-time?

johanatan22:02:20

doesn't matter. tx-id or time both should be identical across all of these

favila22:02:27

:quote/time = tx time?

johanatan22:02:43

:quote/time is roughly wall clock time at the point of the insertion

favila22:02:53

why not == tx time?

johanatan22:02:12

because they're not equal 🙂

favila22:02:14

that's the red flag to me. generally it's really really hard to make tx time anything but a git-commit like audit history

favila22:02:29

you can set :db/txInstant

favila22:02:44

as long as you don't set it before the most recent one

johanatan22:02:45

time is just a piece of data. doesn't matter if it is skewed by a few hundred milliseconds. it is the time that the server quoted the price to me

johanatan22:02:54

so, txInstant will be several hundred milliseconds later

johanatan22:02:36

i am more interested in knowing that the price in question was the price at the moment that the server reported it for

johanatan22:02:43

hence its inclusion in the query

favila22:02:14

so winding back, unless you include ?q you are not guaranteed a result per ?q

favila22:02:48

you can use :with to include a binding for the purposes of computing the result set but do not want to include it in the result set

johanatan22:02:26

hmm, ok. with may be the answer here. including q only got me the fan-out at a particular moment in time. i am still not getting the fan-out across all moments in time

favila22:02:31

:with ?q would ensure you got at least one result per q

johanatan22:02:44

i am more interested in getting at least one result per tx

johanatan22:02:00

and including ?tx in the :find doesn't seem to be doing that

favila22:02:15

and you are sure there is a unique ?q and ?und per ?tx

johanatan22:02:37

pretty sure. if that isn't true then much bigger problems are here. how can i verify it?

favila22:02:00

just remove the tx

favila22:02:03

from query and find

favila22:02:05

see what you get

favila22:02:12

(include the q)

favila22:02:11

or you can do a clause at a time

favila22:02:42

[:find ?q ?und ?tx :where [?q :quote/underlying ?und ?tx]

johanatan22:02:42

but if i'm not including the ?tx, how can i know how many ?tx's are accounted for in the result?

favila22:02:09

removing the tx is to be sure you actually have multiple entities

johanatan22:02:28

ah, right. sorry, lol

johanatan22:02:37

well this query is taking a long time

johanatan22:02:49

so, it is likely gonna return a lot of data

johanatan22:02:06

i have to leave now. i'll play more with this later. thx!

johanatan23:02:43

so, i got OutOfMemoryError on that query so i think it's safe to say that there are multiple entities

superancetre23:02:01

Hi, I'm sure you've got the question a thousand time before

superancetre23:02:10

but I am trying my hands with datomic

superancetre23:02:19

was trying to setup the dev storage

superancetre23:02:37

I put my key in the properties files

superancetre23:02:45

launch a transactor with .\bin\transactor .\config\dev-transactor.properties

superancetre23:02:03

I get back a message System started datomic:, storing data in: data

superancetre23:02:31

Then I try to launch a peer-server like in the tutorial using in memory storage

superancetre23:02:00

Command is bin/run -m datomic.peer-server -h localhost -p 8998 -a myaccesskey,mysecret -d mydb,datomic:

marshall19:02:57

The peer server can’t create databases in dev storage. you’ll need to connect a REPL and create the database first, then launch the peer server

superancetre23:02:38

And I get an error Exception in thread "main" java.lang.RuntimeException: Could not find mydb in catalog

superancetre23:02:04

So I guess I need to create a catalog called mydb but how I am supposed to do?

superancetre23:02:25

I'm sorry I am very confused by the Datomic Architecture right now

johanatan23:02:26

@favila why is this only returning one transaction id?

core=> 
(def price-history-for-underlying
  '[:find ?tx
    :with ?und
    :in $ ?sym
    :where
    [?und :underlying/symbol ?sym ?tx]
;   [?und :underlying/price ?price ?tx]
;   [?q :quote/underlying ?und ?tx]
;   [?q :quote/time ?time ?tx]
    ])
#'core/price-history-for-underlying
core=> 
core=> (d/q price-history-for-underlying (d/history (db)) "OEX")          
[[13194139534793]]
core=> 
I was hoping to get all tx's in which that symbol is involved

johanatan23:02:40

[and i think this is the root of the other problems i'm having]

favila23:02:42

because there is only one ?und?

favila23:02:51

what does a transaction look like

johanatan23:02:56

there is only one ?und but across time there are many