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

Build Scalar with ArrayRef #5459

Closed
jayzhan211 opened this issue Mar 3, 2024 · 1 comment
Closed

Build Scalar with ArrayRef #5459

jayzhan211 opened this issue Mar 3, 2024 · 1 comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@jayzhan211
Copy link
Contributor

jayzhan211 commented Mar 3, 2024

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Describe the solution you'd like

I want to build Scalar with ArrayRef, but I got an err

error[E0277]: the trait bound `std::sync::Arc<arrow_array::GenericListArray<i32>>: arrow_array::Array` is not satisfied
    --> datafusion/common/src/scalar/mod.rs:3352:29
     |
3352 |         let s = Scalar::new(arr);
     |                 ----------- ^^^ the trait `arrow_array::Array` is not implemented for `std::sync::Arc<arrow_array::GenericListArray<i32>>`
     |                 |
     |                 required by a bound introduced by this call
     |
     = help: the trait `arrow_array::Array` is implemented for `std::sync::Arc<(dyn arrow_array::Array + 'static)>`
note: required by a bound in `arrow_array::Scalar::<T>::new`
    --> /Users/jayzhan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/arrow-array-50.0.0/src/scalar.rs:130:9
     |
130  | impl<T: Array> Scalar<T> {
     |         ^^^^^ required by this bound in `Scalar::<T>::new`
...
136  |     pub fn new(array: T) -> Self {
     |            --- required by a bound in this associated function

error[E0277]: the trait bound `std::sync::Arc<arrow_array::GenericListArray<i32>>: arrow_array::Array` is not satisfied
    --> datafusion/common/src/scalar/mod.rs:3352:17
     |
3352 |         let s = Scalar::new(arr);
     |                 ^^^^^^^^^^^^^^^^ the trait `arrow_array::Array` is not implemented for `std::sync::Arc<arrow_array::GenericListArray<i32>>`
     |
     = help: the trait `arrow_array::Array` is implemented for `std::sync::Arc<(dyn arrow_array::Array + 'static)>`
note: required by a bound in `arrow_array::Scalar`
    --> /Users/jayzhan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/arrow-array-50.0.0/src/scalar.rs:128:22
     |
128  | pub struct Scalar<T: Array>(T);
     |                      ^^^^^ required by this bound in `Scalar`

error[E0277]: the trait bound `std::sync::Arc<arrow_array::GenericListArray<i32>>: arrow_array::Array` is not satisfied
    --> datafusion/common/src/scalar/mod.rs:3353:26
     |
3353 |         println!("{:?}", s);
     |                   ----   ^ the trait `arrow_array::Array` is not implemented for `std::sync::Arc<arrow_array::GenericListArray<i32>>`
     |                   |
     |                   required by a bound introduced by this call
     |
     = help: the trait `arrow_array::Array` is implemented for `std::sync::Arc<(dyn arrow_array::Array + 'static)>`
     = note: required for `arrow_array::Scalar<std::sync::Arc<arrow_array::GenericListArray<i32>>>` to implement `Debug`
note: required by a bound in `core::fmt::rt::Argument::<'a>::new_debug`
    --> /Users/jayzhan/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/rt.rs:100:29
     |
100  |     pub fn new_debug<'b, T: Debug>(x: &'b T) -> Argument<'_> {
     |                             ^^^^^ required by this bound in `Argument::<'a>::new_debug`
     = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

This is what the code is like which we can also find in Scalar Example, but turns out not working

        let arr = Arc::new(ListArray::from_iter_primitive::<Int32Type, _, _>(vec![
            Some(vec![Some(1), None, Some(2)]),
        ]));
        println!("{:?}", arr);
        let s = Scalar::new(arr);
        println!("{:?}", s);

I'm working on apache/datafusion#8846, and trying to find whether Scalar<Arc<ListArray>> or Arc<Scalar<ListArray>> is better.

however, the previous one meets the error described above, the second one we can only get &dyn Array from fn get(), which doesn't seem like a good way either.

Describe alternatives you've considered

Remove the example that is built with ArrayRef.

Additional context

@jayzhan211 jayzhan211 added the enhancement Any new improvement worthy of a entry in the changelog label Mar 3, 2024
@jayzhan211
Copy link
Contributor Author

I forgot to cast to ArrayRef..

@tustvold tustvold added the arrow Changes to the arrow crate label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

No branches or pull requests

2 participants