@@ -46,7 +46,8 @@ use arrow::{
46
46
DECIMAL128_MAX_PRECISION ,
47
47
} ,
48
48
} ;
49
- use arrow_array:: { timezone:: Tz , ArrowNativeTypeOp } ;
49
+ use arrow_array:: timezone:: Tz ;
50
+ use arrow_array:: ArrowNativeTypeOp ;
50
51
use chrono:: { Datelike , Duration , NaiveDate , NaiveDateTime } ;
51
52
52
53
// Constants we use throughout this file:
@@ -1779,6 +1780,25 @@ macro_rules! eq_array_primitive {
1779
1780
}
1780
1781
1781
1782
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
+
1782
1802
/// Create a decimal Scalar from value/precision and scale.
1783
1803
pub fn try_new_decimal128 ( value : i128 , precision : u8 , scale : i8 ) -> Result < Self > {
1784
1804
// make sure the precision and scale is valid
@@ -2089,11 +2109,13 @@ impl ScalarValue {
2089
2109
impl_op ! ( self , rhs, & )
2090
2110
}
2091
2111
2112
+ #[ deprecated( note = "Use arrow kernels or specialization (#6842)" ) ]
2092
2113
pub fn bitor < T : Borrow < ScalarValue > > ( & self , other : T ) -> Result < ScalarValue > {
2093
2114
let rhs = other. borrow ( ) ;
2094
2115
impl_op ! ( self , rhs, |)
2095
2116
}
2096
2117
2118
+ #[ deprecated( note = "Use arrow kernels or specialization (#6842)" ) ]
2097
2119
pub fn bitxor < T : Borrow < ScalarValue > > ( & self , other : T ) -> Result < ScalarValue > {
2098
2120
let rhs = other. borrow ( ) ;
2099
2121
impl_op ! ( self , rhs, ^)
@@ -4059,6 +4081,7 @@ mod tests {
4059
4081
use arrow:: datatypes:: ArrowPrimitiveType ;
4060
4082
use arrow:: util:: pretty:: pretty_format_columns;
4061
4083
use arrow_array:: ArrowNumericType ;
4084
+ use chrono:: NaiveDate ;
4062
4085
use rand:: Rng ;
4063
4086
4064
4087
use crate :: cast:: { as_string_array, as_uint32_array, as_uint64_array} ;
0 commit comments