main
Ziyang Hu 2 years ago
parent 5cdf6885f4
commit 6d343c6929

@ -1,11 +1,15 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="CrateNotFound" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="CrateVersionInvalid" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true"> <inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages> <Languages>
<language minSize="89" name="Rust" /> <language minSize="89" name="Rust" />
</Languages> </Languages>
</inspection_tool> </inspection_tool>
<inspection_tool class="MissingFeatures" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="NewCrateVersionAvailable" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true"> <inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers"> <option name="ignoredIdentifiers">
<list> <list>
@ -13,5 +17,55 @@
</list> </list>
</option> </option>
</inspection_tool> </inspection_tool>
<inspection_tool class="RsApproxConstant" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsArgumentNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsAssertEqual" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsAssocTypeNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsBareTraitObjects" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsCStringPointer" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsConstNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsConstantConditionIf" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsDanglingElse" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsDeprecation" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsDetachedFile" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsDoubleMustUse" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsDoubleNeg" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsDropRef" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsDuplicatedTraitMethodBinding" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsEnumNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsEnumVariantNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsExtraSemicolon" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsFieldInitShorthand" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsFieldNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsFunctionNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsLifetimeNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsLift" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsLiveness" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsMacroNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsMethodNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsMissingElse" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsModuleNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsNeedlessLifetimes" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsNonShorthandFieldPatterns" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsRedundantElse" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsSelfConvention" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsSimplifyBooleanExpression" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsSimplifyPrint" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsSortImplTraitMembers" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsStaticConstNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsStructNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsSuspiciousAssignment" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsTraitNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsTryMacro" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsTypeAliasNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsTypeParameterNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsUnnecessaryQualifications" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsUnreachableCode" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsUnreachablePatterns" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsUnusedImport" enabled="false" level="ERROR" enabled_by_default="false" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsUnusedMustUse" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsVariableMutable" enabled="false" level="ERROR" enabled_by_default="false" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsVariableNaming" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
<inspection_tool class="RsWhileTrueLoop" enabled="true" level="ERROR" enabled_by_default="true" editorAttributes="ERRORS_ATTRIBUTES" />
</profile> </profile>
</component> </component>

@ -1,7 +1,7 @@
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::str::Utf8Error; use std::str::Utf8Error;
use lazy_static::lazy_static;
use lazy_static::lazy_static;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};

