@@ -16,6 +16,7 @@ use std::collections::BTreeMap;
16
16
use std:: collections:: HashSet ;
17
17
use std:: sync:: Arc ;
18
18
19
+ use chrono:: Utc ;
19
20
use databend_common_ast:: ast:: AddColumnOption as AstAddColumnOption ;
20
21
use databend_common_ast:: ast:: AlterTableAction ;
21
22
use databend_common_ast:: ast:: AlterTableStmt ;
@@ -1141,22 +1142,20 @@ impl Binder {
1141
1142
1142
1143
let partitions = settings. get_hilbert_num_range_ids ( ) ?;
1143
1144
let sample_size = settings. get_hilbert_sample_size_per_block ( ) ?;
1144
- let keys_bounds_str = cluster_key_strs
1145
- . iter ( )
1146
- . map ( |s| format ! ( "range_bound({partitions}, {sample_size})({s}) AS {s}_bound" ) )
1147
- . collect :: < Vec < _ > > ( )
1148
- . join ( ", " ) ;
1149
-
1150
- let hilbert_keys_str = cluster_key_strs
1151
- . iter ( )
1152
- . map ( |s| {
1153
- format ! (
1154
- "hilbert_key(cast(ifnull(range_partition_id({table}.{s}, _keys_bound.{s}_bound), {}) as uint16))" ,
1155
- partitions
1156
- )
1157
- } )
1158
- . collect :: < Vec < _ > > ( )
1159
- . join ( ", " ) ;
1145
+ let mut keys_bounds = Vec :: with_capacity ( cluster_key_strs. len ( ) ) ;
1146
+ let mut hilbert_keys = Vec :: with_capacity ( cluster_key_strs. len ( ) ) ;
1147
+ let suffix = format ! ( "{:08x}" , Utc :: now( ) . timestamp( ) ) ;
1148
+ for ( index, cluster_key_str) in cluster_key_strs. into_iter ( ) . enumerate ( ) {
1149
+ hilbert_keys. push ( format ! (
1150
+ "hilbert_key(cast(ifnull(range_partition_id({table}.{cluster_key_str}, \
1151
+ _keys_bound._bound{index}_{suffix}), {partitions}) as uint16))"
1152
+ ) ) ;
1153
+ keys_bounds. push ( format ! (
1154
+ "range_bound({partitions}, {sample_size})({cluster_key_str}) AS _bound{index}_{suffix}"
1155
+ ) ) ;
1156
+ }
1157
+ let keys_bounds_str = keys_bounds. join ( ", " ) ;
1158
+ let hilbert_keys_str = hilbert_keys. join ( ", " ) ;
1160
1159
1161
1160
let quote = settings. get_sql_dialect ( ) ?. default_ident_quote ( ) ;
1162
1161
let schema = tbl. schema_with_stream ( ) ;
0 commit comments