andrusha / snowflake-rs

Snowflake API libraries for Rust
Apache License 2.0
31 stars 26 forks source link

Type error when converting results to polars #48

Open ms-2k opened 5 months ago

ms-2k commented 5 months ago

Hi, I have encountered an issue while building a project using the latest version available on cargo, 0.9.0, with the polars feature enabled. The error is as follows:

error[E0308]: mismatched types
 40 |         .infer_schema_len(Some(5))
    |                           ---- ^ expected `NonZero<usize>`, found integer
    |                           |
    |                           arguments to this enum variant are incorrect
    |
    = note: expected struct `NonZero<usize>`

The issue appears to be in line 40 of the file polars.rs. My build environment was the rust:slim-bookworm docker image on ARM64 using rust version 1.79.0-aarch64-unknown-linux-gnu.

A potential solution I suggest is as follows, starting from line 39:

let df = JsonReader::new(reader)
    .with_json_format(JsonFormat::Json)
    .infer_schema_len(Some(NonZeroUsize::new(5).unwrap()))
    .finish()?;

The modification above resolves the issue on my end.

tobisinghania commented 4 months ago

This error only pops up when using the latest polars-rs version 0.41.3, specifically because of this PR https://github.com/pola-rs/polars/pull/16770

The unwrap in the proposal for the fix is not needed btw, since NonZeroUsize::new returns an option already:

let df = JsonReader::new(reader)
    .with_json_format(JsonFormat::Json)
    .infer_schema_len(NonZeroUsize::new(5))
    .finish()?;