alamb commented on code in PR #4704:
URL: https://github.com/apache/arrow-rs/pull/4704#discussion_r1296002346
##########
arrow-array/src/array/byte_array.rs:
##########
@@ -182,6 +182,11 @@ impl<T: ByteArrayType> GenericByteArray<T> {
}
}
+ /// Create a new [`Scalar`] from `v`
+ pub fn new_scalar(value: impl AsRef<T::Native>) -> Scalar<Self> {
Review Comment:
How about BooleanArray and DictonaryArray and ListArray?
##########
arrow-array/src/scalar.rs:
##########
@@ -101,22 +101,23 @@ impl Datum for &dyn Array {
/// A wrapper around a single value [`Array`] indicating kernels should treat
it as a scalar value
///
/// See [`Datum`] for more information
-pub struct Scalar<'a>(&'a dyn Array);
+#[derive(Debug, Copy, Clone)]
+pub struct Scalar<T: Array>(T);
Review Comment:
I think what a user would be looking for is `Scalar::new_primitive() and
`ScalarValue::new_string()`. Without thos signatures function, I predict pretty
much anyone using `Scalars` are going to make some version of the function from
https://github.com/apache/arrow-rs/pull/4701
```rust
fn make_primitive_scalar<T: num::ToPrimitive + std::fmt::Debug>(
d: &DataType,
scalar: T,
) -> Result<ArrayRef, ArrowError> {
match d {
DataType::Int8 => {
let right = try_to_type!(scalar, to_i8)?;
Ok(Arc::new(PrimitiveArray::<Int8Type>::from(vec![right])))
}
DataType::Int16 => {
let right = try_to_type!(scalar, to_i16)?;
Ok(Arc::new(PrimitiveArray::<Int16Type>::from(vec![right])))
}
DataType::Int32 => {
let right = try_to_type!(scalar, to_i32)?;
Ok(Arc::new(PrimitiveArray::<Int32Type>::from(vec![right])))
}
DataType::Int64 => {
let right = try_to_type!(scalar, to_i64)?;
Ok(Arc::new(PrimitiveArray::<Int64Type>::from(vec![right])))
}
DataType::UInt8 => {
let right = try_to_type!(scalar, to_u8)?;
Ok(Arc::new(PrimitiveArray::<UInt8Type>::from(vec![right])))
}
...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]