Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FromSql trait not implemented for types used in sqllogictest postgres_engine #8042

Closed
spaydar opened this issue Nov 3, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@spaydar
Copy link
Contributor

spaydar commented Nov 3, 2023

Describe the bug

When trying to complete Postgres-compatible sqllogictests in a new file pg_compat_timestamps on spaydar:7868 for #7868, the build fails with errors indicating the FromSql trait is not implemented for rust_decimal:Decimal, NaiveDate, NaiveTime, and NaiveDateTime

To Reproduce

Run the following terminal command and observe the build failure output

$ PG_COMPAT=true PG_URI="postgresql://postgres@127.0.0.1/postgres" cargo test --features=postgres --test sqllogictests -- pg_compat_timestamps --complete
   Compiling datafusion-sqllogictest v32.0.0 (~/arrow-datafusion/datafusion/sqllogictest)
error[E0277]: the trait bound `rust_decimal::Decimal: FromSql<'_>` is not satisfied
   --> datafusion/sqllogictest/src/engines/postgres_engine/mod.rs:306:38
    |
306 |         let value: Option<$t> = $row.get($idx);
    |                                      ^^^ the trait `FromSql<'_>` is not implemented for `rust_decimal::Decimal`
...
320 |         Type::NUMERIC => make_string!(row, idx, Decimal, decimal_to_str),
    |                          ----------------------------------------------- in this macro invocation
    |
    = help: the following other types implement trait `FromSql<'a>`:
              bool
              i8
              i16
              i32
              i64
              u32
              f32
              f64
            and 15 others
    = note: required for `Option<rust_decimal::Decimal>` to implement `FromSql<'_>`
note: required by a bound in `tokio_postgres::Row::get`
   --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-postgres-0.7.10/src/row.rs:147:12
    |
144 |     pub fn get<'a, I, T>(&'a self, idx: I) -> T
    |            --- required by a bound in this associated function
...
147 |         T: FromSql<'a>,
    |            ^^^^^^^^^^^ required by this bound in `Row::get`
    = note: this error originates in the macro `make_string` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NaiveDate: FromSql<'_>` is not satisfied
   --> datafusion/sqllogictest/src/engines/postgres_engine/mod.rs:299:38
    |
299 |         let value: Option<$t> = $row.get($idx);
    |                                      ^^^ the trait `FromSql<'_>` is not implemented for `NaiveDate`
...
321 |         Type::DATE => make_string!(row, idx, NaiveDate),
    |                       --------------------------------- in this macro invocation
    |
    = help: the following other types implement trait `FromSql<'a>`:
              bool
              i8
              i16
              i32
              i64
              u32
              f32
              f64
            and 15 others
    = note: required for `Option<NaiveDate>` to implement `FromSql<'_>`
note: required by a bound in `tokio_postgres::Row::get`
   --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-postgres-0.7.10/src/row.rs:147:12
    |
144 |     pub fn get<'a, I, T>(&'a self, idx: I) -> T
    |            --- required by a bound in this associated function
...
147 |         T: FromSql<'a>,
    |            ^^^^^^^^^^^ required by this bound in `Row::get`
    = note: this error originates in the macro `make_string` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NaiveTime: FromSql<'_>` is not satisfied
   --> datafusion/sqllogictest/src/engines/postgres_engine/mod.rs:299:38
    |
299 |         let value: Option<$t> = $row.get($idx);
    |                                      ^^^ the trait `FromSql<'_>` is not implemented for `NaiveTime`
...
322 |         Type::TIME => make_string!(row, idx, NaiveTime),
    |                       --------------------------------- in this macro invocation
    |
    = help: the following other types implement trait `FromSql<'a>`:
              bool
              i8
              i16
              i32
              i64
              u32
              f32
              f64
            and 15 others
    = note: required for `Option<NaiveTime>` to implement `FromSql<'_>`
note: required by a bound in `tokio_postgres::Row::get`
   --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-postgres-0.7.10/src/row.rs:147:12
    |
144 |     pub fn get<'a, I, T>(&'a self, idx: I) -> T
    |            --- required by a bound in this associated function
...
147 |         T: FromSql<'a>,
    |            ^^^^^^^^^^^ required by this bound in `Row::get`
    = note: this error originates in the macro `make_string` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NaiveDateTime: FromSql<'_>` is not satisfied
   --> datafusion/sqllogictest/src/engines/postgres_engine/mod.rs:324:52
    |
324 |             let value: Option<NaiveDateTime> = row.get(idx);
    |                                                    ^^^ the trait `FromSql<'_>` is not implemented for `NaiveDateTime`
    |
    = help: the following other types implement trait `FromSql<'a>`:
              bool
              i8
              i16
              i32
              i64
              u32
              f32
              f64
            and 15 others
    = note: required for `Option<NaiveDateTime>` to implement `FromSql<'_>`
note: required by a bound in `tokio_postgres::Row::get`
   --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-postgres-0.7.10/src/row.rs:147:12
    |
144 |     pub fn get<'a, I, T>(&'a self, idx: I) -> T
    |            --- required by a bound in this associated function
...
147 |         T: FromSql<'a>,
    |            ^^^^^^^^^^^ required by this bound in `Row::get`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `datafusion-sqllogictest` (lib) due to 4 previous errors

Expected behavior

A successful build and sqllogictest completion

Additional context

I can investigate possible solutions e.g. implementing the trait, but thought I'd raise this with the community if someone more familiar knows a quick fix for this

@spaydar spaydar added the bug Something isn't working label Nov 3, 2023
@alamb
Copy link
Contributor

alamb commented Nov 3, 2023

🤔 It seems to work for me:

alamb@MacBook-Pro-8:~/Software/arrow-datafusion$ PG_COMPAT=true PG_URI="postgresql://postgres@127.0.0.1/postgres" cargo test --features=postgres --test sqllogictests -- pg_compat_timestamps --complete
   Compiling datafusion-common v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/common)
   Compiling datafusion-expr v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/expr)
   Compiling datafusion-physical-expr v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/physical-expr)
   Compiling datafusion-execution v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/execution)
   Compiling datafusion-sql v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/sql)
   Compiling datafusion-optimizer v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/optimizer)
   Compiling datafusion-physical-plan v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/physical-plan)
   Compiling datafusion v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/core)
   Compiling datafusion-sqllogictest v32.0.0 (/Users/alamb/Software/arrow-datafusion/datafusion/sqllogictest)
    Finished test [unoptimized + debuginfo] target(s) in 48.80s
     Running bin/sqllogictests.rs (target/debug/deps/sqllogictests-034cac5fc916c502)

@alamb
Copy link
Contributor

alamb commented Nov 3, 2023

I did find if I tried to run cargo test directly from arrow-datafusion/datafusion/sqllogictest then I get the error you reported

There is probably a missing feature in the sqllogictets/Cargo.toml file for one of the crates which is activated when run in the larger workspace

@spaydar
Copy link
Contributor Author

spaydar commented Nov 4, 2023

Thanks @alamb, that fixed the issue

@spaydar spaydar closed this as completed Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants