-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define partition rule trait (#501)
* define partition rule trait. * address CR. * add a mock impl.
- Loading branch information
Showing
3 changed files
with
60 additions
and
14 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |