Skip to content

Commit 2302a9c

Browse files
committed
fix quoted cluster key
1 parent c731826 commit 2302a9c

File tree

1 file changed

+15
-16
lines changed
  • src/query/sql/src/planner/binder/ddl

1 file changed

+15
-16
lines changed

src/query/sql/src/planner/binder/ddl/table.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::collections::BTreeMap;
1616
use std::collections::HashSet;
1717
use std::sync::Arc;
1818

19+
use chrono::Utc;
1920
use databend_common_ast::ast::AddColumnOption as AstAddColumnOption;
2021
use databend_common_ast::ast::AlterTableAction;
2122
use databend_common_ast::ast::AlterTableStmt;
@@ -1141,22 +1142,20 @@ impl Binder {
11411142

11421143
let partitions = settings.get_hilbert_num_range_ids()?;
11431144
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(", ");
11601159

11611160
let quote = settings.get_sql_dialect()?.default_ident_quote();
11621161
let schema = tbl.schema_with_stream();

0 commit comments

Comments
 (0)