|
1 | | -use crate::common::{ |
2 | | - nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode}, |
3 | | - values::Value, |
4 | | -}; |
| 1 | +use crate::common::nodes::{ArcPredicateNode, PredicateNode, PredicateType, ReprPredicateNode}; |
5 | 2 |
|
| 3 | +use super::id_pred::IdPred; |
| 4 | + |
| 5 | +/// [`AttributeRefPred`] represents a reference to a column in a relation. |
| 6 | +/// |
| 7 | +/// An [`AttributeRefPred`] has two children: |
| 8 | +/// 1. The table id, represented by an [`IdPred`]. |
| 9 | +/// 2. The index of the column, represented by an [`IdPred`]. |
6 | 10 | #[derive(Clone, Debug)] |
7 | 11 | pub struct AttributeRefPred(pub ArcPredicateNode); |
8 | 12 |
|
9 | 13 | impl AttributeRefPred { |
10 | | - /// Creates a new `ColumnRef` expression. |
11 | | - pub fn new(attribute_idx: usize) -> AttributeRefPred { |
12 | | - // this conversion is always safe since usize is at most u64 |
13 | | - let u64_attribute_idx = attribute_idx as u64; |
| 14 | + pub fn new(table_id: usize, attribute_idx: usize) -> AttributeRefPred { |
14 | 15 | AttributeRefPred( |
15 | 16 | PredicateNode { |
16 | 17 | typ: PredicateType::AttributeRef, |
17 | | - children: vec![], |
18 | | - data: Some(Value::UInt64(u64_attribute_idx)), |
| 18 | + children: vec![ |
| 19 | + IdPred::new(table_id).into_pred_node(), |
| 20 | + IdPred::new(attribute_idx).into_pred_node(), |
| 21 | + ], |
| 22 | + data: None, |
19 | 23 | } |
20 | 24 | .into(), |
21 | 25 | ) |
22 | 26 | } |
23 | 27 |
|
24 | | - fn get_data_usize(&self) -> usize { |
25 | | - self.0.data.as_ref().unwrap().as_u64() as usize |
| 28 | + /// Gets the table id. |
| 29 | + pub fn table_id(&self) -> usize { |
| 30 | + self.0.child(0).data.as_ref().unwrap().as_u64() as usize |
26 | 31 | } |
27 | 32 |
|
28 | | - /// Gets the column index. |
29 | | - pub fn index(&self) -> usize { |
30 | | - self.get_data_usize() |
| 33 | + /// Gets the attribute index. |
| 34 | + pub fn attr_index(&self) -> usize { |
| 35 | + self.0.child(1).data.as_ref().unwrap().as_u64() as usize |
31 | 36 | } |
32 | 37 | } |
33 | 38 |
|
|
0 commit comments