 (ns akvo.lumen.endpoint.split-column
   (:require [akvo.lumen.protocols :as p]
             [akvo.lumen.lib :as lib]
+            [akvo.lumen.db.transformation :as db.transformation]
             [akvo.lumen.lib.transformation.split-column :as transformation]
             [clojure.spec.alpha :as s]
             [akvo.lumen.component.tenant-manager :as tenant-manager]

        tenant :tenant}]
    (let [query           (json/parse-string (get query-params "query") keyword)
          tenant-conn     (p/connection tenant-manager tenant)
          dataset-version (latest-dataset-version-by-dataset-id tenant-conn {:dataset-id dataset-id})
          sql-query       {:table-name  (:table-name dataset-version)
                           :column-name (:columnName query)
                           :limit       (str (:limit query "200"))}
          values          (map (comp str (keyword (:columnName query)))
                               (select-random-column-data tenant-conn sql-query))
          pattern-analysis (transformation/pattern-analysis (re-pattern "[^a-zA-Z0-9\\s]") values)]
      (lib/ok {:analysis (sort-pattern-analysis-by pattern-analysis :total-row-coincidences)}))))


            [clojure.tools.logging :as log]
            [hugsql.core :as hugsql]
            [integrant.core :as ig]))

(defn sort-pattern-analysis-by [pattern-analysis sort-by*]
  (->> (seq (:analysis pattern-analysis))
