nil
is a valid heterogeneous tuple value, right?
Given the following schema:
{:db/ident :person/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :person/parents
:db/valueType :db.type/tuple
:db/tupleTypes [:db.type/ref :db.type/ref]
:db/cardinality :db.cardinality/one}
I can happily transact:
{:tx-data [{:db/id "child"
:person/name "child"
:person/parents ["parent-a" nil]}]}
=> Success
And happily pull the result:
(d/q '{:find [(pull ?p [*])]
:in [$]
:where [[?p :person/name "child"]]}
db)
=> [[{:db/id 101155069755487
:person/name "child"
:person/parents [101155069755485 nil]}]]
However, when attempting to untuple
the tuple values and bind to their values, the binding to the nil
value throws a NullPointerException:
(d/q '{:find [?person ?parent-a-name ?parent-b-name]
:in [$]
:where [[?person :person/name "child"]
[?person :person/parents ?parents-tuple]
[(untuple ?parents-tuple) [?parent-a ?parent-b]]
[?parent-a :person/name ?parent-a-name]
[?parent-b :person/name ?parent-b-name] ;<-- adding this throws exception
]}
db)
Execution error (NullPointerException) at datomic.core.db/asserting-datum (db.clj:-1).
null
clojure.lang.ExceptionInfo: processing clause: [?parent-b :person/name ?parent-b-name], message: #:cognitect.anomalies{:category :cognitect.anomalies/incorrect, :message "processing clause: [?parent-b :person/name ?parent-b-name], message: "}
at datomic.core.datalog$throw_query_ex_BANG_.invokeStatic(datalog.clj:50)
java.lang.NullPointerException
Is this expected? Thanks!