Skip to content
Snippets Groups Projects
Commit ad8d3aa8 authored by Denis Smirnov's avatar Denis Smirnov
Browse files

refactoring: make "add_ref" plan Nodes method

parent f953e9e4
No related branches found
No related tags found
1 merge request!1414sbroad import
......@@ -98,16 +98,6 @@ impl Expression {
Err(QueryPlannerError::InvalidRow)
}
/// Reference expression constructor.
#[must_use]
pub fn new_ref(parent: usize, targets: Option<Vec<usize>>, position: usize) -> Self {
Expression::Reference {
parent,
targets,
position,
}
}
// TODO: check that doesn't contain top-level aliases with the same names
/// Row expression constructor.
#[must_use]
......@@ -146,6 +136,21 @@ impl Nodes {
pub fn add_const(&mut self, value: Value) -> usize {
self.push(Node::Expression(Expression::Constant { value }))
}
/// Reference expression constructor.
pub fn add_ref(
&mut self,
parent: usize,
targets: Option<Vec<usize>>,
position: usize,
) -> usize {
let r = Expression::Reference {
parent,
targets,
position,
};
self.push(Node::Expression(r))
}
}
impl Plan {
......@@ -219,11 +224,7 @@ impl Plan {
};
let new_targets: Vec<usize> = targets.iter().copied().collect();
// Create new references and aliases. Save them to the plan nodes arena.
let r_id = self.nodes.push(Node::Expression(Expression::new_ref(
rel_node_id,
Some(new_targets),
pos,
)));
let r_id = self.nodes.add_ref(rel_node_id, Some(new_targets), pos);
let a_id = self.nodes.add_alias(&name, r_id)?;
aliases.push(a_id);
}
......@@ -246,11 +247,7 @@ impl Plan {
map.get(*col).map_or(false, |pos| {
let new_targets: Vec<usize> = targets.iter().copied().collect();
// Create new references and aliases. Save them to the plan nodes arena.
let r_id = self.nodes.push(Node::Expression(Expression::new_ref(
rel_node_id,
Some(new_targets),
*pos,
)));
let r_id = self.nodes.add_ref(rel_node_id, Some(new_targets), *pos);
if let Ok(a_id) = self.nodes.add_alias(col, r_id) {
aliases.push(a_id);
true
......
......@@ -327,8 +327,7 @@ impl Plan {
let mut refs: Vec<usize> = Vec::new();
for (pos, col) in columns.iter().enumerate() {
let r_id = nodes
.push(Node::Expression(Expression::new_ref(logical_id, None, pos)));
let r_id = nodes.add_ref(logical_id, None, pos);
let alias_id = nodes.add_alias(&col.name, r_id)?;
refs.push(alias_id);
}
......
......@@ -150,11 +150,7 @@ fn selection() {
let scan_id = plan.add_scan("t").unwrap();
let ref_a_id = plan.nodes.push(Node::Expression(Expression::new_ref(
scan_id + 1,
Some(vec![0]),
0,
)));
let ref_a_id = plan.nodes.add_ref(scan_id + 1, Some(vec![0]), 0);
let a_id = plan.nodes.add_alias("a", ref_a_id).unwrap();
let const_id = plan.nodes.add_const(Value::number_from_str("10").unwrap());
let gt_id = plan.nodes.push(Node::Expression(Expression::new_bool(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment