         (is (= years-slash (map (comp tcc/from-long :c3) table-data)))
         (is (= years-hiphen (map (comp tcc/from-long :c4) table-data)))))))
 
-
-(defn change-datatype-transformation [column-name]
-  {:type :transformation
-   :transformation
-   (-> (gen-transformation
-        :core/change-datatype {:akvo.lumen.specs.db.dataset-version.column/columnName "column-name"
-                               :akvo.lumen.specs.transformation.change-datatype/newType "number"
-                               :akvo.lumen.specs.transformation.engine/onError "default-value"})
-       (assoc-in ["args" "defaultValue"] nil) ;; we can generate nil values ... spec related
-       )})
-
-(defn latest-data [dataset-id]
-  (let [table-name (:table-name
-                    (latest-dataset-version-by-dataset-id *tenant-conn* {:dataset-id dataset-id}))]
-    (get-data *tenant-conn* {:table-name table-name})))
-
 (deftest ^:functional derived-column-test
-  (let [dataset-id (import-file *tenant-conn* *error-tracker* {:has-column-headers? true
+  (let [change-datatype-transformation (fn [column-name]
+                                         {:type :transformation
+                                          :transformation
+                                          (-> (gen-transformation
+                                               :core/change-datatype {::db.dataset-version.column.s/columnName "column-name"
+                                                                      ::transformation.change-datatype.s/newType "number"
+                                                                      ::transformation.engine.s/onError "default-value"})
+                                              (assoc-in ["args" "defaultValue"] nil))})
+        dataset-id (import-file *tenant-conn* *error-tracker* {:has-column-headers? true
                                                                :file "derived-column.csv"})
         apply-transformation (partial transformation/apply {:tenant-conn *tenant-conn*} dataset-id)]
     (do (apply-transformation (change-datatype-transformation "c2"))

      (apply-transformation {:type :transformation
                             :transformation
                             (gen-transformation :core/derive
                                                 {:akvo.lumen.specs.transformation.derive/newColumnTitle "Derived 4"
                                                  :akvo.lumen.specs.transformation.derive/code "row['foo'].toUpperCase()"
                                                  :akvo.lumen.specs.transformation.derive/newColumnType "text"
                                                  :akvo.lumen.specs.transformation.engine/onError "leave-empty"})})
      (is (= ["A" "B" nil] (map :d2 (latest-data dataset-id))))

      (apply-transformation {:type :transformation
                             :transformation
                             (gen-transformation :core/derive
                                                 {:akvo.lumen.specs.transformation.derive/newColumnTitle "Derived 5"
                                                  :akvo.lumen.specs.transformation.derive/code "row['Derived 4'].toLowerCase()"
                                                  :akvo.lumen.specs.transformation.derive/newColumnType "text"
                                                  :akvo.lumen.specs.transformation.engine/onError "leave-empty"})})
      (is (= ["a" "b" nil] (map :d3 (latest-data dataset-id)))))

    (testing "Date transform"
      (let [[tag _] (apply-transformation {:type :transformation
                                           :transformation
                                           (gen-transformation :core/derive
                                                               {:akvo.lumen.specs.transformation.derive/newColumnTitle "Derived 5"
                                                                :akvo.lumen.specs.transformation.derive/code "new Date()"
                                                                :akvo.lumen.specs.transformation.derive/newColumnType "date"
                                                                :akvo.lumen.specs.transformation.engine/onError "fail"})})]
        (is (= tag ::lib/ok))
        (is (every? number? (map :d4 (latest-data dataset-id))))))


      (apply-transformation {:type :transformation
                             :transformation
                             (gen-transformation :core/derive
                                                 {::transformation.derive.s/newColumnTitle "Derived 1"
                                                  ::transformation.derive.s/code "row['foo'].toUpperCase()"
                                                  ::transformation.derive.s/newColumnType "text"
                                                  ::transformation.engine.s/onError "leave-empty"})})
      (is (= ["A" "B" nil] (map :d1 (latest-data dataset-id)))))

    (testing "Basic text transform with drop row on error"
      (apply-transformation {:type :transformation
                             :transformation
                             (gen-transformation :core/derive
                                                 {::transformation.derive.s/newColumnTitle "Derived 3"
                                                  ::transformation.derive.s/code "row['foo'].replace('a', 'b')"
                                                  ::transformation.derive.s/newColumnType "text"
                                                  ::transformation.engine.s/onError "delete-row"})})
      (is (= ["b" "b"] (map :d2 (latest-data dataset-id))))
      ;; Undo this so we have all the rows in the remaining tests
      (apply-transformation {:type :undo}))
