I am having trouble streaming a large result-set from a MySQL database using clojure.java.jdbc. This is what I'm trying now:
(defn etl! [query result-set-fn]
(jdbc/with-db-transaction [t-conn db-spec]
(let [conn (jdbc/get-connection t-conn)
statement (jdbc/prepare-statement conn query
:fetch-size Integer/MIN_VALUE
:concurrency :read-only
:result-type :forward-only)]
(jdbc/query conn [statement] :result-set-fn first))))
I have also tried it without the transaction and with (.setAutoCommit conn False)
(which is necessary for Postgres). According to the MySQL docs, setting that fetch-size, concurrency and result-type should tell MySQL to deliver the results one at a time, but that doesn't seem to be happening; the query hangs and heap consumption rises steadily for at least hundreds of megabytes.
A similar question was asked a few years ago, but the answer has now been deprecated by clojure.java.jdbc: Streaming from MySQL with clojure.java.jdbc
Any ideas?