formatting

main
Ziyang Hu 2 years ago
parent 3583438bb0
commit 9ccb891233

@ -10,13 +10,13 @@
extern crate test; extern crate test;
use std::cmp::max;
use cozo::{DbInstance, NamedRows}; use cozo::{DbInstance, NamedRows};
use itertools::Itertools; use itertools::Itertools;
use lazy_static::{initialize, lazy_static}; use lazy_static::{initialize, lazy_static};
use rand::Rng; use rand::Rng;
use rayon::prelude::*; use rayon::prelude::*;
use serde_json::json; use serde_json::json;
use std::cmp::max;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::time::Instant; use std::time::Instant;
use test::Bencher; use test::Bencher;

@ -796,7 +796,6 @@ impl NormalAggrObj for AggrSmallestBy {
} }
} }
define_aggr!(AGGR_MIN_COST, true); define_aggr!(AGGR_MIN_COST, true);
pub(crate) struct AggrMinCost { pub(crate) struct AggrMinCost {

@ -6,8 +6,8 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use base64::Engine;
use base64::engine::general_purpose::STANDARD; use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use serde_json::json; use serde_json::json;
pub(crate) use serde_json::Value as JsonValue; pub(crate) use serde_json::Value as JsonValue;
@ -29,11 +29,7 @@ impl From<JsonValue> for DataValue {
JsonValue::Array(arr) => DataValue::List(arr.iter().map(DataValue::from).collect()), JsonValue::Array(arr) => DataValue::List(arr.iter().map(DataValue::from).collect()),
JsonValue::Object(d) => DataValue::List( JsonValue::Object(d) => DataValue::List(
d.into_iter() d.into_iter()
.map(|(k, v)| { .map(|(k, v)| DataValue::List([DataValue::from(k), DataValue::from(v)].into()))
DataValue::List(
[DataValue::from(k), DataValue::from(v)].into(),
)
})
.collect(), .collect(),
), ),
} }

@ -6,17 +6,16 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
pub(crate) mod json;
pub(crate) mod symb;
pub(crate) mod value;
pub(crate) mod tuple;
pub(crate) mod expr;
pub(crate) mod program;
pub(crate) mod aggr; pub(crate) mod aggr;
pub(crate) mod expr;
pub(crate) mod functions; pub(crate) mod functions;
pub(crate) mod relation; pub(crate) mod json;
pub(crate) mod memcmp; pub(crate) mod memcmp;
pub(crate) mod program;
pub(crate) mod relation;
pub(crate) mod symb;
pub(crate) mod tuple;
pub(crate) mod value;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

@ -6,20 +6,29 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use crate::{DataValue, new_cozo_mem}; use crate::{new_cozo_mem, DataValue};
#[test] #[test]
fn expression_eval() { fn expression_eval() {
let db = new_cozo_mem().unwrap(); let db = new_cozo_mem().unwrap();
let res = db
let res = db.run_script(r#" .run_script(
r#"
?[a] := a = if(2 + 3 > 1 * 99999, 190291021 + 14341234212 / 2121) ?[a] := a = if(2 + 3 > 1 * 99999, 190291021 + 14341234212 / 2121)
"#, Default::default()).unwrap(); "#,
Default::default(),
)
.unwrap();
assert_eq!(res.rows[0][0], DataValue::Null); assert_eq!(res.rows[0][0], DataValue::Null);
let res = db.run_script(r#" let res = db
.run_script(
r#"
?[a] := a = if(2 + 3 > 1, true, false) ?[a] := a = if(2 + 3 > 1, true, false)
"#, Default::default()).unwrap(); "#,
Default::default(),
)
.unwrap();
assert_eq!(res.rows[0][0].get_bool().unwrap(), true); assert_eq!(res.rows[0][0].get_bool().unwrap(), true);
} }

@ -6,10 +6,10 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
mod functions;
mod aggrs; mod aggrs;
mod validity; mod exprs;
mod functions;
mod json; mod json;
mod memcmp; mod memcmp;
mod validity;
mod values; mod values;
mod exprs;

@ -6,9 +6,9 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use std::cmp::Reverse;
use crate::data::functions::TERMINAL_VALIDITY; use crate::data::functions::TERMINAL_VALIDITY;
use miette::Result; use miette::Result;
use std::cmp::Reverse;
use crate::data::memcmp::MemCmpEncoder; use crate::data::memcmp::MemCmpEncoder;
use crate::data::value::{DataValue, Validity, ValidityTs}; use crate::data::value::{DataValue, Validity, ValidityTs};

@ -6,12 +6,12 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use std::cmp::{Ordering, Reverse}; use std::cmp::{Ordering, Reverse};
use std::collections::BTreeSet; use std::collections::BTreeSet;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
use regex::Regex; use regex::Regex;

@ -6,9 +6,9 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use std::cmp::Reverse; use std::cmp::Reverse;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use itertools::Itertools; use itertools::Itertools;
use miette::Result; use miette::Result;
@ -17,11 +17,11 @@ use priority_queue::PriorityQueue;
use rayon::prelude::*; use rayon::prelude::*;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::algos::shortest_path_dijkstra::dijkstra_keep_ties;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::algos::shortest_path_dijkstra::dijkstra_keep_ties;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;
@ -38,8 +38,7 @@ impl FixedRule for BetweennessCentrality {
let edges = payload.get_input(0)?; let edges = payload.get_input(0)?;
let undirected = payload.bool_option("undirected", Some(false))?; let undirected = payload.bool_option("undirected", Some(false))?;
let (graph, indices, _inv_indices) = let (graph, indices, _inv_indices) = edges.as_directed_weighted_graph(undirected, false)?;
edges.as_directed_weighted_graph(undirected, false)?;
let n = graph.node_count(); let n = graph.node_count();
if n == 0 { if n == 0 {
@ -107,8 +106,7 @@ impl FixedRule for ClosenessCentrality {
let edges = payload.get_input(0)?; let edges = payload.get_input(0)?;
let undirected = payload.bool_option("undirected", Some(false))?; let undirected = payload.bool_option("undirected", Some(false))?;
let (graph, indices, _inv_indices) = let (graph, indices, _inv_indices) = edges.as_directed_weighted_graph(undirected, false)?;
edges.as_directed_weighted_graph(undirected, false)?;
let n = graph.node_count(); let n = graph.node_count();
if n == 0 { if n == 0 {
@ -125,7 +123,10 @@ impl FixedRule for ClosenessCentrality {
}) })
.collect::<Result<_>>()?; .collect::<Result<_>>()?;
for (idx, centrality) in res.into_iter().enumerate() { for (idx, centrality) in res.into_iter().enumerate() {
out.put(vec![indices[idx].clone(), DataValue::from(centrality as f64)]); out.put(vec![
indices[idx].clone(),
DataValue::from(centrality as f64),
]);
poison.check()?; poison.check()?;
} }
Ok(()) Ok(())
@ -167,7 +168,6 @@ pub(crate) fn dijkstra_cost_only(
distance[nxt_node as usize] = nxt_cost; distance[nxt_node as usize] = nxt_cost;
back_pointers[nxt_node as usize] = node; back_pointers[nxt_node as usize] = node;
} }
} }
poison.check()?; poison.check()?;
} }

