 
 ;; create some whales...
 
-(def num-whales 1000)
+(def num-whales 10
+)
 
 (time
  (doall
   (let [batcher (Batcher. 999 1000 (list whales-model))]
-    (pmap (fn [id] (insert whales-model (whale id))) (range num-whales)))))
+    (map (fn [id] (insert whales-model (whale id))) (range num-whales))))) ;TODO: reinstate pmap later
 
 (println "LOADED: " num-whales)
 

		  [(meta-view
		    (str "=" extra-value)
		    tgt-metamodel
		    (fn [tgt-metamodel2 model & extra-values]
			;;(insert tgt-metamodel tgt-metamodel2)
			(insert tgt-metamodel2 [model])
			;;(insert *metamodel* model)
			))
		   src-metadata
		   []]))
	       model
	       )))))
   src-metadata
   (concat extra-keys [split-key])])

;; extra keys are inserted into attribute list
;; extra values are carried in model's row in metamodel
;; each split adds an extra key/value downstream that we may need to unwrap upstream
(defn ccount [[#^Model src-metamodel #^Metadata src-metadata #^Collection extra-keys]
	      & [count-key]]
  (let [extra-attributes (map (fn [key] (.getAttribute src-metadata key)) extra-keys)
	tgt-metadata (count-reducer-metadata extra-keys count-key extra-attributes)]
    [(meta-view
      (str "." (count-value-key count-key))
      src-metamodel
      (fn [tgt-metamodel #^Model src-model & extra-values]
	  (let [count-model (do-reduce-count 
			     (.getName src-model)
			     (.getMetadata src-model)

;; pivot-key - e.g. :time
;; pivot-values - e.g. years
;; value-key - e.g. :count(*) - needed to find type of new columns
(defn pivot [[#^Model src-metamodel #^Metadata src-metadata prefix #^Collection extra-keys] pivot-key pivot-values value-key]
  (println "pivot" prefix ":" extra-keys)
  (let [pivot-name (str ".pivot(" value-key "/" pivot-key")")
	pivot-metadata (pivot-metadata src-metadata extra-keys pivot-values value-key)
	tgt-model (PivotModel. 
		   (str prefix pivot-name)
		   src-metadata
		   (fn [old new] new)	;TODO - sort out version-fn
		   value-key
		   pivot-values
		   pivot-metadata)
