create_array! Drop (Large)Binary special case and support BinaryView#10400
create_array! Drop (Large)Binary special case and support BinaryView#10400Tpt wants to merge 4 commits into
Conversation
The three types support `From<Vec<&[u8]>>` and `From<Vec<Option<&[u8]>>>`, making the default macro code paths working
|
i'm not sure about this; on main this test compiles fine: #[test]
fn test123() {
let _ = create_array!(Binary, [&[0], &[1]]);
}however with the changes of this PR i get a compile error: arrow-rs (tpt/create_array_binary)$ cargo test -p arrow-array
Compiling arrow-array v59.1.0 (/Users/jeffrey/Code/arrow-rs/arrow-array)
error[E0277]: the trait bound `byte_array::GenericByteArray<types::GenericBinaryType<i32>>: From<Vec<&[{integer}; 1]>>` is not satisfied
--> arrow-array/src/record_batch.rs:130:30
|
130 | std::sync::Arc::new(<$crate::create_array!(@from $ty)>::from(vec![$($values),*]))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
...
1784 | let _ = create_array!(Binary, [&[0], &[1]]);
| ----------------------------------- in this macro invocation
|
help: the trait `From<Vec<&[{integer}; 1]>>` is not implemented for `byte_array::GenericByteArray<types::GenericBinaryType<i32>>`
--> arrow-array/src/array/byte_array.rs:87:1
|
87 | pub struct GenericByteArray<T: ByteArrayType> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: the following other types implement trait `From<T>`:
`byte_array::GenericByteArray<T>` implements `From<arrow_data::ArrayData>`
`byte_array::GenericByteArray<types::GenericBinaryType<OffsetSize>>` implements `From<Vec<&[u8]>>`
`byte_array::GenericByteArray<types::GenericBinaryType<OffsetSize>>` implements `From<Vec<Option<&[u8]>>>`
`byte_array::GenericByteArray<types::GenericBinaryType<OffsetSize>>` implements `From<byte_array::GenericByteArray<types::GenericStringType<OffsetSize>>>`
`byte_array::GenericByteArray<types::GenericBinaryType<T>>` implements `From<list_array::GenericListArray<T>>`
`byte_array::GenericByteArray<types::GenericStringType<OffsetSize>>` implements `From<Vec<&str>>`
`byte_array::GenericByteArray<types::GenericStringType<OffsetSize>>` implements `From<Vec<Option<&str>>>`
`byte_array::GenericByteArray<types::GenericStringType<OffsetSize>>` implements `From<Vec<Option<String>>>`
and 3 others
= note: this error originates in the macro `create_array` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `arrow-array` (lib test) due to 1 previous errorso it seems like a breaking change 🤔 |
Indeed. This is likely because of a change in type inference: when a function like An option is to add more With it the MR has the upside of making What do you think about it? |
|
it's a bit of a niche case indeed; since its technically breaking we'd need to wait for next major release if youre fine with that (we can split the binaryview addition into a separate PR to merge that one faster) |
|
Thank you!
Yes! Of course. Fine to see the MR waiting, I do not have any strong need for it (I got surprised that something I expected to work was not working the way I expected and opened this MR to fix that) |
|
thinking about it some more, im not sure the tradeoff of introducing new unless we have other instances of needing these new |
This |
211affb to
3543db3
Compare
could you elaborate? i was referring to the |
Sorry, I missunderstood your comment. My usecases are:
|
#[test]
fn test123() {
let _ = create_array!(Binary, [b"foo"]);
}this already compiles fine on main. my point here is that while the cleanup is nice, it forces new From API implementations to ensure it maintains the existing behaviour. if the main driver for this PR is just a cleanup, then i dont think we can justify these new APIs; however if there is a separate need for these new From API implementations then theres more rationale for this change (we can still add the |
Yes, it make this work: #[test]
fn test123() {
let _ = create_array!(Binary, [Some(b"foo"), None]);
}With the current macro definition, it will expand to Sorry for so many back and force, please close if you still disagree and I will open an MR for |
The three types support
From<Vec<&[u8]>>andFrom<Vec<Option<&[u8]>>>, making the default macro code paths workingRationale for this change
Simplify code and adds
BinaryViewsupportAre these changes tested?
create_array!(Binary)is already covered in the tests