1919
2020use arrow:: array:: { Array , ArrayRef , AsArray , BinaryArray , BinaryArrayType } ;
2121use arrow:: datatypes:: DataType ;
22- use blake2:: { Blake2b512 , Blake2s256 , Digest } ;
22+ use blake2:: { Blake2b512 , Blake2s256 } ;
2323use blake3:: Hasher as Blake3 ;
2424
2525use arrow:: compute:: StringArrayType ;
@@ -85,7 +85,8 @@ impl fmt::Display for DigestAlgorithm {
8585}
8686
8787macro_rules! digest_to_array {
88- ( $METHOD: ident, $INPUT: expr) => { {
88+ ( $MODULE: ident, $METHOD: ident, $INPUT: expr) => { {
89+ use $MODULE:: Digest ;
8990 let binary_array: BinaryArray = $INPUT
9091 . iter( )
9192 . map( |x| x. map( |x| $METHOD:: digest( x) ) )
@@ -95,20 +96,23 @@ macro_rules! digest_to_array {
9596}
9697
9798macro_rules! digest_to_scalar {
98- ( $METHOD: ident, $INPUT: expr) => { { ScalarValue :: Binary ( $INPUT. map( |v| $METHOD:: digest( v) . as_slice( ) . to_vec( ) ) ) } } ;
99+ ( $MODULE: ident, $METHOD: ident, $INPUT: expr) => { {
100+ use $MODULE:: Digest ;
101+ ScalarValue :: Binary ( $INPUT. map( |v| $METHOD:: digest( v) . as_slice( ) . to_vec( ) ) )
102+ } } ;
99103}
100104
101105impl DigestAlgorithm {
102106 /// digest an optional string to its hash value, null values are returned as is
103107 fn digest_scalar ( self , value : Option < & [ u8 ] > ) -> ColumnarValue {
104108 ColumnarValue :: Scalar ( match self {
105- Self :: Md5 => digest_to_scalar ! ( Md5 , value) ,
106- Self :: Sha224 => digest_to_scalar ! ( Sha224 , value) ,
107- Self :: Sha256 => digest_to_scalar ! ( Sha256 , value) ,
108- Self :: Sha384 => digest_to_scalar ! ( Sha384 , value) ,
109- Self :: Sha512 => digest_to_scalar ! ( Sha512 , value) ,
110- Self :: Blake2b => digest_to_scalar ! ( Blake2b512 , value) ,
111- Self :: Blake2s => digest_to_scalar ! ( Blake2s256 , value) ,
109+ Self :: Md5 => digest_to_scalar ! ( md5 , Md5 , value) ,
110+ Self :: Sha224 => digest_to_scalar ! ( sha2 , Sha224 , value) ,
111+ Self :: Sha256 => digest_to_scalar ! ( sha2 , Sha256 , value) ,
112+ Self :: Sha384 => digest_to_scalar ! ( sha2 , Sha384 , value) ,
113+ Self :: Sha512 => digest_to_scalar ! ( sha2 , Sha512 , value) ,
114+ Self :: Blake2b => digest_to_scalar ! ( blake2 , Blake2b512 , value) ,
115+ Self :: Blake2s => digest_to_scalar ! ( blake2 , Blake2s256 , value) ,
112116 Self :: Blake3 => ScalarValue :: Binary ( value. map ( |v| {
113117 let mut digest = Blake3 :: default ( ) ;
114118 digest. update ( v) ;
@@ -125,13 +129,13 @@ impl DigestAlgorithm {
125129 StringArrType : StringArrayType < ' a > ,
126130 {
127131 match self {
128- Self :: Md5 => digest_to_array ! ( Md5 , input_value) ,
129- Self :: Sha224 => digest_to_array ! ( Sha224 , input_value) ,
130- Self :: Sha256 => digest_to_array ! ( Sha256 , input_value) ,
131- Self :: Sha384 => digest_to_array ! ( Sha384 , input_value) ,
132- Self :: Sha512 => digest_to_array ! ( Sha512 , input_value) ,
133- Self :: Blake2b => digest_to_array ! ( Blake2b512 , input_value) ,
134- Self :: Blake2s => digest_to_array ! ( Blake2s256 , input_value) ,
132+ Self :: Md5 => digest_to_array ! ( md5 , Md5 , input_value) ,
133+ Self :: Sha224 => digest_to_array ! ( sha2 , Sha224 , input_value) ,
134+ Self :: Sha256 => digest_to_array ! ( sha2 , Sha256 , input_value) ,
135+ Self :: Sha384 => digest_to_array ! ( sha2 , Sha384 , input_value) ,
136+ Self :: Sha512 => digest_to_array ! ( sha2 , Sha512 , input_value) ,
137+ Self :: Blake2b => digest_to_array ! ( blake2 , Blake2b512 , input_value) ,
138+ Self :: Blake2s => digest_to_array ! ( blake2 , Blake2s256 , input_value) ,
135139 Self :: Blake3 => {
136140 let binary_array: BinaryArray = input_value
137141 . iter ( )
@@ -156,13 +160,13 @@ impl DigestAlgorithm {
156160 BinaryArrType : BinaryArrayType < ' a > ,
157161 {
158162 match self {
159- Self :: Md5 => digest_to_array ! ( Md5 , input_value) ,
160- Self :: Sha224 => digest_to_array ! ( Sha224 , input_value) ,
161- Self :: Sha256 => digest_to_array ! ( Sha256 , input_value) ,
162- Self :: Sha384 => digest_to_array ! ( Sha384 , input_value) ,
163- Self :: Sha512 => digest_to_array ! ( Sha512 , input_value) ,
164- Self :: Blake2b => digest_to_array ! ( Blake2b512 , input_value) ,
165- Self :: Blake2s => digest_to_array ! ( Blake2s256 , input_value) ,
163+ Self :: Md5 => digest_to_array ! ( md5 , Md5 , input_value) ,
164+ Self :: Sha224 => digest_to_array ! ( sha2 , Sha224 , input_value) ,
165+ Self :: Sha256 => digest_to_array ! ( sha2 , Sha256 , input_value) ,
166+ Self :: Sha384 => digest_to_array ! ( sha2 , Sha384 , input_value) ,
167+ Self :: Sha512 => digest_to_array ! ( sha2 , Sha512 , input_value) ,
168+ Self :: Blake2b => digest_to_array ! ( blake2 , Blake2b512 , input_value) ,
169+ Self :: Blake2s => digest_to_array ! ( blake2 , Blake2s256 , input_value) ,
166170 Self :: Blake3 => {
167171 let binary_array: BinaryArray = input_value
168172 . iter ( )
0 commit comments