formatting

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

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

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

@ -6,8 +6,8 @@
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use serde_json::json;
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::Object(d) => DataValue::List(
d.into_iter()
.map(|(k, v)| {
DataValue::List(
[DataValue::from(k), DataValue::from(v)].into(),
)
})
.map(|(k, v)| DataValue::List([DataValue::from(k), DataValue::from(v)].into()))
.collect(),
),
}

@ -6,17 +6,16 @@
* 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 expr;
pub(crate) mod functions;
pub(crate) mod relation;
pub(crate) mod json;
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)]
mod tests;

@ -6,20 +6,29 @@
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
use crate::{DataValue, new_cozo_mem};
use crate::{new_cozo_mem, DataValue};
#[test]
fn expression_eval() {
let db = new_cozo_mem().unwrap();
let res = db.run_script(r#"
let res = db
.run_script(
r#"
?[a] := a = if(2 + 3 > 1 * 99999, 190291021 + 14341234212 / 2121)
"#, Default::default()).unwrap();
"#,
Default::default(),
)
.unwrap();
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)
"#, Default::default()).unwrap();
"#,
Default::default(),
)
.unwrap();
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/.
*/
mod functions;
mod aggrs;
mod validity;
mod exprs;
mod functions;
mod json;
mod memcmp;
mod validity;
mod values;
mod exprs;

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

@ -6,12 +6,12 @@
* 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::collections::BTreeSet;
use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use ordered_float::OrderedFloat;
use regex::Regex;

@ -6,9 +6,9 @@
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use std::cmp::Reverse;
use std::collections::BTreeMap;
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use itertools::Itertools;
use miette::Result;
@ -17,11 +17,11 @@ use priority_queue::PriorityQueue;
use rayon::prelude::*;
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::symb::Symbol;
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::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore;
@ -38,8 +38,7 @@ impl FixedRule for BetweennessCentrality {
let edges = payload.get_input(0)?;
let undirected = payload.bool_option("undirected", Some(false))?;
let (graph, indices, _inv_indices) =
edges.as_directed_weighted_graph(undirected, false)?;
let (graph, indices, _inv_indices) = edges.as_directed_weighted_graph(undirected, false)?;
let n = graph.node_count();
if n == 0 {
@ -107,8 +106,7 @@ impl FixedRule for ClosenessCentrality {
let edges = payload.get_input(0)?;
let undirected = payload.bool_option("undirected", Some(false))?;
let (graph, indices, _inv_indices) =
edges.as_directed_weighted_graph(undirected, false)?;
let (graph, indices, _inv_indices) = edges.as_directed_weighted_graph(undirected, false)?;
let n = graph.node_count();
if n == 0 {
@ -125,7 +123,10 @@ impl FixedRule for ClosenessCentrality {
})
.collect::<Result<_>>()?;
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()?;
}
Ok(())
@ -167,7 +168,6 @@ pub(crate) fn dijkstra_cost_only(
distance[nxt_node as usize] = nxt_cost;
back_pointers[nxt_node as usize] = node;
}
}
poison.check()?;
}

@ -11,10 +11,10 @@ use std::collections::{BTreeMap, BTreeSet, VecDeque};
use miette::Result;
use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload, NodeNotFoundError};
use crate::data::expr::{eval_bytecode_pred, Expr};
use crate::data::symb::Symbol;
use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload, NodeNotFoundError};
use crate::parse::SourceSpan;
use crate::runtime::db::Poison;
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()));
if found.len() >= limit {
break 'outer;

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

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

@ -16,13 +16,13 @@ pub(crate) mod label_propagation;
pub(crate) mod louvain;
pub(crate) mod pagerank;
pub(crate) mod prim;
pub(crate) mod random_walk;
pub(crate) mod shortest_path_bfs;
pub(crate) mod shortest_path_dijkstra;
pub(crate) mod strongly_connected_components;
pub(crate) mod top_sort;
pub(crate) mod triangles;
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 astar::ShortestPathAStar;
@ -34,10 +34,10 @@ pub(crate) use label_propagation::LabelPropagation;
pub(crate) use louvain::CommunityDetectionLouvain;
pub(crate) use pagerank::PageRank;
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 strongly_connected_components::StronglyConnectedComponent;
pub(crate) use top_sort::TopSort;
pub(crate) use triangles::ClusteringCoefficients;
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)?;
if indices.is_empty() {
return Ok(())
return Ok(());
}
let (ranks, _n_run, _) = page_rank(

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

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

@ -6,10 +6,10 @@
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use std::cmp::{Ordering, Reverse};
use std::collections::{BTreeMap, BTreeSet};
use std::iter;
use graph::prelude::{DirectedCsrGraph, DirectedNeighborsWithValues, Graph};
use itertools::Itertools;
use miette::Result;
@ -19,10 +19,10 @@ use rayon::prelude::*;
use smallvec::{smallvec, SmallVec};
use smartstring::{LazyCompact, SmartString};
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr;
use crate::data::symb::Symbol;
use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan;
use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore;
@ -42,8 +42,7 @@ impl FixedRule for ShortestPathDijkstra {
let undirected = payload.bool_option("undirected", Some(false))?;
let keep_ties = payload.bool_option("keep_ties", Some(false))?;
let (graph, indices, inv_indices) =
edges.as_directed_weighted_graph(undirected, false)?;
let (graph, indices, inv_indices) = edges.as_directed_weighted_graph(undirected, false)?;
let mut starting_nodes = BTreeSet::new();
for tuple in starting.iter()? {
@ -91,7 +90,11 @@ impl FixedRule for ShortestPathDijkstra {
indices[start as usize].clone(),
indices[target as usize].clone(),
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)
}
@ -135,7 +138,11 @@ impl FixedRule for ShortestPathDijkstra {
indices[start as usize].clone(),
indices[target as usize].clone(),
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)
}

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

@ -102,7 +102,11 @@ impl FixedRule for KShortestPathYen {
indices[start as usize].clone(),
indices[goal as usize].clone(),
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)
}

