From cda264a45828e910c53fca86c967b96aa9653e3b Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Fri, 29 Apr 2022 18:55:56 +0800 Subject: [PATCH] some cleanup --- cozorocks/src/lib.rs | 4 +- src/db/engine.rs | 3 +- src/db/eval.rs | 54 +++++++++++++------------- src/db/mutation.rs | 4 +- src/db/plan.rs | 72 +++++++++++++++++------------------ src/error.rs | 5 ++- src/parser/text_identifier.rs | 1 - src/relation/tuple.rs | 2 - src/relation/typing.rs | 3 +- src/relation/value.rs | 2 +- 10 files changed, 73 insertions(+), 77 deletions(-) diff --git a/cozorocks/src/lib.rs b/cozorocks/src/lib.rs index 8d809f85..18f20b69 100644 --- a/cozorocks/src/lib.rs +++ b/cozorocks/src/lib.rs @@ -2,7 +2,7 @@ mod bridge; use bridge::*; -use std::fmt::{Display, Formatter, write}; +use std::fmt::{Display, Formatter}; use std::fmt::Debug; use std::ops::{Deref, DerefMut}; use cxx::{let_cxx_string}; @@ -536,7 +536,7 @@ impl TransactionPtr { match res { Ok(r) => Ok(Some(r)), Err(e) if e.status.code == StatusCode::kNotFound => Ok(None), - res => res.map(|v| None) + res => res.map(|_| None) } } #[inline] diff --git a/src/db/engine.rs b/src/db/engine.rs index de01004f..a67b9c74 100644 --- a/src/db/engine.rs +++ b/src/db/engine.rs @@ -12,7 +12,6 @@ use rand::Rng; use crate::error::{CozoError, Result}; use crate::error::CozoError::{Poisoned, SessionErr}; use crate::relation::tuple::Tuple; -use crate::relation::value::{StaticValue, Value}; pub struct EngineOptions { cmp: RustComparatorPtr, @@ -109,7 +108,7 @@ impl Engine { perm_cf: SharedPtr::null(), temp_cf: SharedPtr::null(), handle, - params: BTreeMap::default() + params: BTreeMap::default(), }; sess.start()?; Ok(sess) diff --git a/src/db/eval.rs b/src/db/eval.rs index 6c90f731..2d6aaece 100644 --- a/src/db/eval.rs +++ b/src/db/eval.rs @@ -1,15 +1,12 @@ use std::borrow::Cow; use std::collections::{BTreeMap, HashSet}; -use std::path::is_separator; -use std::process::id; use pest::Parser as PestParser; use pest::iterators::{Pair, Pairs}; -use cozorocks::{SlicePtr, StatusCode}; +use cozorocks::{SlicePtr}; use crate::db::engine::{Session}; -use crate::relation::table::{Table}; use crate::relation::tuple::{OwnTuple, Tuple}; use crate::relation::typing::Typing; -use crate::relation::value::{StaticValue, Value}; +use crate::relation::value::{Value}; use crate::error::{CozoError, Result}; use crate::relation::data::DataKind; use crate::parser::{Parser, Rule}; @@ -27,9 +24,6 @@ pub trait Environment<'t, T: AsRef<[u8]>> where Self: Sized { data.push_value(val); self.define_data(name, data, in_root) } - fn define_table(&mut self, table: &Table, in_root: bool) -> Result<()> { - todo!() - } fn resolve(&self, name: &str) -> Result>>; fn resolve_param(&self, name: &str) -> Result; fn resolve_value(&self, name: &str) -> Result> { @@ -813,25 +807,31 @@ mod tests { email: Text } "#; - // let mut env = MemoryEnv::default(); - // let mut parsed = Parser::parse(Rule::file, s).unwrap(); - // - // let t = parsed.next().unwrap(); - // env.run_definition(t).unwrap(); - // println!("{:?}", env.resolve("Person")); - // - // let t = parsed.next().unwrap(); - // env.run_definition(t).unwrap(); - // println!("{:?}", env.resolve("Friend")); - // - // let t = parsed.next().unwrap(); - // env.run_definition(t).unwrap(); - // println!("{:?}", env.resolve("XXY")); - // - // let t = parsed.next().unwrap(); - // env.run_definition(t).unwrap(); - // println!("{:?}", env.resolve("WorkInfo")); - // println!("{:?}", env.resolve("Person")); + let db_path = "_test_node"; + { + let engine = Engine::new(db_path.to_string(), true).unwrap(); + let mut env = engine.session().unwrap(); + + let mut parsed = Parser::parse(Rule::file, s).unwrap(); + + let t = parsed.next().unwrap(); + env.run_definition(t).unwrap(); + println!("{:?}", env.resolve("Person")); + + let t = parsed.next().unwrap(); + env.run_definition(t).unwrap(); + println!("{:?}", env.resolve("Friend")); + + let t = parsed.next().unwrap(); + env.run_definition(t).unwrap(); + println!("{:?}", env.resolve("XXY")); + + let t = parsed.next().unwrap(); + env.run_definition(t).unwrap(); + println!("{:?}", env.resolve("WorkInfo")); + println!("{:?}", env.resolve("Person")); + } + fs::remove_dir_all(db_path).unwrap(); } #[test] diff --git a/src/db/mutation.rs b/src/db/mutation.rs index 7f96d543..962e6ec5 100644 --- a/src/db/mutation.rs +++ b/src/db/mutation.rs @@ -75,7 +75,7 @@ impl<'a, 'b, 't> MutationManager<'a, 'b, 't> { None => { self.cache.insert(tbl_name.to_string(), ()); } - Some(t) => {}, + Some(_t) => {} } Ok(()) } @@ -124,7 +124,7 @@ mod tests { insert [{id: 1, name: "Jack"}, {id: 2, name: "Joe", habits: ["Balls"]}] as Person; "#; let p = Parser::parse(Rule::file, s).unwrap().next().unwrap(); - sess.run_mutation(p); + sess.run_mutation(p).unwrap(); } drop(engine); diff --git a/src/db/plan.rs b/src/db/plan.rs index ab3c70ea..9906543f 100644 --- a/src/db/plan.rs +++ b/src/db/plan.rs @@ -1,36 +1,36 @@ -struct Filter; - -enum QueryPlan { - Union { - args: Vec - }, - Intersection { - args: Vec - }, - Difference { - left: Box, - right: Box, - }, - Selection { - arg: Box, - filter: (), - }, - Projection { - arg: Box, - keys: (), - fields: (), - }, - Product { - args: Vec - }, - Join { - args: Vec - }, - LeftJoin { - left: Box, - right: Box - }, - BaseRelation { - relation: () - }, -} \ No newline at end of file +// struct Filter; +// +// enum QueryPlan { +// Union { +// args: Vec +// }, +// Intersection { +// args: Vec +// }, +// Difference { +// left: Box, +// right: Box, +// }, +// Selection { +// arg: Box, +// filter: (), +// }, +// Projection { +// arg: Box, +// keys: (), +// fields: (), +// }, +// Product { +// args: Vec +// }, +// Join { +// args: Vec +// }, +// LeftJoin { +// left: Box, +// right: Box +// }, +// BaseRelation { +// relation: () +// }, +// } \ No newline at end of file diff --git a/src/error.rs b/src/error.rs index 81851183..cb083909 100644 --- a/src/error.rs +++ b/src/error.rs @@ -82,8 +82,9 @@ pub enum CozoError { // #[error(transparent)] // Storage(#[from] cozo_rocks::BridgeStatus), // -// #[error(transparent)] -// Io(#[from] std::io::Error), + #[error(transparent)] + Io(#[from] std::io::Error), + #[error("Session error")] SessionErr, diff --git a/src/parser/text_identifier.rs b/src/parser/text_identifier.rs index 9fc23478..eccbb272 100644 --- a/src/parser/text_identifier.rs +++ b/src/parser/text_identifier.rs @@ -1,5 +1,4 @@ use pest::iterators::Pair; -use crate::parser::Parser; use crate::parser::Rule; use crate::error::{CozoError, Result}; use crate::parser::number::parse_int; diff --git a/src/relation/tuple.rs b/src/relation/tuple.rs index 9855f927..b57ee71c 100644 --- a/src/relation/tuple.rs +++ b/src/relation/tuple.rs @@ -1,10 +1,8 @@ use std::borrow::{Cow}; use std::cell::RefCell; use std::collections::BTreeMap; -use std::convert::Infallible; use std::fmt::{Debug, Formatter}; use std::hash::{Hash, Hasher}; -use std::ptr::write; use uuid::Uuid; use crate::relation::data::DataKind; use crate::relation::value::{Tag, Value}; diff --git a/src/relation/typing.rs b/src/relation/typing.rs index 4a916664..594118c6 100644 --- a/src/relation/typing.rs +++ b/src/relation/typing.rs @@ -1,5 +1,4 @@ -use std::collections::BTreeMap; -use std::fmt::{Display, Formatter, write}; +use std::fmt::{Display, Formatter}; use pest::iterators::Pair; use crate::error::{Result, CozoError}; use crate::relation::value::Value; diff --git a/src/relation/value.rs b/src/relation/value.rs index 5ed956e6..c4eed19a 100644 --- a/src/relation/value.rs +++ b/src/relation/value.rs @@ -376,7 +376,7 @@ fn build_expr_primary(pair: Pair) -> Result { Rule::boolean => Ok(Value::Bool(pair.as_str() == "true")), Rule::quoted_string | Rule::s_quoted_string | Rule::raw_string => Ok( Value::Text(Cow::Owned(parse_string(pair)?))), - Rule::list => Ok(pair.into_inner().map(|v| build_expr_primary(v)).collect::>>()?.into()), + Rule::list => Ok(pair.into_inner().map(build_expr_primary).collect::>>()?.into()), Rule::dict => { Ok(pair.into_inner().map(|p| { match p.as_rule() {