Skip to content

Commit

Permalink
feat: define partition rule trait (#501)
Browse files Browse the repository at this point in the history
* define partition rule trait.

* address CR.

* add a mock impl.
  • Loading branch information
Rachelint authored Dec 22, 2022
1 parent 61f9250 commit 28a2ae5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
14 changes: 0 additions & 14 deletions table_engine/src/partition/rule.rs

This file was deleted.

21 changes: 21 additions & 0 deletions table_engine/src/partition/rule/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.

//! Mock partition rule

use common_types::row::RowGroup;

use crate::partition::rule::{PartitionFilter, PartitionRule, Result};

pub struct MockRule {
pub wanted: usize,
}

impl PartitionRule for MockRule {
fn locate_partitions_for_write(&self, row_group: &RowGroup) -> Result<Vec<usize>> {
Ok(vec![self.wanted; row_group.num_rows()])
}

fn locate_partitions_for_read(&self, _filters: &[PartitionFilter]) -> Result<Vec<usize>> {
Ok(vec![self.wanted])
}
}
39 changes: 39 additions & 0 deletions table_engine/src/partition/rule/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.

//! Partition rules

pub mod mock;

use common_types::row::RowGroup;
use common_util::define_result;
use datafusion_expr::{Expr, Operator};
use snafu::Snafu;

#[derive(Debug, Snafu)]
pub enum Error {}

define_result!(Error);

/// Partition rule locate partition
pub trait PartitionRule {
/// Locate the partition for each row in `row_group`.
///
/// Len of returned value should be equal to the one of rows in `row group`.
fn locate_partitions_for_write(&self, row_group: &RowGroup) -> Result<Vec<usize>>;

/// Locate partitions according to `filters`.
fn locate_partitions_for_read(&self, filters: &[PartitionFilter]) -> Result<Vec<usize>>;
}

/// Filter using for partition
///
/// Now, it is same as the `BinaryExpr`in datafusion.
#[allow(dead_code)]
pub struct PartitionFilter {
/// Left-hand side of the expression
left: Box<Expr>,
/// The comparison operator
op: Operator,
/// Right-hand side of the expression
right: Box<Expr>,
}

0 comments on commit 28a2ae5

Please sign in to comment.