Created
January 19, 2013 05:38
-
-
Save cs224/4570937 to your computer and use it in GitHub Desktop.
How to query for dublet attributes across entities via datomic.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn datomic-group-fds-by-fd-id [fd-v & {:keys [id-fn] :or {id-fn :hash}}] | |
(q '[:find ?fd-id (into [] ?fd) | |
:in $fd-v | |
:where | |
[$fd-v ?fd ?fd-id] | |
] | |
(maps->rel fd-v [id-fn]))) | |
(defn datomic-get-redundant-files [grouped-fds-by-fd-id & {:keys [id-fn] :or {id-fn :hash}}] | |
(q '[:find ?fd-v-g | |
:in $fd-v | |
:where | |
[$fd-v ?fd-id ?fd-v-g] | |
;; the following does not work: [(> (count ?fd-v-g) 1)] | |
[(count ?fd-v-g) ?cnt] | |
[(> ?cnt 1)] | |
] | |
grouped-fds-by-fd-id)) | |
(defn map-and-filter-get-redundant-files [grouped-fds-by-fd-id & {:keys [id-fn] :or {id-fn :hash}}] | |
(filter (fn [x-seq] (> (count x-seq) 1)) | |
(map second grouped-fds-by-fd-id))) | |
(defn get-redundant-files [fd-v & {:keys [id-fn] :or {id-fn :hash}}] | |
(-> fd-v | |
(datomic-group-fds-by-fd-id :id-fn id-fn) | |
;;(datomic-get-redundant-files :id-fn id-fn) | |
(map-and-filter-get-redundant-files :id-fn id-fn) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment