java - Clojure Reflection warning - call to write can't be resolved -
i'm struggling correct type hints avoid warn on reflection while writing text-file-output database query.
i've tried put ^string type hints before each function being called, output going hit text file on disk.
the reflection warning occurs on :row-fn line towards end of function. have comment reflection warning, dbdump/dbdump.clj:157:44 - call write can't resolved.
on same line.
how can rid of warning? i'm thinking there performance cost when working large datasets.
(defn run-job [job-time-string db-spec config] (let [; {{{ source-sql (str "select * " (:source-base-name config)(:table-name config)) max-rows (:max-rows config) fetch-size (:fetch-size config) working-dir (:working-dir config) output-name (str working-dir "/" job-time-string ".pipe" ) field-delim (:field-delim config) row-delim (:row-delim config) log-report-interval (:log-report-interval config) row-count (atom 0) ; state on rows db-connection (doto (j/get-connection db-spec)) statement (j/prepare-statement db-connection source-sql :fetch-size fetch-size :concurrency :read-only :max-rows max-rows) start-in-millis (system/currenttimemillis) replace-newline (^string fn [s] (if (string? s) (clojure.string/replace s #"\n" " ") s)) ; i'd prefer not this; right can't load \n fields. row-fn (^string fn [v] (swap! row-count inc) (when (zero? (mod @row-count log-report-interval)) (write-logs @row-count start-in-millis 3 (:table-name config) )) (str (join field-delim (doall (map #(replace-newline %) v))) row-delim )) ]; }}} (with-open [^java.io.writer wrtr (io/writer output-name )] (info "fetching jdbc query..." ) (info source-sql) (try (j/query db-connection [statement] :as-arrays? true :result-set-fn vec ; reflection warning, dbdump/dbdump.clj:157:44 - call write can not resolved. :row-fn ^string #(.write wrtr (row-fn %))) (catch exception e (error (str "error while fetching jdbc data." (.getmessage e))) (system/exit 9)))) (write-logs @row-count start-in-millis 0 (str (:source-base-name config) (:table-name config) " completed - "))))
the reflection warning tells you need clarify write
method called in #(.write wrtr (row-fn %))
. you'll need type-hint wrtr
, (row-fn %)
:
#(.write ^java.io.writer wrtr ^string (row-fn %))
incidentally, adding type hints fn
forms or function literals has no effect. (well, adding primitive hints make resulting function implement relevant clojure.lang.ifn$[old]+
interface, hints need attached parameter vector and/or individual symbols naming parameters.)
(in contrast, adding type hints function names in defn
forms have effect of placing :tag
metadata on resulting vars; used compiler disambiguate java method calls.)
Comments
Post a Comment