-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21d01ae
commit a533ce6
Showing
10 changed files
with
686 additions
and
5 deletions.
There are no files selected for viewing
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
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,45 @@ | ||
use crate::common::{ | ||
nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode}, | ||
values::Value, | ||
}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct AttributeRefPred(pub ArcPredicateNode); | ||
|
||
impl AttributeRefPred { | ||
/// Creates a new `ColumnRef` expression. | ||
pub fn new(column_idx: usize) -> AttributeRefPred { | ||
// this conversion is always safe since usize is at most u64 | ||
let u64_column_idx = column_idx as u64; | ||
AttributeRefPred( | ||
PredicateNode { | ||
typ: PredicateType::AttributeRef, | ||
children: vec![], | ||
data: Some(Value::UInt64(u64_column_idx)), | ||
} | ||
.into(), | ||
) | ||
} | ||
|
||
fn get_data_usize(&self) -> usize { | ||
self.0.data.as_ref().unwrap().as_u64() as usize | ||
} | ||
|
||
/// Gets the column index. | ||
pub fn index(&self) -> usize { | ||
self.get_data_usize() | ||
} | ||
} | ||
|
||
impl ReprPredicateNode for AttributeRefPred { | ||
fn into_pred_node(self) -> ArcPredicateNode { | ||
self.0 | ||
} | ||
|
||
fn from_pred_node(pred_node: ArcPredicateNode) -> Option<Self> { | ||
if pred_node.typ != PredicateType::AttributeRef { | ||
return None; | ||
} | ||
Some(Self(pred_node)) | ||
} | ||
} |
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,44 @@ | ||
use arrow_schema::DataType; | ||
|
||
use crate::common::nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode}; | ||
|
||
use super::data_type_pred::DataTypePred; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct CastPred(pub ArcPredicateNode); | ||
|
||
impl CastPred { | ||
pub fn new(child: ArcPredicateNode, cast_to: DataType) -> Self { | ||
CastPred( | ||
PredicateNode { | ||
typ: PredicateType::Cast, | ||
children: vec![child, DataTypePred::new(cast_to).into_pred_node()], | ||
data: None, | ||
} | ||
.into(), | ||
) | ||
} | ||
|
||
pub fn child(&self) -> ArcPredicateNode { | ||
self.0.child(0) | ||
} | ||
|
||
pub fn cast_to(&self) -> DataType { | ||
DataTypePred::from_pred_node(self.0.child(1)) | ||
.unwrap() | ||
.data_type() | ||
} | ||
} | ||
|
||
impl ReprPredicateNode for CastPred { | ||
fn into_pred_node(self) -> ArcPredicateNode { | ||
self.0 | ||
} | ||
|
||
fn from_pred_node(pred_node: ArcPredicateNode) -> Option<Self> { | ||
if !matches!(pred_node.typ, PredicateType::Cast) { | ||
return None; | ||
} | ||
Some(Self(pred_node)) | ||
} | ||
} |
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
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,40 @@ | ||
use arrow_schema::DataType; | ||
|
||
use crate::common::nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct DataTypePred(pub ArcPredicateNode); | ||
|
||
impl DataTypePred { | ||
pub fn new(typ: DataType) -> Self { | ||
DataTypePred( | ||
PredicateNode { | ||
typ: PredicateType::DataType(typ), | ||
children: vec![], | ||
data: None, | ||
} | ||
.into(), | ||
) | ||
} | ||
|
||
pub fn data_type(&self) -> DataType { | ||
if let PredicateType::DataType(ref data_type) = self.0.typ { | ||
data_type.clone() | ||
} else { | ||
panic!("not a data type") | ||
} | ||
} | ||
} | ||
|
||
impl ReprPredicateNode for DataTypePred { | ||
fn into_pred_node(self) -> ArcPredicateNode { | ||
self.0 | ||
} | ||
|
||
fn from_pred_node(pred_node: ArcPredicateNode) -> Option<Self> { | ||
if !matches!(pred_node.typ, PredicateType::DataType(_)) { | ||
return None; | ||
} | ||
Some(Self(pred_node)) | ||
} | ||
} |
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
Oops, something went wrong.