Skip to content

Commit

Permalink
use ColIndexMapping new instead of without_target_size
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 committed Oct 30, 2023
1 parent b260553 commit 2321765
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/frontend/src/optimizer/rule/apply_join_transpose_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl ApplyJoinTransposeRule {
correlated_indices,
false,
);
let output_indices: Vec<_> = {
let (output_indices, target_size) = {
let (apply_left_len, join_right_len) = match apply_join_type {
JoinType::LeftSemi | JoinType::LeftAnti => (apply_left_len, 0),
JoinType::RightSemi | JoinType::RightAnti => (0, join.right().schema().len()),
Expand All @@ -368,14 +368,19 @@ impl ApplyJoinTransposeRule {
join_left_len + apply_left_len..join_left_len + apply_left_len + join_right_len,
);

match join.join_type() {
let output_indices: Vec<_> = match join.join_type() {
JoinType::LeftSemi | JoinType::LeftAnti => left_iter.collect(),
JoinType::RightSemi | JoinType::RightAnti => right_iter.collect(),
_ => left_iter.chain(right_iter).collect(),
}
};

let target_size = join_left_len + apply_left_len + join_right_len;
(output_indices, target_size)
};
let mut output_indices_mapping =
ColIndexMapping::without_target_size(output_indices.iter().map(|x| Some(*x)).collect());
let mut output_indices_mapping = ColIndexMapping::new(
output_indices.iter().map(|x| Some(*x)).collect(),
target_size,
);
let new_join = LogicalJoin::new(
join.left(),
new_join_right,
Expand Down Expand Up @@ -518,7 +523,7 @@ impl ApplyJoinTransposeRule {
false,
);

let output_indices: Vec<_> = {
let (output_indices, target_size) = {
let (apply_left_len, join_right_len) = match apply_join_type {
JoinType::LeftSemi | JoinType::LeftAnti => (apply_left_len, 0),
JoinType::RightSemi | JoinType::RightAnti => (0, join.right().schema().len()),
Expand All @@ -529,11 +534,14 @@ impl ApplyJoinTransposeRule {
let right_iter = join_left_len + apply_left_len * 2
..join_left_len + apply_left_len * 2 + join_right_len;

match join.join_type() {
let output_indices: Vec<_> = match join.join_type() {
JoinType::LeftSemi | JoinType::LeftAnti => left_iter.collect(),
JoinType::RightSemi | JoinType::RightAnti => right_iter.collect(),
_ => left_iter.chain(right_iter).collect(),
}
};

let target_size = join_left_len + apply_left_len * 2 + join_right_len;
(output_indices, target_size)
};
let new_join = LogicalJoin::new(
new_join_left,
Expand All @@ -548,8 +556,9 @@ impl ApplyJoinTransposeRule {
new_join.into()
}
JoinType::Inner | JoinType::LeftOuter | JoinType::RightOuter | JoinType::FullOuter => {
let mut output_indices_mapping = ColIndexMapping::without_target_size(
let mut output_indices_mapping = ColIndexMapping::new(
output_indices.iter().map(|x| Some(*x)).collect(),
target_size,
);
// Leave other condition for predicate push down to deal with
LogicalFilter::create(
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/src/optimizer/rule/apply_offset_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ pub struct ApplyCorrelatedIndicesConverter {}
impl ApplyCorrelatedIndicesConverter {
pub fn convert_to_index_mapping(correlated_indices: &[usize]) -> ColIndexMapping {
// Inverse anyway.
let col_mapping = ColIndexMapping::without_target_size(
let target_size = match correlated_indices.iter().max_by_key(|&&x| x) {
Some(target_max) => target_max + 1,
None => 0,
};
let col_mapping = ColIndexMapping::new(
correlated_indices.iter().copied().map(Some).collect_vec(),
target_size,
);
let mut map = vec![None; col_mapping.target_size()];
for (src, dst) in col_mapping.mapping_pairs() {
Expand Down

0 comments on commit 2321765

Please sign in to comment.