Skip to content

Instantly share code, notes, and snippets.

@cs224
Created January 19, 2013 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cs224/4570937 to your computer and use it in GitHub Desktop.
Save cs224/4570937 to your computer and use it in GitHub Desktop.
How to query for dublet attributes across entities via datomic.
(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