remove params nonsense

main
Ziyang Hu 2 years ago
parent 7a735269b5
commit 571d072d4c

@ -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<RwLock<SessionHandle>>,
pub txn: TransactionPtr,
pub perm_cf: SharedPtr<ColumnFamilyHandle>,
pub temp_cf: SharedPtr<ColumnFamilyHandle>,
pub params: BTreeMap<String, &'b str>,
}
// 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);

@ -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<Option<Value>> {
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<String, Value>, table_bindings: BTreeMap<String, ()>) -> Result<(bool, Value<'a>)> {
pub fn partial_eval<'a>(&self, value: Value<'a>, params: BTreeMap<String, Value<'a>>,
_table_bindings: BTreeMap<String, ()>) -> 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<Option<Tuple<SlicePtr>>> {
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<Value> {
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(())
}

@ -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<Rule>) -> 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<BTreeMap<String, Rc<TableInfo>>>,
default_tbl: Option<String>,
}
impl<'a, 'b, 't> MutationManager<'a, 'b, 't> {
fn new(sess: &'a Session<'b, 't>, default_tbl: Option<String>) -> Self {
impl<'a, 'b> MutationManager<'a, 'b> {
fn new(sess: &'a Session<'b>, default_tbl: Option<String>) -> Self {
Self { sess, cache: RefCell::new(BTreeMap::new()), default_tbl }
}
fn get_table_info(&self, tbl_name: Cow<str>) -> Result<Rc<TableInfo>> {

@ -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<Rule>) -> Result<Vec<FromEl>> {
let res: Result<Vec<_>> = 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;

@ -40,7 +40,7 @@ pub struct TableInfo {
pub associates: Vec<TableInfo>,
}
impl<'a, 't> Session<'a, 't> {
impl<'a> Session<'a> {
pub fn get_table_info(&self, tbl_name: &str) -> Result<TableInfo> {
let table_info = match self.resolve(&tbl_name)? {
None => return Err(CozoError::UndefinedType(tbl_name.to_string())),

@ -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<Rule>, env: Option<&Session<'a, 't>>) -> Result<Self> {
pub fn from_pair<'a, 't>(pair: Pair<Rule>, env: Option<&Session<'a>>) -> Result<Self> {
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!(),

Loading…
Cancel
Save