@@ -64,7 +64,9 @@ use crate::SegmentLocation;
6464use crate :: io:: MetaReaders ;
6565use crate :: operations:: ReclusterMode ;
6666use crate :: operations:: common:: BlockMetaIndex as BlockIndex ;
67+ use crate :: statistics:: PreparedClusterKeyExpr ;
6768use crate :: statistics:: get_min_max_stats;
69+ use crate :: statistics:: prepare_cluster_key_exprs;
6870use crate :: statistics:: reducers:: merge_statistics_mut;
6971
7072/// Maximum recluster depth allowed when only two blocks remain.
@@ -162,7 +164,7 @@ pub struct ReclusterMutator {
162164 pub ( crate ) schema : TableSchemaRef ,
163165 pub ( crate ) max_tasks : usize ,
164166 pub ( crate ) memory_threshold : usize ,
165- pub ( crate ) cluster_key_exprs : Vec < Expr < usize > > ,
167+ pub ( crate ) prepared_cluster_key_exprs : Vec < PreparedClusterKeyExpr > ,
166168 pub ( crate ) cluster_key_types : Vec < DataType > ,
167169}
168170
@@ -199,6 +201,8 @@ impl ReclusterMutator {
199201 . iter ( )
200202 . map ( |v| v. data_type ( ) . clone ( ) )
201203 . collect :: < Vec < _ > > ( ) ;
204+ let prepared_cluster_key_exprs =
205+ prepare_cluster_key_exprs ( & cluster_key_exprs, schema. as_ref ( ) ) ;
202206
203207 Ok ( Self {
204208 ctx,
@@ -209,7 +213,7 @@ impl ReclusterMutator {
209213 cluster_key_id,
210214 max_tasks,
211215 memory_threshold,
212- cluster_key_exprs ,
216+ prepared_cluster_key_exprs ,
213217 cluster_key_types,
214218 } )
215219 }
@@ -234,6 +238,8 @@ impl ReclusterMutator {
234238 . iter ( )
235239 . map ( |expr| expr. data_type ( ) . clone ( ) )
236240 . collect ( ) ;
241+ let prepared_cluster_key_exprs =
242+ prepare_cluster_key_exprs ( & cluster_key_exprs, schema. as_ref ( ) ) ;
237243 let memory_threshold = ctx
238244 . get_settings ( )
239245 . get_recluster_block_size ( )
@@ -248,7 +254,7 @@ impl ReclusterMutator {
248254 cluster_key_id,
249255 max_tasks,
250256 memory_threshold,
251- cluster_key_exprs ,
257+ prepared_cluster_key_exprs ,
252258 cluster_key_types,
253259 }
254260 }
@@ -870,7 +876,7 @@ impl ReclusterMutator {
870876 // flush, only bounded anchors remain eligible for the next window.
871877 let mut seen_in_hot_range = IndexSet :: new ( ) ;
872878 let ( keys, values) : ( Vec < _ > , Vec < _ > ) = segment_points. into_iter ( ) . unzip ( ) ;
873- let sorted_indices = compare_scalars ( keys, & self . cluster_key_types ) ?;
879+ let sorted_indices = compare_scalars ( & keys, & self . cluster_key_types ) ?;
874880
875881 for idx in sorted_indices {
876882 let start = & values[ idx as usize ] . 0 ;
@@ -1046,11 +1052,10 @@ impl ReclusterMutator {
10461052 }
10471053
10481054 let ( min_stats, max_stats) = get_min_max_stats (
1049- & self . cluster_key_exprs ,
1055+ & self . prepared_cluster_key_exprs ,
10501056 col_stats,
10511057 cluster_stats,
10521058 Some ( self . cluster_key_id ) ,
1053- self . schema . as_ref ( ) ,
10541059 ) ;
10551060
10561061 ClusterStatistics :: new ( self . cluster_key_id , min_stats, max_stats, 0 , None )
@@ -1180,7 +1185,7 @@ impl ReclusterMutator {
11801185 let mut point_overlaps: Vec < Vec < usize > > = Vec :: with_capacity ( points_map. len ( ) ) ;
11811186 let mut unfinished_intervals = BTreeMap :: new ( ) ;
11821187 let ( keys, values) : ( Vec < _ > , Vec < _ > ) = points_map. into_iter ( ) . unzip ( ) ;
1183- let indices = compare_scalars ( keys, & self . cluster_key_types ) ?;
1188+ let indices = compare_scalars ( & keys, & self . cluster_key_types ) ?;
11841189 for ( i, idx) in indices. into_iter ( ) . enumerate ( ) {
11851190 let start = & values[ idx as usize ] . 0 ;
11861191 let end = & values[ idx as usize ] . 1 ;
0 commit comments