 
 ;; (? (dunion)(dsplit :ocean nil [(pivot :type org.dada.demo.whales/types (keyword (sum-value-key :weight)))(dsum :weight)(split :type )])(from "Whales"))
 ;; (? (dunion)(split :type nil [(pivot :ocean org.dada.demo.whales/oceans (keyword (sum-value-key :weight)))(sum :weight)(split :ocean )]) (from "Whales"))
+
+;; (? (ccount)(from "Whales"))
+;; (? (split :ocean)(from "Whales"))
+;; (? (split :type)(from "Whales"))
+;; (? (union)(split :ocean nil [(pivot :type org.dada.demo.whales/types (keyword (sum-value-key :weight)))(sum :weight)(split :type )])(from "Whales"))
+;; (? (union)(split :type nil [(pivot :ocean org.dada.demo.whales/oceans (keyword (sum-value-key :weight)))(sum :weight)(split :ocean )]) (from "Whales"))
+;; (? (from "MetaModel"))

;; Join scratch area
;;--------------------------------------------------------------------------------

(if false
  (do

    (inspect (? (dfrom "Whales")))
    (inspect (? (dfrom "Oceans")))
    (inspect (? (dfrom "WhalesAndOceans")))

    (insert oceans-model (Ocean. "arctic"   1000000 99999999 17880))
    (insert oceans-model (Ocean. "southern" 1000000  10000000 23737))

    (insert whales-model (Whale. 50 3011 (Date. 0 1 1) "jules" "blue whale" "atlantic" 100 100))
    (delete whales-model (Whale. 50 3100 (Date. 0 1 1) "jules" "blue whale" "seaworld" 100 100))
    (.find whales-model 10000)

    ))

;;--------------------------------------------------------------------------------
;; DSL experimentation

;;(? (pivot :ocean oceans (keyword (count-value-key nil)))(ccount)(split :ocean)(from "Whales"))


;; (if false
;;   (do
    
;;     ;; all whales
;;     (inspect (? (dfrom "Whales")))

;;     ;; count all whales
;;     (inspect (? (dcount)(dfrom "Whales")))

;;     ;; sum length of all whales
;;     (inspect (? (dsum :length)(dfrom "Whales")))

;;     ;; we're only interested in toothed whales
;;     (inspect (? (dsplit :type (fn [type] (if (isa? whale-hierarchy :odontoceti type) [:odontoceti] []))) (dfrom "Whales")))

;;     ;; we're only interested in rorquals
;;     (inspect (? (dsplit :type (fn [type] (if (isa? whale-hierarchy :balaenopteridae type) [:balaenopteridae] []))) (dfrom "Whales")))

;;     ;; split by suborder
;;     (do
;;       (def whale-hierarchy-children
;; 	(reduce (fn [reduction [key vals]] (reduce (fn [reduction val] (conj reduction [val key])) reduction vals)) {} (whale-hierarchy :parents)))
      
;;       (def whale-type-to-suborder
;; 	(reduce (fn [reduction type] (conj reduction [type (whale-hierarchy-children (whale-hierarchy-children type))])) {} types))
      
;;       (inspect (? (dsplit :type (fn [type] [(whale-type-to-suborder type)])) (dfrom "Whales"))))
    
;;     ;; split by family
;;     (do
;;       (def whale-hierarchy-children
;; 	(reduce (fn [reduction [key vals]] (reduce (fn [reduction val] (conj reduction [val key])) reduction vals)) {} (whale-hierarchy :parents)))
      
;;       (def whale-type-to-family
;; 	(reduce (fn [reduction type] (conj reduction [type (whale-hierarchy-children type)])) {} types))
      
;;       (inspect (? (dsplit :type (fn [type] [(whale-type-to-family type)])) (dfrom "Whales"))))

;;     ;; split by ocean
;;     (inspect (? (dsplit :ocean)(dfrom "Whales")))
;;     (inspect (? (dsplit :ocean)(dfrom "WhalesAndOceans")))

;;     ;; flat split by type then ocean
;;     (inspect (? (dsplit :ocean)(dsplit :type)(dfrom "Whales")))

;;     ;; nested split by type then ocean
;;     (inspect (? (dsplit :type list [(dsplit :ocean)])(dfrom "Whales")))

;;     (inspect (? (dsplit :type list [(dunion)(dsplit :ocean)])(dfrom "Whales")))

;;     ;; sum weights per ocean
;;     (inspect (? (dsum :weight)(dsplit :ocean)(dfrom "Whales")))

;;     ;; summarise weights per ocean
;;     (inspect (? (dunion)(dsum :weight)(dsplit :ocean)(dfrom "Whales")))
;;     ;; summarise weights per type
;;     (inspect (? (dunion)(dsum :weight)(dsplit :type)(dfrom "Whales")))

;;     ;; pivot weights per ocean summary
;;     (inspect (? (dpivot :ocean ["arctic" "atlantic" "indian" "pacific" "southern"] (keyword "sum(:weight)")) (dsum :weight) (dsplit :ocean) (dfrom "Whales")))

;;     ;; for each type - pivot weights per ocean summary
;;     (inspect (? (dsplit :type list [(dpivot :ocean ["arctic" "atlantic" "indian" "pacific" "southern"] (keyword "sum(:weight)")) (dsum :weight) (dsplit :ocean)]) (dfrom "Whales")))

;;     (inspect (? (dsplit :type list [(dunion)(dpivot :ocean ["arctic" "atlantic" "indian" "pacific" "southern"] (keyword "sum(:weight)")) (dsum :weight) (dsplit :ocean)]) (dfrom "Whales")))

;; ;; TODO
;; ;; split multiple dimensions at same time...
;; ;; reduce multiple columns at same time...
;; ;; rethink pivot 
;; ;; support adding/deleting UI rows
;; ;; support updating UI rows

;;   ;;(? (union "count/type/ocean")(split :type nil [(pivot :ocean oceans (keyword (count-value-key nil)))(ccount)(split :ocean )]) (from "Whales"))
;;   ;;(? (union "count/ocean/type")(split :ocean nil [(pivot :type types (keyword (count-value-key nil)))(ccount)(split :type )]) (from "Whales"))

;;   ;; weight/ocean/type
;;   ;;(inspect (? (dsplit :type nil [(dpivot :ocean oceans (keyword (sum-value-key :weight)))(dsum :weight)(dsplit :ocean )])(dfrom "Whales")))
  
;;   ;; weight/type/ocean
;;   ;;(inspect (? (dsplit :ocean nil [(dpivot :type types (keyword (sum-value-key :weight)))(dsum :weight)(dsplit :type )])(dfrom "Whales")))

;;     ))

(if false
  (do
