Skip to content

Commit

Permalink
Attempting to reproduce #22
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Feb 27, 2024
1 parent 365ee4c commit a6c9102
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
3 changes: 1 addition & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{:paths ["src" "lib"]
:deps {techascent/tech.ml.dataset {:mvn/version "7.023"}
:deps {techascent/tech.ml.dataset {:mvn/version "7.025"}
techascent/tech.ml.dataset.sql {:mvn/version "7.000-beta-52"}
cnuernber/dtype-next {:mvn/version "10.109-SNAPSHOT"}
net.java.dev.jna/jna {:mvn/version "5.13.0"}}
:aliases
{:build
Expand Down
17 changes: 17 additions & 0 deletions src/tmducken/duckdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ _unnamed [5 3]:
@initialize*)


(defn duckdb-library-version
^String []
(dt-ffi/c->string (duckdb-ffi/duckdb_library_version)))


(defn- check-lib-version!
[]
(let [lib-version (duckdb-library-version)
parts (.split lib-version "\\.")
mid-part (Integer/parseInt (aget parts 1))]
(when-not (or (not= "v0" (aget parts 0))
(>= mid-part 10))
(throw (RuntimeException. (str "Invalid version: " lib-version " - " "this version of tmducken is meant for duckdb version 0.10.0 and up"))))
:ok))


(defn initialize!
"Initialize the duckdb ffi system. This must be called first should be called only once.
It is safe, however, to call this multiple times.
Expand Down Expand Up @@ -119,6 +135,7 @@ _unnamed [5 3]:
(log/info "Attempting to load in-process duckdb"))
(duckdb-ffi/define-datatypes!)
(dt-ffi/library-singleton-set! duckdb-ffi/lib libpath))))
(check-lib-version!)
true)))
([] (initialize! nil)))

Expand Down
1 change: 1 addition & 0 deletions src/tmducken/duckdb/ffi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ associated with the connection.
:doc "Closes the specified connection and de-allocates all memory allocated for that connection.
* connection: The connection to close."}
:duckdb_library_version {:rettype :pointer}
:duckdb_config_count {:rettype :size-t
:doc "This returns the total amount of configuration options available for usage with `duckdb_get_config_flag`.
Expand Down
28 changes: 28 additions & 0 deletions test/tmducken/duckdb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[tmducken.duckdb.ffi :as duckdb-ffi]
[tech.v3.dataset :as ds]
[tech.v3.datatype.functional :as dfn]
[tech.v3.datatype :as dt]
[tech.v3.datatype.datetime :as dtype-dt]
[tech.v3.resource :as resource])
(:import [java.util UUID]
Expand Down Expand Up @@ -94,6 +95,33 @@
(catch Throwable e nil)))))


(deftest filter-stonks-test
(let [stonks (-> @stocks-src*
(ds/row-map (fn [m]
(cond
(< (:price m) 37.) (update m :price (constantly nil))
:else m)))
(vary-meta assoc :name :stonks))]
(try
(do (duckdb/create-table! @conn* stonks)
(duckdb/insert-dataset! @conn* stonks))
(let [sql-stocks (duckdb/sql->dataset @conn* "select * from stonks")]
(is (= (ds/row-count stonks)
(ds/row-count sql-stocks)))
(is (= (vec (stonks :symbol))
(vec (sql-stocks "symbol"))))
(is (= (vec (stonks :date))
(vec (sql-stocks "date"))))
(is (== (dt/ecount (ds/missing stonks))
(dt/ecount (ds/missing sql-stocks))))
(is (dfn/equals (stonks :price)
(sql-stocks "price"))))
(finally
(try
(duckdb/drop-table! @conn* stonks)
(catch Throwable e nil))))))


(deftest prepared-statements-test
(try
(let [stocks @stocks-src*
Expand Down

0 comments on commit a6c9102

Please sign in to comment.