This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-05
Channels
- # adventofcode (89)
- # announcements (9)
- # babashka (11)
- # beginners (8)
- # biff (5)
- # calva (4)
- # cherry (121)
- # clara (15)
- # clerk (16)
- # clj-kondo (20)
- # clj-otel (2)
- # cljdoc (20)
- # clojure (84)
- # clojure-austin (1)
- # clojure-bay-area (3)
- # clojure-berlin (1)
- # clojure-czech (2)
- # clojure-europe (59)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-poland (1)
- # clojure-uk (15)
- # cursive (16)
- # datomic (46)
- # events (3)
- # fulcro (85)
- # graalvm (20)
- # hyperfiddle (11)
- # improve-getting-started (1)
- # lsp (7)
- # off-topic (48)
- # overtone (8)
- # podcasts-discuss (4)
- # re-frame (31)
- # releases (1)
- # ring (12)
- # sci (13)
- # shadow-cljs (8)
- # specter (3)
- # squint (26)
- # xtdb (5)
- # yamlscript (6)
Is it expected the java.util.Date/from
is not available to Datomic Cloud queries? I know that static method is not in early-ish Java versions, but I didn’t think Datomic Cloud was running on Java that old.
there is no such method - it is java.util.Date/from (was added in Java 1.8, should exist in Datomic cloud)
Sorry, that’s the method I meant to type. HEre’s the exception I see:
Execution error (ExceptionInfo) at datomic.core.require/anomaly! (require.clj:53).
Unable to load namespace for java.util.Date/from
(FWIW, this is running against Datomic Local, but I assume it’s high-fidelity with Datomic Cloud/Ion).
Minimal test case:
(let [{conn :datomic/connection} @user/sysref
db (d/db conn)
works-here (java.util.Date/from (Instant/now))]
(d/q {:query '{:find [?xnow]
:in [$]
:where [[(java.util.Date/from (java.time.Instant/now)) ?xnow]]} ; not here
:args [db]}))
Surprisingly, this works (note the immediately executed thunk):
(let [{conn :datomic/connection} @user/sysref
db (d/db conn)
works-here (java.util.Date/from (java.time.Instant/now))]
(d/q {:query '{:find [?xnow]
:in [$]
:where [[(#(java.util.Date/from ^java.time.Instant (java.time.Instant/now))) ?xnow]]}
:args [db]}))
https://docs.datomic.com/cloud/query/query-data-reference.html#built-in-functions This leads me to believe it’s a smaller set of allowable functions and not any arbitrary expression
This led me to believe that as long as the class was available on the classpath https://docs.datomic.com/cloud/query/query-data-reference.html#calling-static-methods
The fact that it works when buried inside a thunk leads me to believe that I either have the syntax wrong or there is a something wrong in the query parser.
have you tried your minimal with the type hint added?
(let [{conn :datomic/connection} @user/sysref
db (d/db conn)
works-here (java.util.Date/from (Instant/now))]
(d/q {:query '{:find [?xnow]
:in [$]
:where [[(java.util.Date/from ^java.util.Date (java.time.Instant/now)) ?xnow]]} ; not here
:args [db]}))
I got one of the type hints wrong in my example above, but correcting it does not solve the problem. Corrected version:
(let [{conn :datomic/connection} @user/sysref
db (d/db conn)
works-here (java.util.Date/from (java.time.Instant/now))]
(d/q {:query '{:find [?xnow]
:in [$]
:where [[(java.util.Date/from ^java.time.Instant (java.time.Instant/now)) ?xnow]]} ; not here
:args [db]}))
…same error.Generally, I’m finding that anonymous functions solve a lot of issues with nesting. It appears as though a complex anonymous fn with typed db args works well.
Yeah, this is just an example. The real work is computing a window around a db value and passing in now
can you describe the real work semantically? there is maybe a different way to accomplish
Find db entities with an date attr before a cutoff that is a function of another attribute of the entity.
[?e :cutoff/inst ?x] [?e :date ?d] [(my-logic ?x) ?actual-cutoff] [(< ?d ?actual-cutoff)]
https://docs.datomic.com/cloud/query/query-data-reference.html#calling-clojure-functions
I know how to add a clojure fn … and if I have to, I’ll solve the problem that way (with deploy cycle). But why can’t it work with an inline fn?
the query clause is not an argument that accepts arbitrary code, even though it looks like it
Possibly. FWIW, I’m finding that un-nesting doesn’t resolve the issue. What does seem to resolve the issue is avoiding the Class/method
syntax and reverting to the (. class method)
syntax.
So this, surprisingly, also works:
(let [{conn :datomic/connection} @user/sysref
db (d/db conn)
works-here (java.util.Date/from (java.time.Instant/now))]
(d/q {:query '{:find [?xnow]
:in [$]
:where [[(. java.util.Date from ^java.time.Instant (java.time.Instant/now)) ?xnow]]} ; not here
:args [db]}))