Skip to content

Commit

Permalink
Merging master in
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Sep 14, 2024
2 parents 1eab826 + b08346b commit 73ca10a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:paths ["src" "lib"]
:deps {techascent/tech.ml.dataset {:mvn/version "7.026"}
:deps {techascent/tech.ml.dataset {:mvn/version "7.032"}
techascent/tech.ml.dataset.sql {:mvn/version "7.000-beta-52"}
net.java.dev.jna/jna {:mvn/version "5.13.0"}}
:aliases
Expand Down
18 changes: 15 additions & 3 deletions src/tmducken/duckdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ tmducken.duckdb> (get-config-options)
(.address (dt-ffi/->pointer ptr)))


(defn toggle-long-msb
[x]
(bit-xor x Long/MIN_VALUE))

(defn insert-dataset!
"Append this dataset using the higher performance append api of duckdb. This is recommended
as opposed to using sql statements or prepared statements. That being said the schema of this
Expand Down Expand Up @@ -437,7 +441,7 @@ tmducken.duckdb> (get-config-options)
(if uuid
(do
(.putLong us laddr (.getLeastSignificantBits uuid))
(.putLong us (+ laddr 8) (.getMostSignificantBits uuid)))
(.putLong us (+ laddr 8) (toggle-long-msb (.getMostSignificantBits uuid))))
(do
(.putLong us laddr 0)
(.putLong us (+ laddr 8) 0))))))))))
Expand Down Expand Up @@ -553,6 +557,7 @@ tmducken.duckdb> (get-config-options)

(deftype ^:private UUIDReader [])


(defn- coldata->buffer
[^RoaringBitmap missing ^long n-rows ^long duckdb-type ^long data-ptr]
(case (get duckdb-ffi/duckdb-type-map duckdb-type)
Expand Down Expand Up @@ -618,8 +623,15 @@ tmducken.duckdb> (get-config-options)
(reify IFnDef$LO
(invokePrim [this idx]
(let [laddr (+ data-ptr (* idx 16))]
(UUID. (.getLong us (+ laddr 8))
(.getLong us laddr))))))
;; typedef struct {
;; uint64_t lower;
;; int64_t upper;
;; } duckdb_hugeint;
;; For some reason the msb when r/w with duckdb api nee to be inverted.
(let [msbytes (.getLong us (+ laddr 8))
msbytes (toggle-long-msb msbytes)
lsbytes (.getLong us laddr)]
(UUID. msbytes lsbytes))))))
0 n-rows)

:DUCKDB_TYPE_VARCHAR
Expand Down
15 changes: 15 additions & 0 deletions test/tmducken/duckdb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@
{"country" "US", "name" "Seattle", "2010" 608}]
(ds/rows result-ds))))))

(deftest uuid-test
(let [id (random-uuid)
data (ds/->dataset [{:id id}] {:dataset-name "uuid_test"})]
(try
(duckdb/drop-table! @conn* "uuid_test")
(catch Throwable _ nil))
(duckdb/create-table! @conn* data)
(duckdb/insert-dataset! @conn* data)
(let [result-ds (duckdb/sql->dataset
@conn*
(format "SELECT id from uuid_test where id = '%s'" id))]
(is (some? result-ds))
(is (= 1 (count (ds/rows result-ds))))
(is (= [{"id" id}] (ds/rows result-ds))))))

(deftest show-all-tables-test
(try
(duckdb/drop-table! @conn* "foo")
Expand Down

0 comments on commit 73ca10a

Please sign in to comment.