Skip to content

Commit 835553e

Browse files
authored
Deprecate ScalarValue bitor, bitand, and bitxor (#6842) (#7351)
* Deprecate ScalarValue bitor, bitand, and bitxor (#6842) * Fixes * Format * Fix BitAndAccumulator
1 parent 9d26397 commit 835553e

File tree

2 files changed

+231
-278
lines changed

2 files changed

+231
-278
lines changed

datafusion/common/src/scalar.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ use arrow::{
4646
DECIMAL128_MAX_PRECISION,
4747
},
4848
};
49-
use arrow_array::{timezone::Tz, ArrowNativeTypeOp};
49+
use arrow_array::timezone::Tz;
50+
use arrow_array::ArrowNativeTypeOp;
5051
use chrono::{Datelike, Duration, NaiveDate, NaiveDateTime};
5152

5253
// Constants we use throughout this file:
@@ -1779,6 +1780,25 @@ macro_rules! eq_array_primitive {
17791780
}
17801781

17811782
impl ScalarValue {
1783+
/// Create a [`ScalarValue`] with the provided value and datatype
1784+
///
1785+
/// # Panics
1786+
///
1787+
/// Panics if d is not compatible with T
1788+
pub fn new_primitive<T: ArrowPrimitiveType>(
1789+
a: Option<T::Native>,
1790+
d: &DataType,
1791+
) -> Self {
1792+
match a {
1793+
None => d.try_into().unwrap(),
1794+
Some(v) => {
1795+
let array = PrimitiveArray::<T>::new(vec![v].into(), None)
1796+
.with_data_type(d.clone());
1797+
Self::try_from_array(&array, 0).unwrap()
1798+
}
1799+
}
1800+
}
1801+
17821802
/// Create a decimal Scalar from value/precision and scale.
17831803
pub fn try_new_decimal128(value: i128, precision: u8, scale: i8) -> Result<Self> {
17841804
// make sure the precision and scale is valid
@@ -2089,11 +2109,13 @@ impl ScalarValue {
20892109
impl_op!(self, rhs, &)
20902110
}
20912111

2112+
#[deprecated(note = "Use arrow kernels or specialization (#6842)")]
20922113
pub fn bitor<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue> {
20932114
let rhs = other.borrow();
20942115
impl_op!(self, rhs, |)
20952116
}
20962117

2118+
#[deprecated(note = "Use arrow kernels or specialization (#6842)")]
20972119
pub fn bitxor<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue> {
20982120
let rhs = other.borrow();
20992121
impl_op!(self, rhs, ^)
@@ -4059,6 +4081,7 @@ mod tests {
40594081
use arrow::datatypes::ArrowPrimitiveType;
40604082
use arrow::util::pretty::pretty_format_columns;
40614083
use arrow_array::ArrowNumericType;
4084+
use chrono::NaiveDate;
40624085
use rand::Rng;
40634086

40644087
use crate::cast::{as_string_array, as_uint32_array, as_uint64_array};

0 commit comments

Comments
 (0)