I'm working with Datomic Cloud and I noticed the following scenario, whenever I transact a fact that is of the java.net.URI
type and try to query it back I get com.cognitect.transit.impl.URIImpl
back as the type, I was expecting that the types remain the same. I have found no documentation about this or how to deal with it.
This breaks behavior where I am using interop to, for example, get the host of a URI. As Clojure will throw an exception No matching field found: getHost for class com.cognitect.transit.impl.URIImpl
.
This issue does not occur in local-dev.
Example:
(require '[datomic.client.api :as d])
(def schema [{:db/ident :test/url
:db/valueType :db.type/uri
:db/unique :db.unique/identity
:db/cardinality :db.cardinality/one
:db/doc "The URL."}])
(def cfg {:server-type :cloud
:region ""
:system ""
:endpoint ""})
(def client (d/client cfg))
(d/create-database client {:db-name "test"})
(def conn (d/connect client {:db-name "test"}))
(d/transact conn {:tx-data schema})
(d/transact conn {:tx-data [{:test/url (java.net.URI. "https://www.google.com")}]})
(let [q '[:find ?url
:where [?e :test/url ?url]]
db (d/db conn)]
(d/q q db))
;; => [[#object[com.cognitect.transit.impl.URIImpl 0x938b85 "https://www.google.com"]]]
(let [q '[:find ?url
:where [?e :test/url ?url]]
db (d/db conn)]
(type (ffirst (d/q q db))))
;; => com.cognitect.transit.impl.URIImpl
(let [q '[:find ?url
:where [?e :test/url ?url]]
db (d/db conn)]
(.getHost (ffirst (d/q q db))))
;; => Unhandled java.lang.IllegalArgumentException
;; No matching field found: getHost for class com.cognitect.transit.impl.URIImpl
I was expecting java.net.URI
as the type.
UPDATE: Jaret Binford from Datomic Support clarified that this is a potential bug on the Datomic end. I'll update the question once further clarification comes.
UPDATE: Jaret Binford from Datomic Support confirmed that this is a bug on the Datomic end.
We released a fix for this in Datomic Local 1.0.277, client-pro 1.0.78, and client-cloud 1.0.125.
Cheers! -Jaret