@@ -19,6 +19,7 @@ use databend_common_column::types::Index;
1919use databend_common_exception:: ErrorCode ;
2020use databend_common_exception:: Result ;
2121
22+ use crate :: types:: bitmap:: BitmapColumn ;
2223use crate :: types:: i256;
2324use crate :: types:: number:: Number ;
2425use crate :: types:: AccessType ;
@@ -47,7 +48,6 @@ use crate::types::StringType;
4748use crate :: types:: TimestampType ;
4849use crate :: types:: ValueType ;
4950use crate :: types:: VariantType ;
50- use crate :: utils:: bitmap:: normalize_bitmap_column;
5151use crate :: visitor:: ValueVisitor ;
5252use crate :: with_decimal_mapped_type;
5353use crate :: with_number_mapped_type;
@@ -167,33 +167,40 @@ impl<const IS_FIRST: bool> ValueVisitor for HashVisitor<'_, IS_FIRST> {
167167 }
168168
169169 fn visit_binary ( & mut self , column : BinaryColumn ) -> Result < ( ) > {
170- self . combine_group_hash_string_column :: < BinaryType > ( & column) ;
170+ self . combine_group_hash_string_column :: < BinaryType , _ > ( & column, |x| Ok ( x . agg_hash ( ) ) ) ? ;
171171 Ok ( ( ) )
172172 }
173173
174174 fn visit_string ( & mut self , column : StringColumn ) -> Result < ( ) > {
175- self . combine_group_hash_string_column :: < StringType > ( & column) ;
175+ self . combine_group_hash_string_column :: < StringType , _ > ( & column, |x| {
176+ Ok ( x. as_bytes ( ) . agg_hash ( ) )
177+ } ) ?;
176178 Ok ( ( ) )
177179 }
178180
179- fn visit_bitmap ( & mut self , column : BinaryColumn ) -> Result < ( ) > {
180- let column = normalize_bitmap_column ( & column) ;
181- self . combine_group_hash_string_column :: < BitmapType > ( column. as_ref ( ) ) ;
181+ fn visit_bitmap ( & mut self , column : BitmapColumn ) -> Result < ( ) > {
182+ let mut bytes = Vec :: new ( ) ;
183+ self . combine_group_hash_string_column :: < BitmapType , _ > ( & column, |x| {
184+ x. serialize_into ( & mut bytes) . unwrap ( ) ;
185+ let hash = bytes. agg_hash ( ) ;
186+ bytes. clear ( ) ;
187+ Ok ( hash)
188+ } ) ?;
182189 Ok ( ( ) )
183190 }
184191
185192 fn visit_variant ( & mut self , column : BinaryColumn ) -> Result < ( ) > {
186- self . combine_group_hash_string_column :: < VariantType > ( & column) ;
193+ self . combine_group_hash_string_column :: < VariantType , _ > ( & column, |x| Ok ( x . agg_hash ( ) ) ) ? ;
187194 Ok ( ( ) )
188195 }
189196
190197 fn visit_geometry ( & mut self , column : BinaryColumn ) -> Result < ( ) > {
191- self . combine_group_hash_string_column :: < GeometryType > ( & column) ;
198+ self . combine_group_hash_string_column :: < GeometryType , _ > ( & column, |x| Ok ( x . agg_hash ( ) ) ) ? ;
192199 Ok ( ( ) )
193200 }
194201
195202 fn visit_geography ( & mut self , column : GeographyColumn ) -> Result < ( ) > {
196- self . combine_group_hash_string_column :: < GeographyType > ( & column) ;
203+ self . combine_group_hash_string_column :: < GeographyType , _ > ( & column, |x| Ok ( x . 0 . agg_hash ( ) ) ) ? ;
197204 Ok ( ( ) )
198205 }
199206
@@ -225,20 +232,25 @@ impl<const IS_FIRST: bool> HashVisitor<'_, IS_FIRST> {
225232 }
226233 }
227234
228- fn combine_group_hash_string_column < T > ( & mut self , col : & T :: Column )
235+ fn combine_group_hash_string_column < T , F > (
236+ & mut self ,
237+ col : & T :: Column ,
238+ mut agg_hash : F ,
239+ ) -> Result < ( ) >
229240 where
230241 T : ValueType ,
231- for < ' a > T :: ScalarRef < ' a > : AsRef < [ u8 ] > ,
242+ for < ' a > F : FnMut ( & T :: ScalarRef < ' a > ) -> Result < u64 > ,
232243 {
233244 if IS_FIRST {
234245 for ( x, val) in T :: iter_column ( col) . zip ( self . values . iter_mut ( ) ) {
235- * val = x . as_ref ( ) . agg_hash ( ) ;
246+ * val = agg_hash ( & x ) ? ;
236247 }
237248 } else {
238249 for ( x, val) in T :: iter_column ( col) . zip ( self . values . iter_mut ( ) ) {
239- * val = ( * val) . wrapping_mul ( NULL_HASH_VAL ) ^ x . as_ref ( ) . agg_hash ( ) ;
250+ * val = ( * val) . wrapping_mul ( NULL_HASH_VAL ) ^ agg_hash ( & x ) ? ;
240251 }
241252 }
253+ Ok ( ( ) )
242254 }
243255}
244256
@@ -359,11 +371,14 @@ where I: Index
359371 self . visit_binary ( column)
360372 }
361373
362- fn visit_bitmap ( & mut self , column : crate :: types :: BinaryColumn ) -> Result < ( ) > {
363- let column = normalize_bitmap_column ( & column ) ;
374+ fn visit_bitmap ( & mut self , column : BitmapColumn ) -> Result < ( ) > {
375+ let mut bytes = Vec :: new ( ) ;
364376 self . visit_indices ( |i| {
365- let value = column. as_ref ( ) . index ( i. to_usize ( ) ) . unwrap ( ) ;
366- value. agg_hash ( )
377+ let value = column. index ( i. to_usize ( ) ) . unwrap ( ) ;
378+ value. serialize_into ( & mut bytes) . unwrap ( ) ;
379+ let hash = bytes. agg_hash ( ) ;
380+ bytes. clear ( ) ;
381+ hash
367382 } )
368383 }
369384
@@ -429,8 +444,8 @@ where I: Index
429444impl < const IS_FIRST : bool , I > IndexHashVisitor < ' _ , ' _ , IS_FIRST , I >
430445where I : Index
431446{
432- fn visit_indices < F > ( & mut self , do_hash : F ) -> Result < ( ) >
433- where F : Fn ( & I ) -> u64 {
447+ fn visit_indices < F > ( & mut self , mut do_hash : F ) -> Result < ( ) >
448+ where F : FnMut ( & I ) -> u64 {
434449 self . visit_indices_update ( |i, val| {
435450 let hash = do_hash ( i) ;
436451 if IS_FIRST {
@@ -441,8 +456,8 @@ where I: Index
441456 } )
442457 }
443458
444- fn visit_indices_update < F > ( & mut self , update : F ) -> Result < ( ) >
445- where F : Fn ( & I , & mut u64 ) {
459+ fn visit_indices_update < F > ( & mut self , mut update : F ) -> Result < ( ) >
460+ where F : FnMut ( & I , & mut u64 ) {
446461 for i in self . indices {
447462 let val = & mut self . target [ i. to_usize ( ) ] ;
448463 update ( i, val) ;
0 commit comments