Skip to content

Commit

Permalink
Fixes #36 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber authored Sep 15, 2024
1 parent 3da4360 commit 343dcc0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/tmducken/duckdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,14 @@ tmducken.duckdb> (get-config-options)
dataset must match *precisely* the schema of the target table."
([conn dataset options]
(resource/stack-resource-context
(let [table-name (sql/table-name dataset options)
(let [table-name (str (sql/table-name dataset options))
app-ptr-ptr (dt-ffi/make-ptr :pointer 0)
app-status (duckdb-ffi/duckdb_appender_create conn "" table-name app-ptr-ptr)
dotindex (.indexOf table-name (int \.))
[schema table] (if (== -1 dotindex)
["" table-name]
[(.substring table-name 0 dotindex)
(.substring table-name (inc dotindex))])
app-status (duckdb-ffi/duckdb_appender_create conn schema table app-ptr-ptr)
appender (Pointer. (app-ptr-ptr 0))
;;this is fine because we are hardcoding to track via stack.
;;Normally dispose-fn cannot reference things being tracked
Expand Down
9 changes: 9 additions & 0 deletions test/tmducken/duckdb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,12 @@
"local_dates"
"local_times"}
(set (first (alltables "column_names")))))])))


(deftest schema-support
(let [ds (-> (ds/->dataset [{:a 1}])
(ds/set-dataset-name :foo.table))]
(duckdb/run-query! @conn* "CREATE SCHEMA foo")
(duckdb/create-table! @conn* ds)
(duckdb/insert-dataset! @conn* ds)
(is (= [1] ((duckdb/sql->dataset @conn* "select * from foo.table") "a")))))

0 comments on commit 343dcc0

Please sign in to comment.