 (defn- build-types-for-slices
   [definition]
   (letfn [(build-types-for-slice [slice definition]
-            (let [slice-def (get-in definition [:slices slice])
-                  table-name (:table slice-def)
-                  table-def (get-in definition [:tables (keyword table-name)])]
-              (reduce (fn [definition column]
-                        (if (and (:name column)
-                                 ((set (data/slice-columns slice-def)) (:name column)))
-                          (assoc-in definition
-                                    [:slices slice :types (keyword (:name column))]
-                                    (slice-type-for-table-type (:type column)))
-                          definition))
-                      definition
-                      (vals (:columns table-def)))))]
+                                 (let [slice-def (get-in definition [:slices slice])
+                                       table-name (:table slice-def)
+                                       table-def (get-in definition [:tables (keyword table-name)])]
+                                   (reduce (fn [definition column]
+                                             (if (and (:name column)
+                                                      ((set (data/slice-columns slice-def)) (:name column)))
+                                               (assoc-in definition
+                                                         [:slices slice :types (keyword (:name column))]
+                                                         (slice-type-for-table-type (:type column)))
+                                               definition))
+                                           definition
+                                           (vals (:columns table-def)))))]
     (let [slices (keys (:slices definition))]
       (reduce (fn [definition slice]
                 (build-types-for-slice slice definition))

    (apply await agents)))

(defmulti load-slice
  (fn [slice _ definition]
    (get-in definition [:slices (keyword slice) :type])))

(defmethod load-slice "table"
  [slice concepts definition]
  (let [sdef (get-in definition [:slices (keyword slice)])
        table (:table sdef)
        references (:references sdef)

                           (:slices definition))
        definition (dissoc definition :tables)]
    (with-db (get-db "metadata")
             (coll/update "datasets" {:name name}
                          definition
                          :upsert true))))

(defmulti cast-value (fn [_ valuedef] (:type valuedef)))

