replikativ / datahike

A fast, immutable, distributed & compositional Datalog engine for everyone.
https://datahike.io
Eclipse Public License 1.0
1.63k stars 97 forks source link

Fix issue 680: correctly pull attributes #681

Closed jonasseglare closed 5 months ago

jonasseglare commented 5 months ago

SUMMARY

Fixes #680

This PR fixes a bug related to pulling attributes. See the issue description and the unit test.

In short, if we run the following query

(let [db (d/db-with ref-db [{:db/ident :attribute-to-use
                                 :db/cardinality :db.cardinality/one
                                 :db/valueType :db.type/keyword}])
          result (d/q '[:find (pull ?attr [*])
                        :in $ ?attr-name
                        :where
                        [?attr :db/ident ?attr-name]]
                      db :attribute-to-use)

the code in this PR makes sure that we get the correct result of

[[#:db{:id 62,
       :ident :attribute-to-use,
       :valueType #:db{:id 23, :ident :db.type/keyword},
       :cardinality #:db{:id 11, :ident :db.cardinality/one}}]]

instead of the incorrect result of

[[#:db{:id 62,
       :ident :attribute-to-use,
       :valueType 23,
       :cardinality 11}]]

Checks

Bugfix