This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-23
Channels
- # announcements (5)
- # babashka (22)
- # beginners (240)
- # calva (51)
- # clj-commons (1)
- # cljsrn (9)
- # clojars (12)
- # clojure (81)
- # clojure-australia (2)
- # clojure-europe (40)
- # clojure-france (10)
- # clojure-italy (1)
- # clojure-nl (2)
- # clojure-uk (37)
- # clojurescript (59)
- # clojureverse-ops (2)
- # copenhagen-clojurians (1)
- # cursive (9)
- # datomic (18)
- # emacs (12)
- # fulcro (24)
- # graalvm (48)
- # hyperfiddle (5)
- # introduce-yourself (1)
- # jackdaw (1)
- # jobs (2)
- # juxt (8)
- # lsp (25)
- # malli (8)
- # missionary (1)
- # music (3)
- # off-topic (32)
- # polylith (16)
- # quil (4)
- # re-frame (52)
- # reitit (5)
- # reveal (3)
- # rewrite-clj (26)
- # rum (1)
- # sci (1)
- # shadow-cljs (14)
- # sql (2)
- # tools-build (40)
- # tools-deps (14)
- # vrac (2)
- # xtdb (63)
Hi folks! I've been looking through the docs but haven't been able to figure out whether it's possible to query against the valid time (or transaction time, for that matter). To be clear, I'm not talking about querying against a snapshot of the db at a particular tx/valid time, but rather against it, like you can with tx times in Datomic. Is this something xtdb can do?
For a bit of added context, what I'm interested in is putting together timeseries data, using valid time. In Datomic, if I was okay with using transaction time, I could query against the tx value in the datoms, like [:find ?t ?v :where [?e :some/attr ?v ?t]]
. That would give me all of the past values that :some/attr
had taken on over time. While this sort of works, it's really begging for the valid time treatment.
Yes this isn't possible atm but is actively being worked on and something along these lines will be possible in a future release
@U7KPK060K Wonderful! That's great to hear. Thanks for the response.
Hi @U05100J3V - sorry for the very delayed response(!) > afaict, the tx and valid time data isn't exposed to queries This is essentially correct, currently. However we will be exposing both possibilities in the next-gen indexes coming soon, discussed lightly in the blog https://xtdb.com/blog/dev-diary-aug-21.html#_future As a workaround in the meantime, you can access the data efficiently in userspace, e.g. https://github.com/xtdb/xtdb/blob/e2f51ed99fc2716faa8ad254c0b18166c937b134/bench/src/xtdb/bench/ts_devices.clj#L215-L240
No worries! Thanks for circling back around to it!
That's great to hear that this is being worked on. Is it safe to take "over the next six months" as a rough ETA? 🙂
As for the workaround, seems like xt/open-entity-history
is the key there, yes? Which if I understand correctly returns a iterator of entity maps that were transacted into the db? I think this will work for now for the project I'm working on, but I'm looking forward to being able to query against this!
> Is it safe to take "over the next six months" as a rough ETA? I can't promise anything, but we have lots of working code (in a private repo, for now) and good momentum at the moment so don't see why we won't hit that target 🤞
I am running juxt/xtdb-in-memory:1.19.0-beta1
and have problem executing clojure code in where clause (posting via
)
This works: [(str ?birth-date) ?date]
but this doesn't: [(.getTime ?birth-date) ?date]
Error msg: "Clause refers to unknown variable: .getTime {:pred {:pred-fn .getTime, :args [?birth-date]}, :return [:scalar ?date]}"
Any clues?
This also doesn't work: [(java.util.Date.) ?today]
Error msg: "Clause refers to unknown variable: java.util.Date. {:pred {:pred-fn java.util.Date.}, :return [:scalar ?today]}"}
so you can (defn time-of [d] (.getTime d))
and use it like [(some.ns/time-of ?birth-date) ?date]
Okay, I have a simple question. I am running xtdb via docker: docker run -p 3000:3000 juxt/xtdb-in-memory:1.19.0-beta1
.
I am invoking a query via POST on
endpoint.
Why doesn't this work in a where clause:
[(java.util.Date.) ?today]
Error msg:
"Clause refers to unknown variable: java.util.Date. {:pred {:pred-fn java.util.Date.}, :return [:scalar ?today]}"}
Hi @U013100GJ14 sorry for the very delayed response(!) As per @U11SJ6Q0K's reply on the earlier thread, you can't do interop like this within Datalog (nor can use evaluate raw Clojure), and instead you will need to define a Clojure function to do the work, and it must be made available to the XT node via the classpath.
This consequently means that you would need to build your own Docker container using the build
module, as per https://xtdb.com/blog/xtdb-build.html - I think you could register your custom functions as a local dependency using deps.edn but I've not tried that before (and would be happy to help!)
To help during development time however, there is a small trick you can use to evaluate arbitrary Clojure: https://gist.github.com/refset/a7f86c8a3ad34aea5d20eac0b5720a28
(you would still need to add this inside your Docker container though....but perhaps we can thinking about exposing it by default in future :thinking_face: - subject to the allow-list
, of course)
Anyway, I have stopped doing stuff via HTTP module and am now into doing stuff in code.
What bothers me here is that they are deprecating the Map<Keyword, ?> submitTx(List<List<?>> transaction);
method
yep, you can already use most of clojure.core/*
but constructing completely arbitrary nested expressions is hard work / impossible
it bothers me, because I want an initial dataset which is the easiest and most readable to do in EDN format
Also, as a side note regarding the HTTP API, this example does not work with EDN: https://xtdb.com/reference/1.19.0-beta1/http.html#submit-tx
Ah, yeah sorry about that one, we have fixed it on master
but not created a new release yet to make the changes obvious yet, but the new version is viewable here https://xtdb.com/reference/http.html#submit-tx
regarding
Have you tried calling the xtdb.api/submit-tx Clojure API via Java interop?
What exactly do you mean?I am now importing EDN dataset the following way:
val data = File(dataResource.toURI()).bufferedReader().readText()
val tr = xtdbNode.submitTx(toClojure(data) as MutableList<MutableList<*>>)
fun toClojure(edn: String?): Any? {
return try {
val read = Clojure.read(edn) ?: throw IllegalArgumentException("EDN String did not produce a value!")
read
} catch (e: Exception) {
logger.error("Exception while reading Clojure edn value: $edn", e)
null
}
}
thanks for sharing your code, my Java is not very good, so I daren't try to suggest what the solution looks like exactly but it seems to be possible in theory 🙂
please let me know if it works, or not, maybe it's a terrible idea and I should avoid suggesting it in future 😅
my pleasure. And I'm very curious about what you're up to with Kotlin! I look forward to hearing more
Did you already see https://github.com/AlistairONeill/crux-kotlin-dsl ?
totally fair. I also prefer the edn, though I've never written a line of Kotlin so can't really judge
One question regarding keywords vs strings for attributes/entity id: is it better (more performant?) to use keywords for attribute names and entity ids?
A quick look at java api, the XtdbDocument.put
seems to favor (support) Strings only for keys?!
we recognise that keywords are mainly a Clojure thing and want to appear more JSON-oriented. There should be no meaningful performance difference between the two though, in either storage or lookup costs