 (println "LOADED")
 
 nil
+
+;;--------------------------------------------------------------------------------
+;; fix so that a split/pivot can handle undeclared keys


;; create some whales...

(def num-whales 1000)

(def some-whales1
     (pmap (fn [id] (whale id)) (range num-whales)))

(def some-whales
     (let [#^Creator creator (.getCreator whale-metadata)]
       (map
	#(.create creator (into-array Object %))
	(list 
	 [0 0 (Date. 0 1 1) "blue whale" "arctic" 100 0]
	 [1 0 (Date. 0 1 1) "blue whale" "indian" 200 0]
	 [2 0 (Date. 0 1 1) "gray whale" "arctic" 101 0]
	 [3 0 (Date. 0 1 1) "gray whale" "indian" 200 0]
	 [4 0 (Date. 1 1 1) "blue whale" "arctic" 100 0]
	 [5 0 (Date. 1 1 1) "blue whale" "indian" 200 0]
	 [6 0 (Date. 1 1 1) "gray whale" "arctic" 100 0]
	 [7 0 (Date. 1 1 1) "gray whale" "indian" 200 0]
	 ))
       ))

(doall (map #(println "WHALES:" (bean %)) some-whales))

(time
 (doall

					  (insert *metamodel* count-model)
					  (insert tgt-metamodel [count-model extra-pairs])
					  (connect src-model count-model))))]
		 [tgt-metamodel new-prefix extra-pairs])))])))

(defn sum [& [sum-key]]
  (fn [[metadata-fn data-fn]]
      (let [[#^Metadata src-metadata metaprefix extra-keys] (metadata-fn)
	    ;;dummy (println "SUM METADATA" metaprefix extra-keys)
	    extra-attributes (map (fn [key] (.getAttribute src-metadata key)) extra-keys)
	    tgt-metadata (sum-reducer-metadata extra-keys sum-key extra-attributes)]
	[ ;; metadata
	 (fn []
	     [tgt-metadata (str metaprefix "." (sum-value-key sum-key)) extra-keys])
	 ;; direct
	 (if data-fn
	   (fn []
	       (let [[#^Model src-metamodel prefix #^Collection extra-pairs] (data-fn)
		     new-prefix (str prefix "." (sum-value-key sum-key))
		     tgt-model (model new-prefix nil src-metadata)
		     tgt-metamodel (meta-view
				    (str "." (sum-value-key sum-key))
				    src-metamodel
				    (fn [tgt-metamodel #^Model src-model extra-pairs]
					;;(println "SUM DATA:" extra-values)
					(let [sum-model (do-reduce-sum 
							 (.getName src-model)
							 (.getMetadata src-model)
							 tgt-metadata
							 sum-key
							 extra-pairs)]
					  (insert *metamodel* sum-model)
					  (insert tgt-metamodel [sum-model extra-pairs])
					  (connect src-model sum-model))))]
		 [tgt-metamodel new-prefix extra-pairs])))])))

(defn split-key-value [key]
