From 6d343c6929937615e7487c419f4e96fd61bb0198 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Sat, 30 Jul 2022 11:51:34 +0800 Subject: [PATCH] reformat --- .idea/inspectionProfiles/Project_Default.xml | 54 ++++++++++++++++++++ src/data/keyword.rs | 2 +- src/parse/pull.rs | 2 +- src/parse/query.rs | 44 ++++++++-------- src/query/compile.rs | 6 +-- src/query/eval.rs | 2 +- src/query/graph.rs | 6 +-- src/query/mod.rs | 8 +-- src/query/relation.rs | 5 +- src/query/stratify.rs | 8 +-- src/runtime/db.rs | 6 +-- 11 files changed, 99 insertions(+), 44 deletions(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 1d32867e..dfdc226f 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,11 +1,15 @@ \ No newline at end of file diff --git a/src/data/keyword.rs b/src/data/keyword.rs index e71c4509..a5e4f428 100644 --- a/src/data/keyword.rs +++ b/src/data/keyword.rs @@ -1,7 +1,7 @@ use std::fmt::{Debug, Display, Formatter}; use std::str::Utf8Error; -use lazy_static::lazy_static; +use lazy_static::lazy_static; use serde_derive::{Deserialize, Serialize}; use smartstring::{LazyCompact, SmartString}; diff --git a/src/parse/pull.rs b/src/parse/pull.rs index a2878c60..6dd6d831 100644 --- a/src/parse/pull.rs +++ b/src/parse/pull.rs @@ -9,8 +9,8 @@ use crate::data::json::JsonValue; use crate::data::keyword::Keyword; use crate::data::value::DataValue; use crate::parse::triple::TxError; -use crate::runtime::transact::SessionTx; use crate::query::pull::{AttrPullSpec, PullSpec, PullSpecs}; +use crate::runtime::transact::SessionTx; #[derive(Debug, thiserror::Error)] pub enum PullError { diff --git a/src/parse/query.rs b/src/parse/query.rs index e65ed7d5..da0b3382 100644 --- a/src/parse/query.rs +++ b/src/parse/query.rs @@ -1,12 +1,13 @@ -use std::collections::btree_map::Entry; use std::collections::{BTreeMap, BTreeSet}; +use std::collections::btree_map::Entry; use anyhow::Result; use itertools::Itertools; use serde_json::Map; +use crate::{EntityId, Validity}; use crate::data::attr::Attribute; -use crate::data::expr::{get_op, Expr}; +use crate::data::expr::{Expr, get_op}; use crate::data::json::JsonValue; use crate::data::keyword::{Keyword, PROG_ENTRY}; use crate::data::value::DataValue; @@ -16,7 +17,6 @@ use crate::query::compile::{ RuleApplyAtom, RuleSet, Term, }; use crate::runtime::transact::SessionTx; -use crate::{EntityId, Validity}; impl SessionTx { pub fn parse_rule_sets( @@ -130,7 +130,7 @@ impl SessionTx { op.min_arity, args.len(), ) - .into()); + .into()); } } else if args.len() != op.min_arity { return Err(QueryCompilationError::PredicateArityMismatch( @@ -138,7 +138,7 @@ impl SessionTx { op.min_arity, args.len(), ) - .into()); + .into()); } Ok(Expr::Apply(op, args)) @@ -163,7 +163,7 @@ impl SessionTx { JsonValue::Object(map.clone()), "must contain either 'const' or 'pred' key".to_string(), ) - .into()) + .into()) } } v => Ok(Expr::Const(v.into())), @@ -212,7 +212,7 @@ impl SessionTx { value_rep.clone(), "reserved string values must be quoted".to_string(), ) - .into()); + .into()); } } if let Some(o) = value_rep.as_object() { @@ -294,15 +294,15 @@ impl SessionTx { if rule_head.len() != rule_head - .iter() - .map(|h| &h.name) - .collect::>() - .len() + .iter() + .map(|h| &h.name) + .collect::>() + .len() { return Err(QueryCompilationError::DuplicateVariables( rule_head.into_iter().map(|h| h.name).collect_vec(), ) - .into()); + .into()); } Atom::Conjunction(rule_body) .disjunctive_normal_form() @@ -414,7 +414,7 @@ impl SessionTx { JsonValue::Object(map.clone()), "too many keys".to_string(), ) - .into()); + .into()); } self.parse_logical_atom(map, vld) } else { @@ -422,14 +422,14 @@ impl SessionTx { JsonValue::Object(map.clone()), "unknown format".to_string(), ) - .into()) + .into()) } } v => Err(QueryCompilationError::UnexpectedForm( v.clone(), "unknown format".to_string(), ) - .into()), + .into()), } } fn parse_logical_atom(&mut self, map: &Map, vld: Validity) -> Result { @@ -483,7 +483,7 @@ impl SessionTx { JsonValue::Object(m.clone()), "expect object with exactly one field".to_string(), ) - .into()); + .into()); } let (k, v) = m.iter().next().unwrap(); let kw = Keyword::from(k as &str); @@ -493,7 +493,7 @@ impl SessionTx { JsonValue::Object(m.clone()), "attribute is not a unique index".to_string(), ) - .into()); + .into()); } let value = attr.val_type.coerce_value(v.into())?; let eid = self @@ -511,7 +511,7 @@ impl SessionTx { JsonValue::Object(m.clone()), "expect object with exactly one field".to_string(), ) - .into()); + .into()); } let (k, v) = m.iter().next().unwrap(); if k != "const" { @@ -519,7 +519,7 @@ impl SessionTx { JsonValue::Object(m.clone()), "expect object with exactly one field named 'const'".to_string(), ) - .into()); + .into()); } let value = attr.val_type.coerce_value(v.into())?; Ok(value) @@ -539,7 +539,7 @@ impl SessionTx { value_rep.clone(), "reserved string values must be quoted".to_string(), ) - .into()); + .into()); } } if let Some(o) = value_rep.as_object() { @@ -566,7 +566,7 @@ impl SessionTx { entity_rep.clone(), "reserved string values must be quoted".to_string(), ) - .into()); + .into()); } } if let Some(u) = entity_rep.as_u64() { @@ -589,7 +589,7 @@ impl SessionTx { v.clone(), "expect attribute keyword".to_string(), ) - .into()), + .into()), } } } diff --git a/src/query/compile.rs b/src/query/compile.rs index 9eddd7f4..c045fd29 100644 --- a/src/query/compile.rs +++ b/src/query/compile.rs @@ -5,6 +5,7 @@ use std::ops::Sub; use anyhow::Result; use itertools::Itertools; +use crate::{EntityId, Validity}; use crate::data::attr::Attribute; use crate::data::expr::Expr; use crate::data::json::JsonValue; @@ -13,7 +14,6 @@ use crate::data::value::DataValue; use crate::query::relation::Relation; use crate::runtime::temp_store::TempStore; use crate::runtime::transact::SessionTx; -use crate::{EntityId, Validity}; /// example ruleset in python and javascript /// ```python @@ -514,7 +514,7 @@ impl SessionTx { e_kw.clone(), v_kw.clone(), ]) - .into()); + .into()); } let right = Relation::triple(a_triple.attr.clone(), vld, e_kw, v_kw); @@ -563,7 +563,7 @@ impl SessionTx { return Err(QueryCompilationError::ArityMismatch( rule_app.name.clone(), ) - .into()); + .into()); } let mut prev_joiner_vars = vec![]; diff --git a/src/query/eval.rs b/src/query/eval.rs index ce4d8ceb..189b0d87 100644 --- a/src/query/eval.rs +++ b/src/query/eval.rs @@ -3,7 +3,7 @@ use std::mem; use anyhow::Result; use itertools::Itertools; -use log::{debug, log_enabled, trace, Level}; +use log::{debug, Level, log_enabled, trace}; use crate::data::keyword::{Keyword, PROG_ENTRY}; use crate::query::compile::{ diff --git a/src/query/graph.rs b/src/query/graph.rs index fa2ed93e..ea730586 100644 --- a/src/query/graph.rs +++ b/src/query/graph.rs @@ -67,8 +67,8 @@ impl<'a> TarjanScc<'a> { pub(crate) type Graph = BTreeMap>; pub(crate) fn strongly_connected_components(graph: &Graph) -> Vec> -where - T: Ord, + where + T: Ord, { let indices = graph.keys().collect_vec(); let invert_indices: BTreeMap<_, _> = indices @@ -177,7 +177,7 @@ mod tests { use std::collections::BTreeMap; use crate::query::graph::{ - generalized_kahn, reachable_components, strongly_connected_components, StratifiedGraph, + generalized_kahn, reachable_components, StratifiedGraph, strongly_connected_components, }; #[test] diff --git a/src/query/mod.rs b/src/query/mod.rs index 3a259126..7ef85fd2 100644 --- a/src/query/mod.rs +++ b/src/query/mod.rs @@ -38,7 +38,7 @@ impl SessionTx { payload.clone(), "empty rules".to_string(), ) - .into()); + .into()); } let prog = if rules_payload.first().unwrap().is_array() { let q = json!([{"rule": "?", "args": rules_payload}]); @@ -146,7 +146,7 @@ impl SessionTx { v.clone(), "out specification should be an array".to_string(), ) - .into()), + .into()), } } fn parse_pull_specs_for_query( @@ -209,11 +209,11 @@ impl SessionTx { v.clone(), "expect binding or map".to_string(), ) - .into()), + .into()), } }) .try_collect() } } -pub type QueryResult<'a> = Box> + 'a>; +pub type QueryResult<'a> = Box> + 'a>; diff --git a/src/query/relation.rs b/src/query/relation.rs index 7d296bed..dff7fa7b 100644 --- a/src/query/relation.rs +++ b/src/query/relation.rs @@ -1035,7 +1035,7 @@ impl StoredDerivedRelation { 'outer: for found in self.storage.scan_prefix(&prefix) { let found = found?; for (left_idx, right_idx) in - left_join_indices.iter().zip(right_join_indices.iter()) + left_join_indices.iter().zip(right_join_indices.iter()) { if tuple.0[*left_idx] != found.0[*right_idx] { continue 'outer; @@ -1142,7 +1142,7 @@ impl Debug for Joiner { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let left_bindings = BindingFormatter(self.left_keys.clone()); let right_bindings = BindingFormatter(self.right_keys.clone()); - write!(f, "{:?}<->{:?}", left_bindings, right_bindings,) + write!(f, "{:?}<->{:?}", left_bindings, right_bindings, ) } } @@ -1265,6 +1265,7 @@ pub struct NegJoin { pub(crate) joiner: Joiner, pub(crate) to_eliminate: BTreeSet, } + impl NegJoin { pub(crate) fn do_eliminate_temp_vars(&mut self, used: &BTreeSet) -> Result<()> { for binding in self.left.bindings_after_eliminate() { diff --git a/src/query/stratify.rs b/src/query/stratify.rs index edcca67b..1752773b 100644 --- a/src/query/stratify.rs +++ b/src/query/stratify.rs @@ -1,5 +1,5 @@ -use std::collections::btree_map::Entry; use std::collections::{BTreeMap, BTreeSet}; +use std::collections::btree_map::Entry; use anyhow::Result; use itertools::Itertools; @@ -7,7 +7,7 @@ use itertools::Itertools; use crate::data::keyword::{Keyword, PROG_ENTRY}; use crate::query::compile::{Atom, DatalogProgram, RuleSet}; use crate::query::graph::{ - generalized_kahn, reachable_components, strongly_connected_components, Graph, StratifiedGraph, + generalized_kahn, Graph, reachable_components, StratifiedGraph, strongly_connected_components, }; #[derive(thiserror::Error, Debug)] @@ -90,7 +90,7 @@ fn verify_no_cycle(g: &StratifiedGraph<&'_ Keyword>, sccs: &[BTreeSet<&Keyword>] return Err(GraphError::GraphNotStratified( scc.iter().cloned().cloned().collect(), ) - .into()); + .into()); } } } @@ -166,7 +166,7 @@ pub(crate) fn stratify_program(prog: &DatalogProgram) -> Result>(); diff --git a/src/runtime/db.rs b/src/runtime/db.rs index f313151a..b3f11f51 100644 --- a/src/runtime/db.rs +++ b/src/runtime/db.rs @@ -1,8 +1,8 @@ use std::collections::BTreeMap; use std::env::temp_dir; use std::fmt::{Debug, Formatter}; -use std::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize, Ordering}; use anyhow::Result; use itertools::Itertools; @@ -11,7 +11,8 @@ use uuid::Uuid; use cozorocks::{DbBuilder, DbIter, RawRocksDb, RocksDb}; -use crate::data::compare::{rusty_cmp, DB_KEY_PREFIX_LEN}; +use crate::AttrTxItem; +use crate::data::compare::{DB_KEY_PREFIX_LEN, rusty_cmp}; use crate::data::encode::{ decode_ea_key, decode_value_from_key, decode_value_from_val, encode_eav_key, StorageTag, }; @@ -22,7 +23,6 @@ use crate::data::tuple::{rusty_scratch_cmp, SCRATCH_DB_KEY_PREFIX_LEN}; use crate::data::value::DataValue; use crate::query::pull::CurrentPath; use crate::runtime::transact::SessionTx; -use crate::AttrTxItem; pub struct Db { db: RocksDb,