@ -9,8 +9,8 @@ use crate::data::json::JsonValue;
use crate::data::keyword::Keyword; use crate::data::keyword::Keyword;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::parse::triple::TxError; use crate::parse::triple::TxError;
use crate::runtime::transact::SessionTx;
use crate::query::pull::{AttrPullSpec, PullSpec, PullSpecs}; use crate::query::pull::{AttrPullSpec, PullSpec, PullSpecs};
use crate::runtime::transact::SessionTx;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum PullError { pub enum PullError {

@ -1,12 +1,13 @@
use std::collections::btree_map::Entry;
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use std::collections::btree_map::Entry;
use anyhow::Result; use anyhow::Result;
use itertools::Itertools; use itertools::Itertools;
use serde_json::Map; use serde_json::Map;
use crate::{EntityId, Validity};
use crate::data::attr::Attribute; 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::json::JsonValue;
use crate::data::keyword::{Keyword, PROG_ENTRY}; use crate::data::keyword::{Keyword, PROG_ENTRY};
use crate::data::value::DataValue; use crate::data::value::DataValue;
@ -16,7 +17,6 @@ use crate::query::compile::{
RuleApplyAtom, RuleSet, Term, RuleApplyAtom, RuleSet, Term,
}; };
use crate::runtime::transact::SessionTx; use crate::runtime::transact::SessionTx;
use crate::{EntityId, Validity};
impl SessionTx { impl SessionTx {
pub fn parse_rule_sets( pub fn parse_rule_sets(
@ -130,7 +130,7 @@ impl SessionTx {
op.min_arity, op.min_arity,
args.len(), args.len(),
) )
.into()); .into());
} }
} else if args.len() != op.min_arity { } else if args.len() != op.min_arity {
return Err(QueryCompilationError::PredicateArityMismatch( return Err(QueryCompilationError::PredicateArityMismatch(
@ -138,7 +138,7 @@ impl SessionTx {
op.min_arity, op.min_arity,
args.len(), args.len(),
) )
.into()); .into());
} }
Ok(Expr::Apply(op, args)) Ok(Expr::Apply(op, args))
@ -163,7 +163,7 @@ impl SessionTx {
JsonValue::Object(map.clone()), JsonValue::Object(map.clone()),
"must contain either 'const' or 'pred' key".to_string(), "must contain either 'const' or 'pred' key".to_string(),
) )
.into()) .into())
} }
} }
v => Ok(Expr::Const(v.into())), v => Ok(Expr::Const(v.into())),
@ -212,7 +212,7 @@ impl SessionTx {
value_rep.clone(), value_rep.clone(),
"reserved string values must be quoted".to_string(), "reserved string values must be quoted".to_string(),
) )
.into()); .into());
} }
} }
if let Some(o) = value_rep.as_object() { if let Some(o) = value_rep.as_object() {
@ -294,15 +294,15 @@ impl SessionTx {
if rule_head.len() if rule_head.len()
!= rule_head != rule_head
.iter() .iter()
.map(|h| &h.name) .map(|h| &h.name)
.collect::<BTreeSet<_>>() .collect::<BTreeSet<_>>()
.len() .len()
{ {
return Err(QueryCompilationError::DuplicateVariables( return Err(QueryCompilationError::DuplicateVariables(
rule_head.into_iter().map(|h| h.name).collect_vec(), rule_head.into_iter().map(|h| h.name).collect_vec(),
) )
.into()); .into());
} }
Atom::Conjunction(rule_body) Atom::Conjunction(rule_body)
.disjunctive_normal_form() .disjunctive_normal_form()
@ -414,7 +414,7 @@ impl SessionTx {
JsonValue::Object(map.clone()), JsonValue::Object(map.clone()),
"too many keys".to_string(), "too many keys".to_string(),
) )
.into()); .into());
} }
self.parse_logical_atom(map, vld) self.parse_logical_atom(map, vld)
} else { } else {
@ -422,14 +422,14 @@ impl SessionTx {
JsonValue::Object(map.clone()), JsonValue::Object(map.clone()),
"unknown format".to_string(), "unknown format".to_string(),
) )
.into()) .into())
} }
} }
v => Err(QueryCompilationError::UnexpectedForm( v => Err(QueryCompilationError::UnexpectedForm(
v.clone(), v.clone(),
"unknown format".to_string(), "unknown format".to_string(),
) )
.into()), .into()),
} }
} }
fn parse_logical_atom(&mut self, map: &Map<String, JsonValue>, vld: Validity) -> Result<Atom> { fn parse_logical_atom(&mut self, map: &Map<String, JsonValue>, vld: Validity) -> Result<Atom> {
@ -483,7 +483,7 @@ impl SessionTx {
JsonValue::Object(m.clone()), JsonValue::Object(m.clone()),
"expect object with exactly one field".to_string(), "expect object with exactly one field".to_string(),
) )
.into()); .into());
} }
let (k, v) = m.iter().next().unwrap(); let (k, v) = m.iter().next().unwrap();
let kw = Keyword::from(k as &str); let kw = Keyword::from(k as &str);
@ -493,7 +493,7 @@ impl SessionTx {
JsonValue::Object(m.clone()), JsonValue::Object(m.clone()),
"attribute is not a unique index".to_string(), "attribute is not a unique index".to_string(),
) )
.into()); .into());
} }
let value = attr.val_type.coerce_value(v.into())?; let value = attr.val_type.coerce_value(v.into())?;
let eid = self let eid = self
@ -511,7 +511,7 @@ impl SessionTx {
JsonValue::Object(m.clone()), JsonValue::Object(m.clone()),
"expect object with exactly one field".to_string(), "expect object with exactly one field".to_string(),
) )
.into()); .into());
} }
let (k, v) = m.iter().next().unwrap(); let (k, v) = m.iter().next().unwrap();
if k != "const" { if k != "const" {
@ -519,7 +519,7 @@ impl SessionTx {
JsonValue::Object(m.clone()), JsonValue::Object(m.clone()),
"expect object with exactly one field named 'const'".to_string(), "expect object with exactly one field named 'const'".to_string(),
) )
.into()); .into());
} }
let value = attr.val_type.coerce_value(v.into())?; let value = attr.val_type.coerce_value(v.into())?;
Ok(value) Ok(value)
@ -539,7 +539,7 @@ impl SessionTx {
value_rep.clone(), value_rep.clone(),
"reserved string values must be quoted".to_string(), "reserved string values must be quoted".to_string(),
) )
.into()); .into());
} }
} }
if let Some(o) = value_rep.as_object() { if let Some(o) = value_rep.as_object() {
@ -566,7 +566,7 @@ impl SessionTx {
entity_rep.clone(), entity_rep.clone(),
"reserved string values must be quoted".to_string(), "reserved string values must be quoted".to_string(),
) )
.into()); .into());
} }
} }
if let Some(u) = entity_rep.as_u64() { if let Some(u) = entity_rep.as_u64() {
@ -589,7 +589,7 @@ impl SessionTx {
v.clone(), v.clone(),
"expect attribute keyword".to_string(), "expect attribute keyword".to_string(),
) )
.into()), .into()),
} }
} }
} }

