diff --git a/src/db/engine.rs b/src/db/engine.rs index 3dbce9e8..489d1ae8 100644 --- a/src/db/engine.rs +++ b/src/db/engine.rs @@ -2,7 +2,6 @@ // will be shared among threads -use std::collections::BTreeMap; use cozorocks::*; use std::sync::{Arc, Mutex, RwLock}; use std::time::{SystemTime, UNIX_EPOCH}; @@ -108,26 +107,24 @@ impl Engine { perm_cf: SharedPtr::null(), temp_cf: SharedPtr::null(), handle, - params: BTreeMap::default(), }; sess.start()?; Ok(sess) } } -pub struct Session<'a, 'b> { +pub struct Session<'a> { pub engine: &'a Engine, pub stack_depth: i32, pub handle: Arc>, pub txn: TransactionPtr, pub perm_cf: SharedPtr, pub temp_cf: SharedPtr, - pub params: BTreeMap, } // every session has its own column family to play with // metadata are stored in table 0 -impl<'a, 'b> Session<'a, 'b> { +impl<'a> Session<'a> { pub fn start(&mut self) -> Result<()> { self.perm_cf = self.engine.db.default_cf(); assert!(!self.perm_cf.is_null()); @@ -172,7 +169,7 @@ impl<'a, 'b> Session<'a, 'b> { } } -impl<'a, 't> Drop for Session<'a, 't> { +impl<'a> Drop for Session<'a> { fn drop(&mut self) { if let Err(e) = self.finish_work() { eprintln!("Dropping session failed {:?}", e); diff --git a/src/db/eval.rs b/src/db/eval.rs index f337eeac..982a9de2 100644 --- a/src/db/eval.rs +++ b/src/db/eval.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; use std::collections::{BTreeMap, HashSet}; -use pest::Parser as PestParser; use pest::iterators::{Pair, Pairs}; use cozorocks::{SlicePtr}; use crate::db::engine::{Session}; @@ -10,7 +9,7 @@ use crate::relation::value::{Value}; use crate::error::{CozoError, Result}; use crate::error::CozoError::LogicError; use crate::relation::data::DataKind; -use crate::parser::{Parser, Rule}; +use crate::parser::{Rule}; use crate::parser::text_identifier::build_name_in_def; use crate::relation::value; @@ -22,16 +21,13 @@ use crate::relation::value; /// `[Null, Int, Text, Int, Text]` inverted index for related tables /// `[True, Int]` table info, value is key -impl<'s, 't> Session<'s, 't> { +impl<'s> Session<'s> { pub fn define_variable(&mut self, name: &str, val: &Value, in_root: bool) -> Result<()> { let mut data = Tuple::with_data_prefix(DataKind::Value); data.push_value(val); self.define_data(name, data, in_root) } fn resolve_value(&self, name: &str) -> Result> { - if name.starts_with('&') { - self.resolve_param(name).map(|v| Some(v.clone())) - } else { match self.resolve(name)? { None => Ok(None), Some(t) => { @@ -43,7 +39,6 @@ impl<'s, 't> Session<'s, 't> { } } } - } } fn encode_definable_key(&self, name: &str, in_root: bool) -> OwnTuple { let depth_code = if in_root { 0 } else { self.get_stack_depth() as i64 }; @@ -262,7 +257,8 @@ impl<'s, 't> Session<'s, 't> { } self.define_data(&name, tuple, in_root) } - pub fn partial_eval<'a>(&self, value: Value<'a>, params: BTreeMap, table_bindings: BTreeMap) -> Result<(bool, Value<'a>)> { + pub fn partial_eval<'a>(&self, value: Value<'a>, params: BTreeMap>, + _table_bindings: BTreeMap) -> Result<(bool, Value<'a>)> { match value { v @ (Value::Null | Value::Bool(_) | @@ -293,12 +289,16 @@ impl<'s, 't> Session<'s, 't> { Ok((is_ev, v.into())) } Value::Variable(v) => { - Ok(match self.resolve_value(&v)? { - None => (false, Value::Variable(v)), - Some(rs) => { - (rs.is_evaluated(), rs.to_static()) - } - }) + if let Some(d) = params.get(v.as_ref()) { + Ok((true, d.clone())) + } else { + Ok(match self.resolve_value(&v)? { + None => (false, Value::Variable(v)), + Some(rs) => { + (rs.is_evaluated(), rs.to_static()) + } + }) + } } Value::Apply(op, args) => { @@ -825,10 +825,6 @@ impl<'s, 't> Session<'s, 't> { Ok(()) } - fn set_param(&mut self, name: &str, val: &'t str) { - self.params.insert(name.to_string(), val); - } - pub fn table_data(&self, id: i64, in_root: bool) -> Result>> { let mut key = Tuple::with_null_prefix(); key.push_bool(true); @@ -897,13 +893,7 @@ impl<'s, 't> Session<'s, 't> { Ok(assocs) } - fn resolve_param(&self, name: &str) -> Result { - let text = self.params.get(name).ok_or_else(|| CozoError::UndefinedParam(name.to_string()))?; - let pair = Parser::parse(Rule::expr, text)?.next().unwrap(); - Value::from_pair(pair) - } - - fn delete_defined(&mut self, name: &str, in_root: bool) -> Result<()> { + pub fn delete_defined(&mut self, name: &str, in_root: bool) -> Result<()> { let key = self.encode_definable_key(name, in_root); if in_root { self.txn.del(true, &self.perm_cf, key)?; @@ -945,7 +935,7 @@ impl<'s, 't> Session<'s, 't> { Ok(res.is_some()) } - fn del_key(&self, key: &OwnTuple, in_root: bool) -> Result<()> { + pub fn del_key(&self, key: &OwnTuple, in_root: bool) -> Result<()> { self.txn.del(in_root, if in_root { &self.perm_cf } else { &self.temp_cf }, key)?; Ok(()) } diff --git a/src/db/mutation.rs b/src/db/mutation.rs index 19ef89d7..2d89c99c 100644 --- a/src/db/mutation.rs +++ b/src/db/mutation.rs @@ -35,7 +35,7 @@ enum MutationKind { Insert, } -impl<'a, 't> Session<'a, 't> { +impl<'a> Session<'a> { pub fn run_mutation(&mut self, pair: Pair) -> Result<()> { let mut pairs = pair.into_inner(); let kind = match pairs.next().unwrap().as_rule() { @@ -54,11 +54,11 @@ impl<'a, 't> Session<'a, 't> { _ => return Err(LogicError("Mutation requires iterator of values".to_string())) }; let mut default_kind = None; - let mut filters: Option<()> = None; + // let mut filters: Option<()> = None; for p in pairs { match p.as_rule() { Rule::name_in_def => default_kind = Some(build_name_in_def(p, true)?), - Rule::mutation_filter => filters = Some(()), // TODO + Rule::mutation_filter => todo!(), // filters = Some(()), // TODO _ => unreachable!() } } @@ -82,14 +82,14 @@ impl<'a, 't> Session<'a, 't> { } } -struct MutationManager<'a, 'b, 't> { - sess: &'a Session<'b, 't>, +struct MutationManager<'a, 'b> { + sess: &'a Session<'b>, cache: RefCell>>, default_tbl: Option, } -impl<'a, 'b, 't> MutationManager<'a, 'b, 't> { - fn new(sess: &'a Session<'b, 't>, default_tbl: Option) -> Self { +impl<'a, 'b> MutationManager<'a, 'b> { + fn new(sess: &'a Session<'b>, default_tbl: Option) -> Self { Self { sess, cache: RefCell::new(BTreeMap::new()), default_tbl } } fn get_table_info(&self, tbl_name: Cow) -> Result> { diff --git a/src/db/plan.rs b/src/db/plan.rs index 64f0a280..818b2a6e 100644 --- a/src/db/plan.rs +++ b/src/db/plan.rs @@ -73,7 +73,7 @@ pub struct EdgeOrNodeEl { pub kind: EdgeOrNodeKind, } -impl<'a, 't> Session<'a, 't> { +impl<'a> Session<'a> { pub fn parse_from_pattern(&self, pair: Pair) -> Result> { let res: Result> = pair.into_inner().map(|p| { match p.as_rule() { @@ -180,7 +180,7 @@ impl<'a, 't> Session<'a, 't> { #[cfg(test)] mod tests { use std::fs; - use super::*; + // use super::*; use crate::parser::{Parser, Rule}; use pest::Parser as PestParser; use crate::db::engine::Engine; diff --git a/src/db/table.rs b/src/db/table.rs index b9c87a88..9b512248 100644 --- a/src/db/table.rs +++ b/src/db/table.rs @@ -40,7 +40,7 @@ pub struct TableInfo { pub associates: Vec, } -impl<'a, 't> Session<'a, 't> { +impl<'a> Session<'a> { pub fn get_table_info(&self, tbl_name: &str) -> Result { let table_info = match self.resolve(&tbl_name)? { None => return Err(CozoError::UndefinedType(tbl_name.to_string())), diff --git a/src/relation/typing.rs b/src/relation/typing.rs index ac86cdc3..b5284fbd 100644 --- a/src/relation/typing.rs +++ b/src/relation/typing.rs @@ -3,7 +3,6 @@ use pest::iterators::Pair; use crate::error::{Result, CozoError}; use crate::relation::value::Value; use pest::Parser as PestParser; -use cozorocks::SlicePtr; use crate::db::engine::Session; use crate::parser::Parser; use crate::parser::Rule; @@ -65,7 +64,7 @@ impl Typing { } impl Typing { - pub fn from_pair<'a, 't>(pair: Pair, env: Option<&Session<'a, 't>>) -> Result { + pub fn from_pair<'a, 't>(pair: Pair, env: Option<&Session<'a>>) -> Result { Ok(match pair.as_rule() { Rule::simple_type => match pair.as_str() { "Any" => Typing::Any, @@ -146,10 +145,10 @@ impl Typing { _ => Err(CozoError::TypeMismatch) } } - Typing::UnnamedTuple(ut) => { + Typing::UnnamedTuple(_ut) => { todo!() } - Typing::NamedTuple(nt) => { + Typing::NamedTuple(_nt) => { todo!() } Typing::Any => unreachable!(),