             [clojure.set :as set]
             [clojure.string :as s]
             [hugsql.core :as hugsql])
-  (:import [java.sql Timestamp]))
+  (:import [akvo.lumen.import.common Geoshape Geopoint]
+           [java.sql Timestamp]))
 
 (hugsql/def-db-fns "akvo/lumen/transformation.sql")
 (hugsql/def-db-fns "akvo/lumen/transformation/engine.sql")

          (or aggregationColumn mergeColumn)
          aggregationDirection))

(defn to-sql-types [row merge-columns]
  ;; For now we only need to change date types.
  (let [date-columns (filter #(= "date" (get % "type")) merge-columns)]
    (reduce (fn [result-row {:strs [columnName]}]
              (update result-row columnName #(when % (Timestamp. %))))
            row
            date-columns)))

(defn fetch-data
  "Fetch data from the source dataset and returns a map with the shape

    (add-column conn {:table-name table-name
                      :new-column-name (get column "columnName")
                      :column-type (condp = (get column "type")
                                     "date" "timestamptz"
                                     "geopoint" "geometry(POINT, 4326)"
                                     "geoshape" "geometry(GEOMETRY, 4326)"
                                     "number" "double precision"
                                     "text" "text")})))

(defn insert-merged-data
  "Insert the merged values into the target dataset"