@ -5,6 +5,7 @@ use std::ops::Sub;
use anyhow::Result; use anyhow::Result;
use itertools::Itertools; use itertools::Itertools;
use crate::{EntityId, Validity};
use crate::data::attr::Attribute; use crate::data::attr::Attribute;
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::json::JsonValue; use crate::data::json::JsonValue;
@ -13,7 +14,6 @@ use crate::data::value::DataValue;
use crate::query::relation::Relation; use crate::query::relation::Relation;
use crate::runtime::temp_store::TempStore; use crate::runtime::temp_store::TempStore;
use crate::runtime::transact::SessionTx; use crate::runtime::transact::SessionTx;
use crate::{EntityId, Validity};
/// example ruleset in python and javascript /// example ruleset in python and javascript
/// ```python /// ```python
@ -514,7 +514,7 @@ impl SessionTx {
e_kw.clone(), e_kw.clone(),
v_kw.clone(), v_kw.clone(),
]) ])
.into()); .into());
} }
let right = let right =
Relation::triple(a_triple.attr.clone(), vld, e_kw, v_kw); Relation::triple(a_triple.attr.clone(), vld, e_kw, v_kw);
@ -563,7 +563,7 @@ impl SessionTx {
return Err(QueryCompilationError::ArityMismatch( return Err(QueryCompilationError::ArityMismatch(
rule_app.name.clone(), rule_app.name.clone(),
) )
.into()); .into());
} }
let mut prev_joiner_vars = vec![]; let mut prev_joiner_vars = vec![];

@ -3,7 +3,7 @@ use std::mem;
use anyhow::Result; use anyhow::Result;
use itertools::Itertools; 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::data::keyword::{Keyword, PROG_ENTRY};
use crate::query::compile::{ use crate::query::compile::{

@ -67,8 +67,8 @@ impl<'a> TarjanScc<'a> {
pub(crate) type Graph<T> = BTreeMap<T, Vec<T>>; pub(crate) type Graph<T> = BTreeMap<T, Vec<T>>;
pub(crate) fn strongly_connected_components<T>(graph: &Graph<T>) -> Vec<Vec<&T>> pub(crate) fn strongly_connected_components<T>(graph: &Graph<T>) -> Vec<Vec<&T>>
where where
T: Ord, T: Ord,
{ {
let indices = graph.keys().collect_vec(); let indices = graph.keys().collect_vec();
let invert_indices: BTreeMap<_, _> = indices let invert_indices: BTreeMap<_, _> = indices
@ -177,7 +177,7 @@ mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use crate::query::graph::{ use crate::query::graph::{
generalized_kahn, reachable_components, strongly_connected_components, StratifiedGraph, generalized_kahn, reachable_components, StratifiedGraph, strongly_connected_components,
}; };
#[test] #[test]

@ -38,7 +38,7 @@ impl SessionTx {
payload.clone(), payload.clone(),
"empty rules".to_string(), "empty rules".to_string(),
) )
.into()); .into());
} }
let prog = if rules_payload.first().unwrap().is_array() { let prog = if rules_payload.first().unwrap().is_array() {
let q = json!([{"rule": "?", "args": rules_payload}]); let q = json!([{"rule": "?", "args": rules_payload}]);
@ -146,7 +146,7 @@ impl SessionTx {
v.clone(), v.clone(),
"out specification should be an array".to_string(), "out specification should be an array".to_string(),
) )
.into()), .into()),
} }
} }
fn parse_pull_specs_for_query( fn parse_pull_specs_for_query(
@ -209,11 +209,11 @@ impl SessionTx {
v.clone(), v.clone(),
"expect binding or map".to_string(), "expect binding or map".to_string(),
) )
.into()), .into()),
} }
}) })
.try_collect() .try_collect()
} }
} }
pub type QueryResult<'a> = Box<dyn Iterator<Item = Result<JsonValue>> + 'a>; pub type QueryResult<'a> = Box<dyn Iterator<Item=Result<JsonValue>> + 'a>;

