Skip to content

Commit

Permalink
refactor(optimizer): remove some ColIndexMapping::without_tar_size usage
Browse files Browse the repository at this point in the history
  • Loading branch information
st1page committed Oct 30, 2023
1 parent 7db34d5 commit fb666c0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/common/src/util/column_index_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ pub struct ColIndexMapping {
}

impl ColIndexMapping {
/// Create a partial mapping which maps from the subscripts range `(0..map.len())` to
/// `(0..target_size)`. Each subscript is mapped to the corresponding element.
pub fn with_target_size(map: Vec<Option<usize>>, target_size: usize) -> Self {
if let Some(target_max) = map.iter().filter_map(|x| *x).max_by_key(|x| *x) {
assert!(target_max < target_size)
};
Self { target_size, map }
}

/// Create a partial mapping which maps the subscripts range `(0..map.len())` to the
/// corresponding element. **This method is not recommended**, please use `with_target_size` instead, see <https://github.com/risingwavelabs/risingwave/issues/7234> for more information**
pub fn without_target_size(map: Vec<Option<usize>>) -> Self {
Expand All @@ -42,15 +51,6 @@ impl ColIndexMapping {
Self { target_size, map }
}

/// Create a partial mapping which maps from the subscripts range `(0..map.len())` to
/// `(0..target_size)`. Each subscript is mapped to the corresponding element.
pub fn with_target_size(map: Vec<Option<usize>>, target_size: usize) -> Self {
if let Some(target_max) = map.iter().filter_map(|x| *x).max_by_key(|x| *x) {
assert!(target_max < target_size)
};
Self { target_size, map }
}

pub fn into_parts(self) -> (Vec<Option<usize>>, usize) {
(self.map, self.target_size)
}
Expand All @@ -69,7 +69,7 @@ impl ColIndexMapping {

pub fn identity(size: usize) -> Self {
let map = (0..size).map(Some).collect();
Self::without_target_size(map)
Self::with_target_size(map, size)
}

pub fn is_identity(&self) -> bool {
Expand Down Expand Up @@ -159,7 +159,7 @@ impl ColIndexMapping {
for (tar, &src) in cols.iter().enumerate() {
map[src] = Some(tar);
}
Self::without_target_size(map)
Self::with_target_size(map, cols.len())
}

// TODO(yuchao): isn't this the same as `with_remaining_columns`?
Expand All @@ -170,7 +170,7 @@ impl ColIndexMapping {
map[src] = Some(tar);
}
}
Self::without_target_size(map)
Self::with_target_size(map, cols.len())
}

/// Remove the given columns, and maps the remaining columns to a consecutive range starting
Expand Down

0 comments on commit fb666c0

Please sign in to comment.