@ -566,7 +566,12 @@ pub trait FixedRule: Send + Sync {
/// but implementation is simpler.
pub struct SimpleFixedRule {
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 {
@ -580,7 +585,10 @@ impl SimpleFixedRule {
// Every row of the returned relation must have length equal to `return_arity`.
pub fn new<R>(return_arity: usize, rule: R) -> Self
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 {
return_arity,
@ -592,7 +600,11 @@ impl SimpleFixedRule {
return_arity: usize,
) -> (
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);
(

@ -12,11 +12,11 @@ use miette::{bail, ensure, Diagnostic, Result};
use smartstring::{LazyCompact, SmartString};
use thiserror::Error;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::data::expr::Expr;
use crate::data::program::WrongFixedRuleOptionError;
use crate::data::symb::Symbol;
use crate::data::value::DataValue;
use crate::fixed_rule::{FixedRule, FixedRulePayload};
use crate::parse::SourceSpan;
use crate::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore;
@ -76,7 +76,9 @@ impl FixedRule for Constant {
options: &mut BTreeMap<SmartString<LazyCompact>, Expr>,
span: SourceSpan,
) -> Result<()> {
let data = options.get("data").ok_or_else(|| WrongFixedRuleOptionError {
let data = options
.get("data")
.ok_or_else(|| WrongFixedRuleOptionError {
name: "data".to_string(),
span: Default::default(),
rule_name: "Constant".to_string(),

@ -12,15 +12,15 @@ use csv::StringRecord;
use miette::{bail, ensure, IntoDiagnostic, Result};
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::functions::{op_to_float, op_to_uuid, TERMINAL_VALIDITY};
use crate::data::program::{FixedRuleOptionNotFoundError, WrongFixedRuleOptionError};
use crate::data::relation::{ColType, NullableColType};
use crate::data::symb::Symbol;
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::runtime::db::Poison;
use crate::runtime::temp_store::RegularTempStore;

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

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

@ -15,7 +15,7 @@ use pest::pratt_parser::{Op, PrattParser};
use smartstring::{LazyCompact, SmartString};
use thiserror::Error;
use crate::data::expr::{get_op, Expr, Bytecode};
use crate::data::expr::{get_op, Bytecode, Expr};
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_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>) {
match expr {
Expr::Binding { var, tuple_pos } => collector.push(Bytecode::Binding { var: var.clone(), tuple_pos: *tuple_pos }),
Expr::Const { val, span } => collector.push(Bytecode::Const { val: val.clone(), span: *span }),
Expr::Binding { var, tuple_pos } => collector.push(Bytecode::Binding {
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 } => {
let arity = args.len();
for arg in args.iter() {
expr2bytecode(arg, collector);
}
collector.push(Bytecode::Apply { op, arity, span: *span })
collector.push(Bytecode::Apply {
op,
arity,
span: *span,
})
}
Expr::Cond { clauses, span } => {
let mut return_jump_pos = vec![];
@ -70,11 +80,17 @@ pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec<Bytecode>) {
// +1
expr2bytecode(cond, collector);
// -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;
// +1 in this branch
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);
collector[false_jump_amend_pos] = Bytecode::JumpIfFalse {
jump_to: collector.len(),
@ -83,7 +99,10 @@ pub(crate) fn expr2bytecode(expr: &Expr, collector: &mut Vec<Bytecode>) {
}
let total_len = collector.len();
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();
if let Some((cond, _)) = clauses.last() {
match cond {
Expr::Const { val: DataValue::Bool(true), ..} => {}
Expr::Const {
val: DataValue::Bool(true),
..
} => {}
_ => {
clauses.push((
Expr::Const {

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

@ -172,7 +172,7 @@ impl InputAtom {
name,
args: new_args,
span,
valid_at
valid_at,
})
}

@ -11,8 +11,8 @@ pub(crate) mod eval;
pub(crate) mod graph;
pub(crate) mod logical;
pub(crate) mod magic;
pub(crate) mod stored;
pub(crate) mod ra;
pub(crate) mod reorder;
pub(crate) mod stratify;
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 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::relation::{ColType, NullableColType};
use crate::data::symb::Symbol;

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

@ -14,7 +14,7 @@ use miette::{ensure, Diagnostic, Result};
use thiserror::Error;
use crate::data::program::{
FixedRuleArg, MagicSymbol, NormalFormRulesOrFixed, NormalFormAtom, NormalFormProgram,
FixedRuleArg, MagicSymbol, NormalFormAtom, NormalFormProgram, NormalFormRulesOrFixed,
StratifiedNormalFormProgram,
};
use crate::data::symb::{Symbol, PROG_ENTRY};
@ -104,7 +104,9 @@ fn convert_normal_form_program_to_graph(
}
} else {
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 new_val = if has_aggr {
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 {
true
}

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

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

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

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

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

@ -24,13 +24,15 @@ fn main() {
.with_autogen_warning(
"/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */",
)
.with_header(r#"/*
.with_header(
r#"/*
Copyright 2022, The Cozo Project Authors.
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,
You can obtain one at https://mozilla.org/MPL/2.0/.
*/"#)
*/"#,
)
.with_documentation(true)
.generate()
.expect("Unable to generate bindings")

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

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

@ -122,23 +122,10 @@ pub(crate) mod ffi {
type RocksDbBridge;
fn get_db_path(self: &RocksDbBridge) -> &CxxString;
fn open_db(
builder: &DbOpts,
status: &mut RocksDbStatus,
) -> UniquePtr<RocksDbBridge>;
fn open_db(builder: &DbOpts, status: &mut RocksDbStatus) -> UniquePtr<RocksDbBridge>;
fn transact(self: &RocksDbBridge) -> UniquePtr<TxBridge>;
fn del_range(
self: &RocksDbBridge,
lower: &[u8],
upper: &[u8],
status: &mut RocksDbStatus,
);
fn put(
self: &RocksDbBridge,
key: &[u8],
val: &[u8],
status: &mut RocksDbStatus,
);
fn del_range(self: &RocksDbBridge, lower: &[u8], upper: &[u8], status: &mut RocksDbStatus);
fn put(self: &RocksDbBridge, key: &[u8], val: &[u8], status: &mut RocksDbStatus);
fn compact_range(
self: &RocksDbBridge,
lower: &[u8],
@ -175,18 +162,8 @@ pub(crate) mod ffi {
for_update: bool,
status: &mut RocksDbStatus,
) -> UniquePtr<PinnableSlice>;
fn exists(
self: &TxBridge,
key: &[u8],
for_update: bool,
status: &mut RocksDbStatus,
);
fn put(
self: &TxBridge,
key: &[u8],
val: &[u8],
status: &mut RocksDbStatus,
);
fn exists(self: &TxBridge, 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 commit(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::process::exit;
use std::str::FromStr;
use std::sync::Arc;
use clap::Parser;
use env_logger::Env;
@ -77,12 +78,14 @@ fn main() {
eprintln!("{SECURITY_WARNING}");
}
let db = DbInstance::new(
let db = Arc::new(
DbInstance::new(
args.engine.as_str(),
args.path.as_str(),
&args.config.clone(),
)
.unwrap();
.unwrap(),
);
if let Some(restore_path) = &args.restore {
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 auth_guard = match fs::read_to_string(&conf_path) {
Ok(s) => s.trim().to_string(),

@ -12,6 +12,7 @@ use std::collections::BTreeMap;
use std::error::Error;
use std::fs::File;
use std::io::{Read, Write};
use std::sync::Arc;
use miette::{bail, miette, IntoDiagnostic};
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!("Type a space followed by newline to enter multiline mode.");

Loading…
Cancel
Save