@ -1035,7 +1035,7 @@ impl StoredDerivedRelation {
'outer: for found in self.storage.scan_prefix(&prefix) { 'outer: for found in self.storage.scan_prefix(&prefix) {
let found = found?; let found = found?;
for (left_idx, right_idx) in 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] { if tuple.0[*left_idx] != found.0[*right_idx] {
continue 'outer; continue 'outer;
@ -1142,7 +1142,7 @@ impl Debug for Joiner {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let left_bindings = BindingFormatter(self.left_keys.clone()); let left_bindings = BindingFormatter(self.left_keys.clone());
let right_bindings = BindingFormatter(self.right_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) joiner: Joiner,
pub(crate) to_eliminate: BTreeSet<Keyword>, pub(crate) to_eliminate: BTreeSet<Keyword>,
} }
impl NegJoin { impl NegJoin {
pub(crate) fn do_eliminate_temp_vars(&mut self, used: &BTreeSet<Keyword>) -> Result<()> { pub(crate) fn do_eliminate_temp_vars(&mut self, used: &BTreeSet<Keyword>) -> Result<()> {
for binding in self.left.bindings_after_eliminate() { for binding in self.left.bindings_after_eliminate() {

@ -1,5 +1,5 @@
use std::collections::btree_map::Entry;
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use std::collections::btree_map::Entry;
use anyhow::Result; use anyhow::Result;
use itertools::Itertools; use itertools::Itertools;
@ -7,7 +7,7 @@ use itertools::Itertools;
use crate::data::keyword::{Keyword, PROG_ENTRY}; use crate::data::keyword::{Keyword, PROG_ENTRY};
use crate::query::compile::{Atom, DatalogProgram, RuleSet}; use crate::query::compile::{Atom, DatalogProgram, RuleSet};
use crate::query::graph::{ 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)] #[derive(thiserror::Error, Debug)]
@ -90,7 +90,7 @@ fn verify_no_cycle(g: &StratifiedGraph<&'_ Keyword>, sccs: &[BTreeSet<&Keyword>]
return Err(GraphError::GraphNotStratified( return Err(GraphError::GraphNotStratified(
scc.iter().cloned().cloned().collect(), scc.iter().cloned().cloned().collect(),
) )
.into()); .into());
} }
} }
} }
@ -166,7 +166,7 @@ pub(crate) fn stratify_program(prog: &DatalogProgram) -> Result<Vec<DatalogProgr
let (invert_indices, reduced_graph) = make_scc_reduced_graph(&sccs, &stratified_graph); let (invert_indices, reduced_graph) = make_scc_reduced_graph(&sccs, &stratified_graph);
// 6. topological sort the reduced graph to get a stratification // 6. topological sort the reduced graph to get a stratification
let sort_result = generalized_kahn(&reduced_graph, stratified_graph.len()); let sort_result = generalized_kahn(&reduced_graph, stratified_graph.len());
let n_strata = sort_result.len(); let n_strata = sort_result.len();
let invert_sort_result = sort_result.into_iter().enumerate().flat_map(|(stratum, indices)| { let invert_sort_result = sort_result.into_iter().enumerate().flat_map(|(stratum, indices)| {
indices.into_iter().map(move |idx| (idx, stratum)) indices.into_iter().map(move |idx| (idx, stratum))
}).collect::<BTreeMap<_, _>>(); }).collect::<BTreeMap<_, _>>();

@ -1,8 +1,8 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::env::temp_dir; use std::env::temp_dir;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize, Ordering};
use anyhow::Result; use anyhow::Result;
use itertools::Itertools; use itertools::Itertools;
@ -11,7 +11,8 @@ use uuid::Uuid;
use cozorocks::{DbBuilder, DbIter, RawRocksDb, RocksDb}; 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::{ use crate::data::encode::{
decode_ea_key, decode_value_from_key, decode_value_from_val, encode_eav_key, StorageTag, 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::data::value::DataValue;
use crate::query::pull::CurrentPath; use crate::query::pull::CurrentPath;
use crate::runtime::transact::SessionTx; use crate::runtime::transact::SessionTx;
use crate::AttrTxItem;
pub struct Db { pub struct Db {
db: RocksDb, db: RocksDb,

Loading…
Cancel
Save