Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Nov 25, 2024
1 parent ce4bae5 commit b1374a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
15 changes: 7 additions & 8 deletions src/partition_table_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,17 @@ pub fn partitioned_predicates(
let exprs = predicate.mut_exprs();
for (filter_idx, key_indices) in filter_indices {
if let Expr::InList(InList {
expr: _expr,
list,
negated: false,
..
}) = &mut exprs[*filter_idx]
{
let keep = list
.iter()
.enumerate()
.map(|(idx, _)| key_indices.contains(&idx))
.collect::<Vec<_>>();
let mut keep = keep.iter();
list.retain(|_| *keep.next().unwrap());
let mut idx = 0;
list.retain(|_| {
let should_kept = key_indices.contains(&idx);
idx += 1;
should_kept
});
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/table_engine/src/partition/rule/df_adapter/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ use std::collections::HashSet;
use common_types::datum::Datum;
use datafusion::logical_expr::{expr::InList, Expr, Operator};
use df_operator::visitor::find_columns_by_expr;
use itertools::enumerate;

use super::IndexedPartitionFilter;
use crate::partition::rule::filter::{PartitionCondition, PartitionFilter};
use crate::partition::rule::{
df_adapter::IndexedPartitionFilter,
filter::{PartitionCondition, PartitionFilter},
};

/// The datafusion filter exprs extractor
///
Expand Down Expand Up @@ -58,7 +59,7 @@ impl FilterExtractor for KeyExtractor {
}

let mut target = Vec::with_capacity(filters.len());
for (index, filter) in enumerate(filters) {
for (index, filter) in filters.iter().enumerate() {
// If no target columns included in `filter`, ignore this `filter`.
let columns_in_filter = find_columns_by_expr(filter)
.into_iter()
Expand All @@ -80,7 +81,6 @@ impl FilterExtractor for KeyExtractor {

// Finally, we try to convert `filter` to `PartitionFilter`.
// We just support the simple situation: "colum = value" now.
// TODO: support "colum in [value list]".
// TODO: we need to compare and check the datatype of column and value.
// (Actually, there is type conversion on high-level, but when converted data
// is overflow, it may take no effect).
Expand Down
8 changes: 2 additions & 6 deletions src/table_engine/src/partition/rule/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,15 @@ impl KeyRule {
group: &[usize],
filters: &[PartitionFilter],
) -> Result<PartitionedFilterKeyIndex> {
let mut partitions = BTreeSet::new();
// Retrieve all the key DatumView instances along with their corresponding
// indices related to their positions in the predicate inlist. Since DatumView
// only implements PartialEq or PartialOrd, it cannot be stored directly in a
// HashSet or BTreeSet.
// indices related to their positions in the predicate inlist.
let expanded_group = expand_partition_keys_group(group, filters)?;

let mut partitioned_key_indices = PartitionedFilterKeyIndex::new();
for indexed_partition_keys in expanded_group {
// batch all the keys for hash computation
let partition_keys = indexed_partition_keys.iter().map(|item| item.1.clone());
let partition = compute_partition(partition_keys, self.partition_num);
partitions.insert(partition);

// collect all the key indices related to all predicate expr in the target
// partition
Expand Down Expand Up @@ -221,7 +217,7 @@ impl PartitionRule for KeyRule {

let filters = indexed_filters
.iter()
.map(|value| value.1.clone())
.map(|(_idx, filter)| filter.clone())
.collect::<Vec<_>>();

// Group the filters by their columns.
Expand Down

0 comments on commit b1374a7

Please sign in to comment.