use super::nested::JoinOutput;
use crate::fx::{FxHashMap, FxHashSet};
use sqlparser::ast::{Expr, TableFactor};
#[derive(Default)]
pub(in super::super) struct Scope {
pub(in super::super) unqualified_columns: std::collections::BTreeSet<String>,
pub(in super::super) candidates: Vec<usize>,
pub(in super::super) join_outputs: FxHashMap<String, JoinOutput>,
pub(in super::super) nested_joins: FxHashMap<*const TableFactor, Scope>,
pub(in super::super) predicates: FxHashMap<*const Expr, Scope>,
pub(in super::super) preceding: FxHashMap<*const TableFactor, Scope>,
pub(in super::super) physical_inputs: Vec<PhysicalInput>,
pub(in super::super) bindings: FxHashMap<String, Option<usize>>,
pub(in super::super) group_names: FxHashSet<*const Expr>,
pub(in super::super) output_aliases: FxHashSet<String>,
pub(in super::super) inputs: usize,
pub(in super::super) known_inputs: usize,
pub(in super::super) known_columns: FxHashSet<String>,
}
#[derive(Clone)]
pub(in super::super) struct PhysicalInput {
pub(in super::super) candidate: Option<usize>,
pub(in super::super) relation: String,
pub(in super::super) renamed: bool,
}
impl Scope {
pub(super) fn snapshot(&self) -> Self {
Self {
candidates: self.candidates.clone(),
join_outputs: self.join_outputs.clone(),
physical_inputs: self.physical_inputs.clone(),
bindings: self.bindings.clone(),
inputs: self.inputs,
known_inputs: self.known_inputs,
known_columns: self.known_columns.clone(),
..Self::default()
}
}
pub(super) fn merge(&mut self, other: Self) {
self.candidates.extend(other.candidates);
self.join_outputs.extend(other.join_outputs);
self.nested_joins.extend(other.nested_joins);
self.preceding.extend(other.preceding);
self.predicates.extend(other.predicates);
self.physical_inputs.extend(other.physical_inputs);
self.bindings.extend(other.bindings);
self.inputs += other.inputs;
self.known_inputs += other.known_inputs;
self.known_columns.extend(other.known_columns);
}
}