Project a stream of bindings onto a literal/relation. Returns a new
db.
(defn project-literal
"Project a stream of bindings onto a literal/relation. Returns a new
db."
([db lit bs] (project-literal db lit bs is-var?))
([db lit bs var?]
(assert (= (:literal-type lit) ::literal))
(let [rel-name (literal-predicate lit)
columns (-> lit :term-bindings keys)
idxs (vec (get-adorned-bindings (literal-predicate lit)))
db1 (ensure-relation db rel-name columns idxs)
rel (get-relation db1 rel-name)
step (fn [rel bindings]
(let [step (fn [t [k v]]
(if (var? v)
(assoc t k (bindings v))
(assoc t k v)))
tuple (reduce step {} (:term-bindings lit))]
(add-tuple rel tuple)))]
(replace-relation db rel-name (reduce step rel bs)))))
Comments top
No comments for project-literal. Log in to add a comment.