@ -11,10 +11,10 @@ use std::collections::{BTreeMap, BTreeSet, VecDeque};
use miette::Result; use miette::Result;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload, NodeNotFoundError};
use crate::data::expr::{eval_bytecode_pred, Expr}; use crate::data::expr::{eval_bytecode_pred, Expr};
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload, NodeNotFoundError};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;
@ -79,7 +79,12 @@ impl FixedRule for Bfs {
})?? })??
}; };
if eval_bytecode_pred(&condition_bytecode, &cand_tuple, &mut stack, condition_span)? { if eval_bytecode_pred(
&condition_bytecode,
&cand_tuple,
&mut stack,
condition_span,
)? {
found.push((starting_node.clone(), to_node.clone())); found.push((starting_node.clone(), to_node.clone()));
if found.len() >= limit { if found.len() >= limit {
break 'outer; break 'outer;

@ -11,10 +11,10 @@ use std::collections::BTreeMap;
use miette::Result; use miette::Result;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;

@ -6,9 +6,9 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use std::cmp::Reverse; use std::cmp::Reverse;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use itertools::Itertools; use itertools::Itertools;
use miette::Result; use miette::Result;
@ -16,10 +16,10 @@ use ordered_float::OrderedFloat;
use priority_queue::PriorityQueue; use priority_queue::PriorityQueue;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;

@ -16,13 +16,13 @@ pub(crate) mod label_propagation;
pub(crate) mod louvain; pub(crate) mod louvain;
pub(crate) mod pagerank; pub(crate) mod pagerank;
pub(crate) mod prim; pub(crate) mod prim;
pub(crate) mod random_walk;
pub(crate) mod shortest_path_bfs;
pub(crate) mod shortest_path_dijkstra; pub(crate) mod shortest_path_dijkstra;
pub(crate) mod strongly_connected_components; pub(crate) mod strongly_connected_components;
pub(crate) mod top_sort; pub(crate) mod top_sort;
pub(crate) mod triangles; pub(crate) mod triangles;
pub(crate) mod yen; pub(crate) mod yen;
pub(crate) mod shortest_path_bfs;
pub(crate) mod random_walk;
pub(crate) use all_pairs_shortest_path::{BetweennessCentrality, ClosenessCentrality}; pub(crate) use all_pairs_shortest_path::{BetweennessCentrality, ClosenessCentrality};
pub(crate) use astar::ShortestPathAStar; pub(crate) use astar::ShortestPathAStar;
@ -34,10 +34,10 @@ pub(crate) use label_propagation::LabelPropagation;
pub(crate) use louvain::CommunityDetectionLouvain; pub(crate) use louvain::CommunityDetectionLouvain;
pub(crate) use pagerank::PageRank; pub(crate) use pagerank::PageRank;
pub(crate) use prim::MinimumSpanningTreePrim; pub(crate) use prim::MinimumSpanningTreePrim;
pub(crate) use random_walk::RandomWalk;
pub(crate) use shortest_path_bfs::ShortestPathBFS;
pub(crate) use shortest_path_dijkstra::ShortestPathDijkstra; pub(crate) use shortest_path_dijkstra::ShortestPathDijkstra;
pub(crate) use strongly_connected_components::StronglyConnectedComponent; pub(crate) use strongly_connected_components::StronglyConnectedComponent;
pub(crate) use top_sort::TopSort; pub(crate) use top_sort::TopSort;
pub(crate) use triangles::ClusteringCoefficients; pub(crate) use triangles::ClusteringCoefficients;
pub(crate) use yen::KShortestPathYen; pub(crate) use yen::KShortestPathYen;
pub(crate) use shortest_path_bfs::ShortestPathBFS;
pub(crate) use random_walk::RandomWalk;

@ -41,7 +41,7 @@ impl FixedRule for PageRank {
let (graph, indices, _) = edges.as_directed_graph(undirected)?; let (graph, indices, _) = edges.as_directed_graph(undirected)?;
if indices.is_empty() { if indices.is_empty() {
return Ok(()) return Ok(());
} }
let (ranks, _n_run, _) = page_rank( let (ranks, _n_run, _) = page_rank(

@ -6,9 +6,9 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use std::cmp::Reverse; use std::cmp::Reverse;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use miette::Diagnostic; use miette::Diagnostic;
use miette::Result; use miette::Result;
@ -17,10 +17,10 @@ use priority_queue::PriorityQueue;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use thiserror::Error; use thiserror::Error;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;

@ -14,10 +14,10 @@ use rand::distributions::WeightedIndex;
use rand::prelude::*; use rand::prelude::*;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload, BadExprValueError, NodeNotFoundError};
use crate::data::expr::{eval_bytecode, Expr}; use crate::data::expr::{eval_bytecode, Expr};
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{BadExprValueError, FixedRule, FixedRulePayload, NodeNotFoundError};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;

@ -6,10 +6,10 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use std::cmp::{Ordering, Reverse}; use std::cmp::{Ordering, Reverse};
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use std::iter; use std::iter;
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use itertools::Itertools; use itertools::Itertools;
use miette::Result; use miette::Result;
@ -19,10 +19,10 @@ use rayon::prelude::*;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;
@ -42,8 +42,7 @@ impl FixedRule for ShortestPathDijkstra {
let undirected = payload.bool_option("undirected", Some(false))?; let undirected = payload.bool_option("undirected", Some(false))?;
let keep_ties = payload.bool_option("keep_ties", Some(false))?; let keep_ties = payload.bool_option("keep_ties", Some(false))?;
let (graph, indices, inv_indices) = let (graph, indices, inv_indices) = edges.as_directed_weighted_graph(undirected, false)?;
edges.as_directed_weighted_graph(undirected, false)?;
let mut starting_nodes = BTreeSet::new(); let mut starting_nodes = BTreeSet::new();
for tuple in starting.iter()? { for tuple in starting.iter()? {
@ -91,7 +90,11 @@ impl FixedRule for ShortestPathDijkstra {
indices[start as usize].clone(), indices[start as usize].clone(),
indices[target as usize].clone(), indices[target as usize].clone(),
DataValue::from(cost as f64), DataValue::from(cost as f64),
DataValue::List(path.into_iter().map(|u| indices[u as usize].clone()).collect_vec()), DataValue::List(
path.into_iter()
.map(|u| indices[u as usize].clone())
.collect_vec(),
),
]; ];
out.put(t) out.put(t)
} }
@ -135,7 +138,11 @@ impl FixedRule for ShortestPathDijkstra {
indices[start as usize].clone(), indices[start as usize].clone(),
indices[target as usize].clone(), indices[target as usize].clone(),
DataValue::from(cost as f64), DataValue::from(cost as f64),
DataValue::List(path.into_iter().map(|u| indices[u as usize].clone()).collect_vec()), DataValue::List(
path.into_iter()
.map(|u| indices[u as usize].clone())
.collect_vec(),
),
]; ];
out.put(t) out.put(t)
} }
@ -284,7 +291,7 @@ pub(crate) fn dijkstra<FE: ForbiddenEdge, FN: ForbiddenNode, G: Goal + Clone>(
continue; continue;
} }
for target in edges.out_neighbors_with_values(node) { for target in edges.out_neighbors_with_values(node) {
let nxt_node = target.target; let nxt_node = target.target;
let path_weight = target.value; let path_weight = target.value;

@ -7,20 +7,20 @@
*/ */
#![allow(unused_imports)] #![allow(unused_imports)]
use graph::prelude::{DirectedCsrGraph, DirectedNeighbors, Graph};
use std::cmp::min; use std::cmp::min;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use graph::prelude::{DirectedCsrGraph, DirectedNeighbors, Graph};
use itertools::Itertools; use itertools::Itertools;
use miette::Result; use miette::Result;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::program::{MagicFixedRuleApply, MagicSymbol}; use crate::data::program::{MagicFixedRuleApply, MagicSymbol};
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::tuple::Tuple; use crate::data::tuple::Tuple;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::{EpochStore, RegularTempStore}; use crate::runtime::temp_store::{EpochStore, RegularTempStore};
@ -47,8 +47,7 @@ impl FixedRule for StronglyConnectedComponent {
) -> Result<()> { ) -> Result<()> {
let edges = payload.get_input(0)?; let edges = payload.get_input(0)?;
let (graph, indices, mut inv_indices) = let (graph, indices, mut inv_indices) = edges.as_directed_graph(!self.strong)?;
edges.as_directed_graph(!self.strong)?;
let tarjan = TarjanSccG::new(graph).run(poison)?; let tarjan = TarjanSccG::new(graph).run(poison)?;
for (grp_id, cc) in tarjan.iter().enumerate() { for (grp_id, cc) in tarjan.iter().enumerate() {
@ -87,7 +86,6 @@ impl FixedRule for StronglyConnectedComponent {
} }
} }
pub(crate) struct TarjanSccG { pub(crate) struct TarjanSccG {
graph: DirectedCsrGraph<u32>, graph: DirectedCsrGraph<u32>,
id: u32, id: u32,
@ -97,7 +95,6 @@ pub(crate) struct TarjanSccG {
stack: Vec<u32>, stack: Vec<u32>,
} }
impl TarjanSccG { impl TarjanSccG {
pub(crate) fn new(graph: DirectedCsrGraph<u32>) -> Self { pub(crate) fn new(graph: DirectedCsrGraph<u32>) -> Self {
let graph_size = graph.node_count(); let graph_size = graph.node_count();
@ -150,4 +147,3 @@ impl TarjanSccG {
} }
} }
} }

@ -6,16 +6,16 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use std::collections::BTreeMap;
use graph::prelude::{DirectedCsrGraph, DirectedNeighbors, Graph}; use graph::prelude::{DirectedCsrGraph, DirectedNeighbors, Graph};
use std::collections::BTreeMap;
use miette::Result; use miette::Result;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;
@ -54,7 +54,6 @@ impl FixedRule for TopSort {
} }
} }
pub(crate) fn kahn_g(graph: &DirectedCsrGraph<u32>, poison: Poison) -> Result<Vec<u32>> { pub(crate) fn kahn_g(graph: &DirectedCsrGraph<u32>, poison: Poison) -> Result<Vec<u32>> {
let graph_size = graph.node_count(); let graph_size = graph.node_count();
let mut in_degree = vec![0; graph_size as usize]; let mut in_degree = vec![0; graph_size as usize];

@ -102,7 +102,11 @@ impl FixedRule for KShortestPathYen {
indices[start as usize].clone(), indices[start as usize].clone(),
indices[goal as usize].clone(), indices[goal as usize].clone(),
DataValue::from(cost as f64), DataValue::from(cost as f64),
DataValue::List(path.into_iter().map(|u| indices[u as usize].clone()).collect_vec()), DataValue::List(
path.into_iter()
.map(|u| indices[u as usize].clone())
.collect_vec(),
),
]; ];
out.put(t) out.put(t)
} }

