This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-06-03
Channels
- # aws (12)
- # beginners (12)
- # biff (10)
- # calva (1)
- # cider (10)
- # cljfx (1)
- # clojure (2)
- # clojure-conj (1)
- # clojure-europe (25)
- # clojure-madison (1)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-sweden (4)
- # clojure-uk (6)
- # datomic (11)
- # dev-tooling (3)
- # emacs (5)
- # gratitude (1)
- # introduce-yourself (7)
- # java (3)
- # jobs (1)
- # london-clojurians (2)
- # lsp (23)
- # off-topic (4)
- # practicalli (9)
- # quil (6)
- # re-frame (3)
- # reagent (4)
- # remote-jobs (1)
- # ring (1)
- # shadow-cljs (18)
- # squint (67)
- # tools-deps (5)
- # xtdb (4)
- # yamlscript (12)
hello! Apologies in advance if this is just a naive hallucination, but I'm pretty new to both XT and Datalog. I have an xtdb (v1) that receives (asynchronously) batches of orders and (separately) updates to commodity prices. I was hoping to be able to model it so that, given a batch of N orders, I could dynamically retrieve the price of the commodity of each order (X) at the time (t) of the order itself... but I can't figure out how and at this point I'm doubting it is possible. One alternative would be to make 1+N queries, passing the order time explicitly as the valid time, which I'd be fine with; but let's say I'm trying to map the boundaries of what is possible and what not.
I believe that v1 doesn't have valid-time as a column at query time so you'll need to make multiple queries. I will say that v2 is much more flexible on this count and we have a pretty similar https://docs.xtdb.com/tutorials/financial-usecase/late-trade.html in the new docs (prices would just be a separate table https://play.xtdb.com/?version=2.0.0-SNAPSHOT&type=sql&txs=W3sic3lzdGVtLXRpbWUiOiIyMDI0LTAxLTAxVDAwOjAwOjAwLjAwMFoiLCJ0eHMiOiItLSBPcmRlcnMgZm9yIHRoZSBkYXlcbklOU0VSVCBJTlRPIG9yZGVycyAoeHQkaWQsIGZvciwgYW1vdW50KVxuICBWQUxVRVNcbiAgKDEsICdHQlAnLCA1MCk7XG5cbi0tIEVPRCBwcmljZXNcbklOU0VSVCBJTlRPIHByaWNlcyAoeHQkaWQsIHZhbHVlKVxuICBWQUxVRVNcbiAgKCdHQlAnLCA1KSxcbiAgKCdVU0QnLCA2KTsifSx7InR4cyI6Ii0tIE9yZGVycyBmb3IgdGhlIGRheVxuSU5TRVJUIElOVE8gb3JkZXJzICh4dCRpZCwgZm9yLCBhbW91bnQsIHh0JHZhbGlkX2Zyb20pXG4gIFZBTFVFU1xuICAoMiwgJ1VTRCcsIDcwLCBEQVRFICcyMDI0LTAxLTAxJyksICAtLSBMYXRlIG9yZGVyXG4gICgzLCAnR0JQJywgMTAsIG51bGwpLFxuICAoNCwgJ1VTRCcsIDMwLCBudWxsKTtcblxuLS0gRU9EIHByaWNlc1xuSU5TRVJUIElOVE8gcHJpY2VzICh4dCRpZCwgdmFsdWUpXG4gIFZBTFVFU1xuICAoJ0dCUCcsIDQpLFxuICAoJ1VTRCcsIDUpOyIsInN5c3RlbS10aW1lIjoiMjAyNC0wMS0wMlQwMDowMDowMC4wMDBaIn1d&query=U0VMRUNUIG8ueHQkaWQsIG8uZm9yLCAoby5hbW91bnQgKiBwLnZhbHVlKSBBUyB0b3RhbCwgby54dCR2YWxpZF9mcm9tCiAgRlJPTSBvcmRlcnMgQVMgbwogIElOTkVSIEpPSU4gcHJpY2VzIEZPUiBWQUxJRF9USU1FIEFMTCBBUyBwCiAgICBPTiBvLnh0JHZhbGlkX2Zyb20gPSBwLnh0JHZhbGlkX2Zyb20KICAgICAgQU5EIG8uZm9yID0gcC54dCRpZApPUkRFUiBCWSBvLnh0JGlk)
Hey @U06KLK9ST what Oliver wrote is essentially correct, but note that v1 does have a couple of built-in history predicates (see https://v1-docs.xtdb.com/language-reference/datalog-queries/#_history_predicates):
[(*get-start-valid-time* e) start-time]
[(*get-end-valid-time* e) end-time]
however in general v1 is much more sympathetic to the idea of doing most of your logic in code and issuing many small queries (rather than sending batches of data to complex queries). In v2 the engine is intended to be used more like a regular SQL db, and behave more how you are thinking (but is still embeddable like v1 if you want to avoid network hops)
@U899JBRPF @U5W78K2UF thanks, that's what I imagined. I did some experiments with get-start-valid-time
, but still couldn't get access to previous incarnations of a record, only the one "currently" (speaking relatively to the query valid time) in scope.
Thank you also for the clarification around what's the idiomatic approach. It's still early days for the project, so I could still either switch to v2, or take the many-query approach (which I just tried, and works nicely).