-
Notifications
You must be signed in to change notification settings - Fork 46
Description
Hi,
First of all thank you very much for sharing and working on the duckdb-r library. I wonder if someone could give me a hand.
When loading/transfering a spatial object (sf) by using duckdb::dbWriteTable() , I got the following error
Error in `duckdb_result()`:
! Invalid Error: Conversion Error: Expected geometry type at position '0' near: '0'|<---
ℹ Context: rapi_execute
ℹ Error type: INVALID
ℹ Raw message: Conversion Error: Expected geometry type at position '0' near: '0'|<---
Run `rlang::last_trace()` to see where the error occurred.
These were the steps:
- Load the sf object, for example using GiscoR
zurich <- giscoR::gisco_get_nuts(country="CH", nuts_level=2) |>
dplyr::filter(NAME_LATN == "Zürich")
- Create the database
con <- duckdb::dbConnect(duckdb())
- Install and load the spatial extension
dbExecute(con, "install spatial; load spatial;")
- Transfer the sf object to duckdb
duckdb::dbWriteTable(con, "zurich", zurich)
The error appeared in the last step (4). To be fair, the official documentation mentions "data frame", not a sf object. Since it is trying to read the geometry, I would say it is also possible to transfer a sf object into the duckdb database. I tried other sf objects (in case the geometry was invalid) with the same result. The CRS is 4326.
The duckdb-r version used was:
> dbGetQuery(con, "PRAGMA version;")
library_version source_id codename
1 v1.4.1 b390a7c376 Andium
Thank you for your time
rlang::last_trace(drop = FALSE)
<error/rlang_error>
Error induckdb_result():
! Invalid Error: Conversion Error: Expected geometry type at position '0' near: '0'|<---
ℹ Context: rapi_execute
ℹ Error type: INVALID
ℹ Raw message: Conversion Error: Expected geometry type at position '0' near: '0'|<---
Backtrace:
▆
- ├─duckdb::dbWriteTable(con, "zurich", zurich)
- ├─duckdb::dbWriteTable(con, "zurich", zurich)
- │ └─sf (local) .local(conn, name, value, ...)
- │ ├─DBI::dbWriteTable(...)
- │ └─duckdb::dbWriteTable(...)
- │ └─duckdb (local) .local(conn, name, value, ...)
- │ ├─DBI::dbExecute(...)
- │ └─DBI::dbExecute(...)
- │ ├─DBI::dbSendStatement(conn, statement, ...)
- │ └─DBI::dbSendStatement(conn, statement, ...)
- │ ├─DBI::dbSendQuery(conn, statement, ...)
- │ └─duckdb::dbSendQuery(conn, statement, ...)
- │ └─duckdb (local) .local(conn, statement, ...)
- │ └─duckdb:::duckdb_result(connection = conn, stmt_lst = stmt_lst, arrow = arrow)
- │ └─duckdb:::duckdb_execute(res)
- │ └─duckdb:::rethrow_rapi_execute(...)
- │ ├─rlang::try_fetch(...)
- │ │ ├─base::tryCatch(...)
- │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
- │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
- │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
- │ │ └─base::withCallingHandlers(...)
- │ └─duckdb:::rapi_execute(stmt, convert_opts)
- ├─duckdb (local)
<fn>(...) - │ └─rlang::abort(error_parts, class = "duckdb_error", !!!fields)
- │ └─rlang:::signal_abort(cnd, .file)
- │ └─base::signalCondition(cnd)
- └─rlang (local)
<fn>(<dckdb_rr>) - └─handlers[1L]
-
└─duckdb:::rethrow_error_from_rapi(e, call) -
└─rlang::abort(msg, call = call)