Skip to content

Commit

Permalink
fix quoted cluster key
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyass committed Jan 16, 2025
1 parent c731826 commit 2302a9c
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/query/sql/src/planner/binder/ddl/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::collections::BTreeMap;
use std::collections::HashSet;
use std::sync::Arc;

use chrono::Utc;
use databend_common_ast::ast::AddColumnOption as AstAddColumnOption;
use databend_common_ast::ast::AlterTableAction;
use databend_common_ast::ast::AlterTableStmt;
Expand Down Expand Up @@ -1141,22 +1142,20 @@ impl Binder {

let partitions = settings.get_hilbert_num_range_ids()?;
let sample_size = settings.get_hilbert_sample_size_per_block()?;
let keys_bounds_str = cluster_key_strs
.iter()
.map(|s| format!("range_bound({partitions}, {sample_size})({s}) AS {s}_bound"))
.collect::<Vec<_>>()
.join(", ");

let hilbert_keys_str = cluster_key_strs
.iter()
.map(|s| {
format!(
"hilbert_key(cast(ifnull(range_partition_id({table}.{s}, _keys_bound.{s}_bound), {}) as uint16))",
partitions
)
})
.collect::<Vec<_>>()
.join(", ");
let mut keys_bounds = Vec::with_capacity(cluster_key_strs.len());
let mut hilbert_keys = Vec::with_capacity(cluster_key_strs.len());
let suffix = format!("{:08x}", Utc::now().timestamp());
for (index, cluster_key_str) in cluster_key_strs.into_iter().enumerate() {
hilbert_keys.push(format!(
"hilbert_key(cast(ifnull(range_partition_id({table}.{cluster_key_str}, \
_keys_bound._bound{index}_{suffix}), {partitions}) as uint16))"
));
keys_bounds.push(format!(
"range_bound({partitions}, {sample_size})({cluster_key_str}) AS _bound{index}_{suffix}"
));
}
let keys_bounds_str = keys_bounds.join(", ");
let hilbert_keys_str = hilbert_keys.join(", ");

let quote = settings.get_sql_dialect()?.default_ident_quote();
let schema = tbl.schema_with_stream();
Expand Down

0 comments on commit 2302a9c

Please sign in to comment.