@ -566,7 +566,12 @@ pub trait FixedRule: Send + Sync {
/// but implementation is simpler. /// but implementation is simpler.
pub struct SimpleFixedRule { pub struct SimpleFixedRule {
return_arity: usize, return_arity: usize,
rule: Box<dyn Fn(Vec<NamedRows>, BTreeMap<String, DataValue>) -> Result<NamedRows> + Send + Sync + 'static>, rule: Box<
dyn Fn(Vec<NamedRows>, BTreeMap<String, DataValue>) -> Result<NamedRows>
+ Send
+ Sync
+ 'static,
>,
} }
impl SimpleFixedRule { impl SimpleFixedRule {
@ -580,7 +585,10 @@ impl SimpleFixedRule {
// Every row of the returned relation must have length equal to `return_arity`. // Every row of the returned relation must have length equal to `return_arity`.
pub fn new<R>(return_arity: usize, rule: R) -> Self pub fn new<R>(return_arity: usize, rule: R) -> Self
where where
R: Fn(Vec<NamedRows>, BTreeMap<String, DataValue>) -> Result<NamedRows> + Send + Sync + 'static, R: Fn(Vec<NamedRows>, BTreeMap<String, DataValue>) -> Result<NamedRows>
+ Send
+ Sync
+ 'static,
{ {
Self { Self {
return_arity, return_arity,
@ -592,7 +600,11 @@ impl SimpleFixedRule {
return_arity: usize, return_arity: usize,
) -> ( ) -> (
Self, Self,
Receiver<(Vec<NamedRows>, BTreeMap<String, DataValue>, Sender<Result<NamedRows>>)>, Receiver<(
Vec<NamedRows>,
BTreeMap<String, DataValue>,
Sender<Result<NamedRows>>,
)>,
) { ) {
let (db2app_sender, db2app_receiver) = bounded(0); let (db2app_sender, db2app_receiver) = bounded(0);
( (

@ -12,11 +12,11 @@ use miette::{bail, ensure, Diagnostic, Result};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use thiserror::Error; use thiserror::Error;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::program::WrongFixedRuleOptionError; use crate::data::program::WrongFixedRuleOptionError;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;
@ -76,12 +76,14 @@ impl FixedRule for Constant {
options: &mut BTreeMap<SmartString<LazyCompact>, Expr>, options: &mut BTreeMap<SmartString<LazyCompact>, Expr>,
span: SourceSpan, span: SourceSpan,
) -> Result<()> { ) -> Result<()> {
let data = options.get("data").ok_or_else(|| WrongFixedRuleOptionError { let data = options
name: "data".to_string(), .get("data")
span: Default::default(), .ok_or_else(|| WrongFixedRuleOptionError {
rule_name: "Constant".to_string(), name: "data".to_string(),
help: "a list of lists is required".to_string(), span: Default::default(),
})?; rule_name: "Constant".to_string(),
help: "a list of lists is required".to_string(),
})?;
let data = match data.clone().eval_to_const()? { let data = match data.clone().eval_to_const()? {
DataValue::List(l) => l, DataValue::List(l) => l,
_ => bail!(WrongFixedRuleOptionError { _ => bail!(WrongFixedRuleOptionError {

@ -12,15 +12,15 @@ use csv::StringRecord;
use miette::{bail, ensure, IntoDiagnostic, Result}; use miette::{bail, ensure, IntoDiagnostic, Result};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
#[cfg(feature = "requests")]
use crate::fixed_rule::utilities::jlines::get_file_content_from_url;
use crate::fixed_rule::{FixedRule, FixedRulePayload, CannotDetermineArity};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::functions::{op_to_float, op_to_uuid, TERMINAL_VALIDITY}; use crate::data::functions::{op_to_float, op_to_uuid, TERMINAL_VALIDITY};
use crate::data::program::{FixedRuleOptionNotFoundError, WrongFixedRuleOptionError}; use crate::data::program::{FixedRuleOptionNotFoundError, WrongFixedRuleOptionError};
use crate::data::relation::{ColType, NullableColType}; use crate::data::relation::{ColType, NullableColType};
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
#[cfg(feature = "requests")]
use crate::fixed_rule::utilities::jlines::get_file_content_from_url;
use crate::fixed_rule::{CannotDetermineArity, FixedRule, FixedRulePayload};
use crate::parse::{parse_type, SourceSpan}; use crate::parse::{parse_type, SourceSpan};
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;

@ -20,11 +20,11 @@ use minreq::Response;
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use thiserror::Error; use thiserror::Error;
use crate::fixed_rule::{FixedRule, FixedRulePayload, CannotDetermineArity};
use crate::data::expr::Expr; use crate::data::expr::Expr;
use crate::data::json::JsonValue; use crate::data::json::JsonValue;
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::fixed_rule::{CannotDetermineArity, FixedRule, FixedRulePayload};
use crate::parse::SourceSpan; use crate::parse::SourceSpan;
use crate::runtime::db::Poison; use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore; use crate::runtime::temp_store::RegularTempStore;

@ -11,7 +11,7 @@ pub(crate) mod csv;
pub(crate) mod jlines; pub(crate) mod jlines;
pub(crate) mod reorder_sort; pub(crate) mod reorder_sort;
pub(crate) use constant::Constant;
pub(crate) use self::csv::CsvReader; pub(crate) use self::csv::CsvReader;
pub(crate) use constant::Constant;
pub(crate) use jlines::JsonReader; pub(crate) use jlines::JsonReader;
pub(crate) use reorder_sort::ReorderSort; pub(crate) use reorder_sort::ReorderSort;

@ -15,7 +15,7 @@ use pest::pratt_parser::{Op, PrattParser};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
use thiserror::Error; use thiserror::Error;
use crate::data::expr::{get_op, Expr, Bytecode}; use crate::data::expr::{get_op, Bytecode, Expr};
use crate::data::functions::{ use crate::data::functions::{
OP_ADD, OP_AND, OP_COALESCE, OP_CONCAT, OP_DIV, OP_EQ, OP_GE, OP_GT, OP_LE, OP_LIST, OP_LT, OP_ADD, OP_AND, OP_COALESCE, OP_CONCAT, OP_DIV, OP_EQ, OP_GE, OP_GT, OP_LE, OP_LIST, OP_LT,
OP_MINUS, OP_MOD, OP_MUL, OP_NEGATE, OP_NEQ, OP_OR, OP_POW, OP_SUB, OP_MINUS, OP_MOD, OP_MUL, OP_NEGATE, OP_NEQ, OP_OR, OP_POW, OP_SUB,
@ -55,14 +55,24 @@ pub(crate) struct InvalidExpression(#[label] pub(crate) SourceSpan);
pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec<Bytecode>) { pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec<Bytecode>) {
match expr { match expr {
Expr::Binding { var, tuple_pos } => collector.push(Bytecode::Binding { var: var.clone(), tuple_pos: *tuple_pos }), Expr::Binding { var, tuple_pos } => collector.push(Bytecode::Binding {
Expr::Const { val, span } => collector.push(Bytecode::Const { val: val.clone(), span: *span }), var: var.clone(),
tuple_pos: *tuple_pos,
}),
Expr::Const { val, span } => collector.push(Bytecode::Const {
val: val.clone(),
span: *span,
}),
Expr::Apply { op, args, span } => { Expr::Apply { op, args, span } => {
let arity = args.len(); let arity = args.len();
for arg in args.iter() { for arg in args.iter() {
expr2bytecode(arg, collector); expr2bytecode(arg, collector);
} }
collector.push(Bytecode::Apply { op, arity, span: *span }) collector.push(Bytecode::Apply {
op,
arity,
span: *span,
})
} }
Expr::Cond { clauses, span } => { Expr::Cond { clauses, span } => {
let mut return_jump_pos = vec![]; let mut return_jump_pos = vec![];
@ -70,11 +80,17 @@ pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec<Bytecode>) {
// +1 // +1
expr2bytecode(cond, collector); expr2bytecode(cond, collector);
// -1 // -1
collector.push(Bytecode::JumpIfFalse { jump_to: 0, span: *span }); collector.push(Bytecode::JumpIfFalse {
jump_to: 0,
span: *span,
});
let false_jump_amend_pos = collector.len() - 1; let false_jump_amend_pos = collector.len() - 1;
// +1 in this branch // +1 in this branch
expr2bytecode(val, collector); expr2bytecode(val, collector);
collector.push(Bytecode::Goto { jump_to: 0, span: *span }); collector.push(Bytecode::Goto {
jump_to: 0,
span: *span,
});
return_jump_pos.push(collector.len() - 1); return_jump_pos.push(collector.len() - 1);
collector[false_jump_amend_pos] = Bytecode::JumpIfFalse { collector[false_jump_amend_pos] = Bytecode::JumpIfFalse {
jump_to: collector.len(), jump_to: collector.len(),
@ -83,7 +99,10 @@ pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec<Bytecode>) {
} }
let total_len = collector.len(); let total_len = collector.len();
for pos in return_jump_pos { for pos in return_jump_pos {
collector[pos] = Bytecode::Goto { jump_to: total_len, span: *span } collector[pos] = Bytecode::Goto {
jump_to: total_len,
span: *span,
}
} }
} }
} }
@ -290,7 +309,10 @@ fn build_term(pair: Pair<'_>, param_pool: &BTreeMap<String, DataValue>) -> Resul
.collect_vec(); .collect_vec();
if let Some((cond, _)) = clauses.last() { if let Some((cond, _)) = clauses.last() {
match cond { match cond {
Expr::Const { val: DataValue::Bool(true), ..} => {} Expr::Const {
val: DataValue::Bool(true),
..
} => {}
_ => { _ => {
clauses.push(( clauses.push((
Expr::Const { Expr::Const {

@ -10,7 +10,7 @@ use std::collections::BTreeMap;
use std::sync::Arc; use std::sync::Arc;
use itertools::Itertools; use itertools::Itertools;
use miette::{miette, Diagnostic, Result, ensure}; use miette::{ensure, miette, Diagnostic, Result};
use thiserror::Error; use thiserror::Error;
use crate::data::program::InputProgram; use crate::data::program::InputProgram;
@ -160,7 +160,6 @@ pub(crate) fn parse_sys(
.map(|p| Symbol::new(p.as_str(), p.extract_span())) .map(|p| Symbol::new(p.as_str(), p.extract_span()))
.collect_vec(); .collect_vec();
#[derive(Debug, Diagnostic, Error)] #[derive(Debug, Diagnostic, Error)]
#[error("index must have at least one column specified")] #[error("index must have at least one column specified")]
#[diagnostic(code(parser::empty_index))] #[diagnostic(code(parser::empty_index))]
@ -182,7 +181,7 @@ pub(crate) fn parse_sys(
Symbol::new(name.as_str(), name.extract_span()), Symbol::new(name.as_str(), name.extract_span()),
) )
} }
_ => unreachable!() _ => unreachable!(),
} }
} }
Rule::list_fixed_rules => SysOp::ListFixedRules, Rule::list_fixed_rules => SysOp::ListFixedRules,

@ -99,7 +99,7 @@ impl InputAtom {
inner: Box::new(a), inner: Box::new(a),
span, span,
} }
.negation_normal_form() .negation_normal_form()
}) })
.try_collect()?, .try_collect()?,
span, span,
@ -113,7 +113,7 @@ impl InputAtom {
inner: Box::new(a), inner: Box::new(a),
span, span,
} }
.negation_normal_form() .negation_normal_form()
}) })
.try_collect()?, .try_collect()?,
span, span,
@ -172,7 +172,7 @@ impl InputAtom {
name, name,
args: new_args, args: new_args,
span, span,
valid_at valid_at,
}) })
} }

@ -11,8 +11,8 @@ pub(crate) mod eval;
pub(crate) mod graph; pub(crate) mod graph;
pub(crate) mod logical; pub(crate) mod logical;
pub(crate) mod magic; pub(crate) mod magic;
pub(crate) mod stored;
pub(crate) mod ra; pub(crate) mod ra;
pub(crate) mod reorder; pub(crate) mod reorder;
pub(crate) mod stratify;
pub(crate) mod sort; pub(crate) mod sort;
pub(crate) mod stored;
pub(crate) mod stratify;

@ -16,7 +16,7 @@ use log::{debug, error};
use miette::{bail, Diagnostic, Result}; use miette::{bail, Diagnostic, Result};
use thiserror::Error; use thiserror::Error;
use crate::data::expr::{compute_bounds, eval_bytecode, eval_bytecode_pred, Expr, Bytecode}; use crate::data::expr::{compute_bounds, eval_bytecode, eval_bytecode_pred, Bytecode, Expr};
use crate::data::program::MagicSymbol; use crate::data::program::MagicSymbol;
use crate::data::relation::{ColType, NullableColType}; use crate::data::relation::{ColType, NullableColType};
use crate::data::symb::Symbol; use crate::data::symb::Symbol;

@ -78,9 +78,13 @@ impl<'a> SessionTx<'a> {
replaced_old_triggers = Some((old_handle.put_triggers, old_handle.rm_triggers)) replaced_old_triggers = Some((old_handle.put_triggers, old_handle.rm_triggers))
} }
for trigger in &old_handle.replace_triggers { for trigger in &old_handle.replace_triggers {
let program = let program = parse_script(
parse_script(trigger, &Default::default(), &db.fixed_rules.read().unwrap(), cur_vld)? trigger,
.get_single_program()?; &Default::default(),
&db.fixed_rules.read().unwrap(),
cur_vld,
)?
.get_single_program()?;
let (_, cleanups) = db let (_, cleanups) = db
.run_query( .run_query(

@ -14,7 +14,7 @@ use miette::{ensure, Diagnostic, Result};
use thiserror::Error; use thiserror::Error;
use crate::data::program::{ use crate::data::program::{
FixedRuleArg, MagicSymbol, NormalFormRulesOrFixed, NormalFormAtom, NormalFormProgram, FixedRuleArg, MagicSymbol, NormalFormAtom, NormalFormProgram, NormalFormRulesOrFixed,
StratifiedNormalFormProgram, StratifiedNormalFormProgram,
}; };
use crate::data::symb::{Symbol, PROG_ENTRY}; use crate::data::symb::{Symbol, PROG_ENTRY};
@ -104,7 +104,9 @@ fn convert_normal_form_program_to_graph(
} }
} else { } else {
e.insert( e.insert(
found_key_is_fixed_rule || found_key_is_meet || is_negated, found_key_is_fixed_rule
|| found_key_is_meet
|| is_negated,
); );
} }
} }
@ -112,7 +114,9 @@ fn convert_normal_form_program_to_graph(
let old = *e.get(); let old = *e.get();
let new_val = if has_aggr { let new_val = if has_aggr {
if is_meet && k == found_key { if is_meet && k == found_key {
found_key_is_fixed_rule || found_key_is_meet || is_negated found_key_is_fixed_rule
|| found_key_is_meet
|| is_negated
} else { } else {
true true
} }

@ -37,7 +37,7 @@ impl CallbackOp {
pub fn as_str(&self) -> &'static str { pub fn as_str(&self) -> &'static str {
match self { match self {
CallbackOp::Put => "Put", CallbackOp::Put => "Put",
CallbackOp::Rm => "Rm" CallbackOp::Rm => "Rm",
} }
} }
} }

@ -85,32 +85,30 @@ impl<'s, S: Storage<'s>> Db<S> {
ImperativeStmt::Continue { target, span, .. } => { ImperativeStmt::Continue { target, span, .. } => {
return Ok(Right(ControlCode::Continue(target.clone(), *span))); return Ok(Right(ControlCode::Continue(target.clone(), *span)));
} }
ImperativeStmt::Return {returns} => { ImperativeStmt::Return { returns } => {
if returns.is_empty() { if returns.is_empty() {
return Ok(Right(ControlCode::Termination(NamedRows::default()))) return Ok(Right(ControlCode::Termination(NamedRows::default())));
} }
let mut current = None; let mut current = None;
for nxt in returns.iter().rev() { for nxt in returns.iter().rev() {
let mut nr = match nxt { let mut nr = match nxt {
Left(prog) => { Left(prog) => self.execute_single_program(
self.execute_single_program( prog.clone(),
prog.clone(), tx,
tx, cleanups,
cleanups, cur_vld,
cur_vld, callback_targets,
callback_targets, callback_collector,
callback_collector, )?,
)?
}
Right(rel) => { Right(rel) => {
let relation = tx.get_relation(rel, false)?; let relation = tx.get_relation(rel, false)?;
relation.as_named_rows(tx)? relation.as_named_rows(tx)?
} }
}; };
nr.next = current; nr.next = current;
current = Some(Box::new(nr)) current = Some(Box::new(nr))
} }
return Ok(Right(ControlCode::Termination(*current.unwrap()))) return Ok(Right(ControlCode::Termination(*current.unwrap())));
} }
ImperativeStmt::TempDebug { temp, .. } => { ImperativeStmt::TempDebug { temp, .. } => {
let relation = tx.get_relation(temp, false)?; let relation = tx.get_relation(temp, false)?;

@ -6,11 +6,11 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
pub(crate) mod callback;
pub(crate) mod db; pub(crate) mod db;
pub(crate) mod transact; pub(crate) mod imperative;
pub(crate) mod relation; pub(crate) mod relation;
pub(crate) mod temp_store; pub(crate) mod temp_store;
pub(crate) mod callback;
pub(crate) mod imperative;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub(crate) mod transact;

@ -6,6 +6,7 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use crossbeam::sync::{ShardedLock, ShardedLockReadGuard, ShardedLockWriteGuard};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::btree_map::Range; use std::collections::btree_map::Range;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -13,8 +14,7 @@ use std::default::Default;
use std::iter::Fuse; use std::iter::Fuse;
use std::mem; use std::mem;
use std::ops::Bound; use std::ops::Bound;
use std::sync::{Arc}; use std::sync::Arc;
use crossbeam::sync::{ShardedLock, ShardedLockReadGuard, ShardedLockWriteGuard};
use itertools::Itertools; use itertools::Itertools;
use miette::{bail, Result}; use miette::{bail, Result};

@ -20,9 +20,9 @@ pub(crate) mod rocks;
pub(crate) mod sled; pub(crate) mod sled;
#[cfg(feature = "storage-sqlite")] #[cfg(feature = "storage-sqlite")]
pub(crate) mod sqlite; pub(crate) mod sqlite;
pub(crate) mod temp;
#[cfg(feature = "storage-tikv")] #[cfg(feature = "storage-tikv")]
pub(crate) mod tikv; pub(crate) mod tikv;
pub(crate) mod temp;
// pub(crate) mod re; // pub(crate) mod re;
/// Swappable storage trait for Cozo's storage engine /// Swappable storage trait for Cozo's storage engine

@ -24,13 +24,15 @@ fn main() {
.with_autogen_warning( .with_autogen_warning(
"/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */", "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */",
) )
.with_header(r#"/* .with_header(
r#"/*
Copyright 2022, The Cozo Project Authors. Copyright 2022, The Cozo Project Authors.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/. You can obtain one at https://mozilla.org/MPL/2.0/.
*/"#) */"#,
)
.with_documentation(true) .with_documentation(true)
.generate() .generate()
.expect("Unable to generate bindings") .expect("Unable to generate bindings")

@ -6,9 +6,9 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use std::env::var;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::{env, fs, process::Command}; use std::{env, fs, process::Command};
use std::env::var;
fn main() { fn main() {
let target = env::var("TARGET").unwrap(); let target = env::var("TARGET").unwrap();
@ -82,8 +82,6 @@ fn main() {
println!("cargo:rerun-if-changed=bridge/tx.h"); println!("cargo:rerun-if-changed=bridge/tx.h");
println!("cargo:rerun-if-changed=bridge/tx.cpp"); println!("cargo:rerun-if-changed=bridge/tx.cpp");
if !Path::new("rocksdb/AUTHORS").exists() { if !Path::new("rocksdb/AUTHORS").exists() {
update_submodules(); update_submodules();
} }
@ -126,9 +124,7 @@ fn link(name: &str, bundled: bool) {
fn fail_on_empty_directory(name: &str) { fn fail_on_empty_directory(name: &str) {
if fs::read_dir(name).unwrap().count() == 0 { if fs::read_dir(name).unwrap().count() == 0 {
println!( println!("The `{name}` directory is empty, did you forget to pull the submodules?");
"The `{name}` directory is empty, did you forget to pull the submodules?"
);
println!("Try `git submodule update --init --recursive`"); println!("Try `git submodule update --init --recursive`");
panic!(); panic!();
} }

@ -6,7 +6,6 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use cxx::UniquePtr; use cxx::UniquePtr;
use crate::bridge::ffi::*; use crate::bridge::ffi::*;

@ -122,23 +122,10 @@ pub(crate) mod ffi {
type RocksDbBridge; type RocksDbBridge;
fn get_db_path(self: &RocksDbBridge) -> &CxxString; fn get_db_path(self: &RocksDbBridge) -> &CxxString;
fn open_db( fn open_db(builder: &DbOpts, status: &mut RocksDbStatus) -> UniquePtr<RocksDbBridge>;
builder: &DbOpts,
status: &mut RocksDbStatus,
) -> UniquePtr<RocksDbBridge>;
fn transact(self: &RocksDbBridge) -> UniquePtr<TxBridge>; fn transact(self: &RocksDbBridge) -> UniquePtr<TxBridge>;
fn del_range( fn del_range(self: &RocksDbBridge, lower: &[u8], upper: &[u8], status: &mut RocksDbStatus);
self: &RocksDbBridge, fn put(self: &RocksDbBridge, key: &[u8], val: &[u8], status: &mut RocksDbStatus);
lower: &[u8],
upper: &[u8],
status: &mut RocksDbStatus,
);
fn put(
self: &RocksDbBridge,
key: &[u8],
val: &[u8],
status: &mut RocksDbStatus,
);
fn compact_range( fn compact_range(
self: &RocksDbBridge, self: &RocksDbBridge,
lower: &[u8], lower: &[u8],
@ -175,18 +162,8 @@ pub(crate) mod ffi {
for_update: bool, for_update: bool,
status: &mut RocksDbStatus, status: &mut RocksDbStatus,
) -> UniquePtr<PinnableSlice>; ) -> UniquePtr<PinnableSlice>;
fn exists( fn exists(self: &TxBridge, key: &[u8], for_update: bool, status: &mut RocksDbStatus);
self: &TxBridge, fn put(self: &TxBridge, key: &[u8], val: &[u8], status: &mut RocksDbStatus);
key: &[u8],
for_update: bool,
status: &mut RocksDbStatus,
);
fn put(
self: &TxBridge,
key: &[u8],
val: &[u8],
status: &mut RocksDbStatus,
);
fn del(self: &TxBridge, key: &[u8], status: &mut RocksDbStatus); fn del(self: &TxBridge, key: &[u8], status: &mut RocksDbStatus);
fn commit(self: Pin<&mut TxBridge>, status: &mut RocksDbStatus); fn commit(self: Pin<&mut TxBridge>, status: &mut RocksDbStatus);
fn rollback(self: Pin<&mut TxBridge>, status: &mut RocksDbStatus); fn rollback(self: Pin<&mut TxBridge>, status: &mut RocksDbStatus);

@ -12,6 +12,7 @@ use std::fs;
use std::net::Ipv6Addr; use std::net::Ipv6Addr;
use std::process::exit; use std::process::exit;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc;
use clap::Parser; use clap::Parser;
use env_logger::Env; use env_logger::Env;
@ -77,12 +78,14 @@ fn main() {
eprintln!("{SECURITY_WARNING}"); eprintln!("{SECURITY_WARNING}");
} }
let db = DbInstance::new( let db = Arc::new(
args.engine.as_str(), DbInstance::new(
args.path.as_str(), args.engine.as_str(),
&args.config.clone(), args.path.as_str(),
) &args.config.clone(),
.unwrap(); )
.unwrap(),
);
if let Some(restore_path) = &args.restore { if let Some(restore_path) = &args.restore {
db.restore_backup(restore_path).unwrap(); db.restore_backup(restore_path).unwrap();
@ -114,7 +117,7 @@ fn main() {
} }
} }
fn server_main(args: Args, db: DbInstance) { fn server_main(args: Args, db: Arc<DbInstance>) {
let conf_path = format!("{}.{}.cozo_auth", args.path, args.engine); let conf_path = format!("{}.{}.cozo_auth", args.path, args.engine);
let auth_guard = match fs::read_to_string(&conf_path) { let auth_guard = match fs::read_to_string(&conf_path) {
Ok(s) => s.trim().to_string(), Ok(s) => s.trim().to_string(),

@ -12,6 +12,7 @@ use std::collections::BTreeMap;
use std::error::Error; use std::error::Error;
use std::fs::File; use std::fs::File;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::sync::Arc;
use miette::{bail, miette, IntoDiagnostic}; use miette::{bail, miette, IntoDiagnostic};
use serde_json::{json, Value}; use serde_json::{json, Value};
@ -57,7 +58,7 @@ impl rustyline::validate::Validator for Indented {
} }
} }
pub(crate) fn repl_main(db: DbInstance) -> Result<(), Box<dyn Error>> { pub(crate) fn repl_main(db: Arc<DbInstance>) -> Result<(), Box<dyn Error>> {
println!("Welcome to the Cozo REPL."); println!("Welcome to the Cozo REPL.");
println!("Type a space followed by newline to enter multiline mode."); println!("Type a space followed by newline to enter multiline mode.");

Loading…
Cancel
Save