1
私はClojureを初めて使用し、jdbcアプリケーションで作業しています。文字列内のすべてのクエリの結果を実現
(def tpch_query15
(str "create view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) "
"from lineitem where l_shipdate >= date '1993-04-01' and l_shipdate < date '1993-04-01' + interval '3' month group by l_suppkey; "
"select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue0 where s_suppkey = supplier_no "
"and total_revenue = (select max(total_revenue) from revenue0) order by s_suppkey LIMIT 1; drop view revenue0"))
(defn run-a-query
"Run a query three times and return the average time."
[conn-db query queryno]
(println (str "Running query " queryno))
(let [starttime (System/currentTimeMillis)]
(dotimes [n 3]
(try
(let
[rs (sql/query conn-db query)]
;; Print column names with | as delimiter
(dorun 0 (map #(println (clojure.string/join " | " (keys %))) rs))
;; Print a seperator between column names and rows
(println "------------------------------------------------------")
;; Print rows with | as delimiter
(dorun (map #(println (clojure.string/join " | " (vals %))) rs)))
(catch Exception e)))
(/ (- (System/currentTimeMillis) starttime) 3.0)))
;;https://clojuredocs.org/clojure.core/conj!
(defn run-all-queries
"Run all TPC-H queries. Return a vector of average time taken for each query."
[conn-db]
(loop [i 0 v (transient [])]
(if (< i 22)
(recur (inc i) (conj! v (run-a-query conn-db (get queries-to-run i) (+ i 1))))
(persistent! v))))
run-a-query関数では、その文字列で定義された3つのクエリすべての結果を出力できますか?現在run-a-queryにtpch_query15が渡された場合、結果は表示されません。私が理解しているところから、これは、ドロップビューである3つのクエリのうち最後のものが結果セットを返さず、最後のクエリ結果のみを返すためです。