duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
470 stars 96 forks source link

Problem with `stmt.query_arrow([])?.collect()` #87

Closed sspaeti closed 1 year ago

sspaeti commented 1 year ago

I'm a total starter and trying to learn Rust with DuckDB. Just close if it's too basic of a question, just posting it here in case others have trouble getting started.

Error:

rustc: a value of type `Vec<RecordBatch>` cannot be built from an iterator over elements of type `arrow::record_batch::RecordBatch` the trait `FromIterator<arrow::record_batch::RecordBatch>` is not implemented for `Vec<RecordBatch>`

Question: What am I doing wrong: image

I understand the rust iterator does not like the arrow RecordBatch. But how can I fix that, did I use the wrong arrow dependencies in my Cargo.toml on the right?

wangfenjin commented 1 year ago

why depends on duckdb 0.1 version but libduckdb-sys 0.5.1 ? suggest to always use the same version, and latest version which is 0.5.1.

0.1 version duckdb doesn't support arrow

sspaeti commented 1 year ago

Thank you so much for your kind answer. OK now I see, I updated to the latest 0.5.1, but still has the same error.

Which Cargo.toml should be used for the simple example on the left? Should that work with the right dependencies, or should I follow something like this https://github.com/wangfenjin/duckdb-rs/blob/main/Cargo.toml?

wangfenjin commented 1 year ago

Refer to #88 , the readme example should works fine. You can try run the example in command line with cargo. Not sure what's the problem with your code editor

sspaeti commented 1 year ago

Didn't really manage to make it work, but I used some part of this https://github.com/hotg-ai/weld-studio/blob/7121cbffbbe7dd4ee703b1dd8b3be89daee1f857/src-tauri/src/sql.rs and removed let rbs: Vec<RecordBatch> = stmt.query_arrow([])?.collect();.

Now I have managed to have a working starting point. Thanks so much; I will close.

wangfenjin commented 1 year ago

Hi @sspaeti

I checked the issue again. The arrow version in your project's Cargo.toml should be same as the version in duckdb (latest one is version 23) . Otherwise it may report error.

Sorry for the inconvenience.

snth commented 1 year ago

I ran into this problem a lot as well and the rustc error message isn't very helpful in this case and doesn't actually tell you what the problem is, i.e. it has nothing to do with an iterator and is actually just a version mismatch between different versions of arrow.

This would be helped a lot by #92 .

sspaeti commented 1 year ago

Excellent, thanks so much, you both. The example of Readme with the arrow version 23 worked!

For anyone else, this is my Cargo.toml:

[package]
name = "duckdb-playground"
version = "0.1.0"
edition = "2021"

[dependencies.duckdb]
version = "0.5.1"
features = ["bundled"]

[dependencies]
libduckdb-sys = "0.5.1"
arrow = { version = "23", features = ["prettyprint", "ffi"] }