Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DO NOT MERGE]hilbert cluster #16956

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/query/ast/src/ast/statements/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ pub enum OptimizeTableAction {
All,
Purge { before: Option<TimeTravelPoint> },
Compact { target: CompactTarget },
ClusterBy { exprs: Vec<Expr> },
}

impl Display for OptimizeTableAction {
Expand All @@ -820,6 +821,11 @@ impl Display for OptimizeTableAction {
}
Ok(())
}
OptimizeTableAction::ClusterBy { exprs } => {
write!(f, "CLUSTER BY HILBERT(")?;
write_comma_separated_list(f, exprs)?;
write!(f, ")")
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3713,6 +3713,10 @@ pub fn optimize_table_action(i: Input) -> IResult<OptimizeTableAction> {
target: opt_segment.map_or(CompactTarget::Block, |_| CompactTarget::Segment),
}
}),
map(
rule! { CLUSTER ~ ^BY ~ HILBERT ~ ^"(" ~ ^#comma_separated_list1(expr) ~ ^")" },
|(_, _, _, _, exprs, _)| OptimizeTableAction::ClusterBy { exprs },
),
))(i)
}

Expand Down
8 changes: 6 additions & 2 deletions src/query/expression/src/kernels/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use databend_common_exception::Result;

use crate::types::DataType;
use crate::visitor::ValueVisitor;
use crate::Column;
use crate::ColumnBuilder;
use crate::DataBlock;
use crate::Scalar;
Expand Down Expand Up @@ -126,8 +127,11 @@ pub fn compare_scalars(rows: Vec<Vec<Scalar>>, data_types: &[DataType]) -> Resul
.into_iter()
.map(|builder| builder.build())
.collect::<Vec<_>>();
compare_columns(order_columns, length)
}

let descriptions = order_columns
pub fn compare_columns(columns: Vec<Column>, length: usize) -> Result<Vec<u32>> {
let descriptions = columns
.iter()
.enumerate()
.map(|(idx, _)| SortColumnDescription {
Expand All @@ -139,7 +143,7 @@ pub fn compare_scalars(rows: Vec<Vec<Scalar>>, data_types: &[DataType]) -> Resul

let mut sort_compare = SortCompare::new(descriptions, length, LimitType::None);

for array in order_columns {
for array in columns {
sort_compare.visit_value(Value::Column(array))?;
sort_compare.increment_column_index();
}
Expand Down
Loading
Loading