disjunction

main
Ziyang Hu 2 years ago
parent 2aa470d0bb
commit c33722ffba

@ -3,9 +3,9 @@
* [x] predicates
* [x] negation
* [x] disjunction
* [ ] aggregation
* [ ] stratum
* [ ] magic sets
* [ ] aggregation
* [ ] function symbol
* [ ] arithmetic
* [ ] range scan

@ -91,9 +91,6 @@ impl EntityId {
pub(crate) const MAX_TEMP: EntityId = EntityId(10_000_000);
pub const MIN_PERM: EntityId = EntityId(10_000_001);
pub const MAX_PERM: EntityId = EntityId(0x00ff_ffff_ff00_0000);
pub(crate) fn is_zero(&self) -> bool {
self.0 == 0
}
pub(crate) fn from_bytes(b: &[u8]) -> Self {
EntityId(u64::from_be_bytes([

@ -10,9 +10,7 @@ use smallvec::SmallVec;
use smartstring::{LazyCompact, SmartString};
use uuid::Uuid;
use cozorocks::PinSlice;
use crate::data::encode::{decode_value, EncodedVec};
use crate::data::encode::EncodedVec;
use crate::data::id::{EntityId, TxId};
use crate::data::keyword::Keyword;
use crate::data::triple::StoreOp;
@ -63,9 +61,7 @@ impl Debug for DataValue {
DataValue::Bool(b) => {
write!(f, "{}", b)
}
DataValue::EnId(id) => {
id.fmt(f)
}
DataValue::EnId(id) => id.fmt(f),
DataValue::Int(i) => {
write!(f, "{}", i)
}
@ -87,11 +83,7 @@ impl Debug for DataValue {
DataValue::Bytes(b) => {
write!(f, "bytes(len={})", b.len())
}
DataValue::List(t) => {
f.debug_list()
.entries(t.iter())
.finish()
}
DataValue::List(t) => f.debug_list().entries(t.iter()).finish(),
DataValue::DescVal(v) => {
write!(f, "desc<{:?}>", v)
}
@ -128,16 +120,6 @@ impl DataValue {
}
}
pub(crate) struct PinSliceValue {
inner: PinSlice,
}
impl PinSliceValue {
pub(crate) fn as_value(&self) -> Result<DataValue> {
decode_value(&self.inner.as_ref()[1..])
}
}
#[cfg(test)]
mod tests {
use std::collections::{BTreeMap, HashMap};

@ -1,6 +1,5 @@
use std::collections::btree_map::Entry;
use std::collections::{BTreeMap, BTreeSet};
use std::iter;
use anyhow::Result;
use itertools::Itertools;
@ -236,7 +235,7 @@ impl SessionTx {
&mut self,
payload: &JsonValue,
default_vld: Validity,
) -> Result<impl Iterator<Item = (Keyword, Rule)>> {
) -> Result<Vec<(Keyword, Rule)>> {
let rule_name = payload.get("rule").ok_or_else(|| {
QueryCompilationError::UnexpectedForm(
payload.clone(),
@ -293,9 +292,6 @@ impl SessionTx {
.map(|el| self.parse_atom(el, default_vld))
.try_collect()?;
let rule_body = Self::reorder_rule_body_for_negations(rule_body)?;
let rule_body = Self::reorder_rule_body_for_predicates(rule_body)?;
if rule_head.len()
!= rule_head
.iter()
@ -308,19 +304,23 @@ impl SessionTx {
)
.into());
}
Ok(Atom::Conjunction(rule_body)
Atom::Conjunction(rule_body)
.disjunctive_normal_form()
.into_iter()
.map(move |rule_body| {
(
.map(move |rule_body| -> Result<(Keyword, Rule)> {
let rule_body = Self::reorder_rule_body_for_negations(rule_body)?;
let rule_body = Self::reorder_rule_body_for_predicates(rule_body)?;
Ok((
rule_name.clone(),
Rule {
head: rule_head.clone(),
body: rule_body,
vld,
},
)
}))
))
})
.try_collect()
}
fn reorder_rule_body_for_negations(clauses: Vec<Atom>) -> Result<Vec<Atom>> {

@ -84,18 +84,6 @@ impl<T> Term<T> {
Term::Const(_) => {}
}
}
pub(crate) fn get_var(&self) -> Option<&Keyword> {
match self {
Self::Var(k) => Some(k),
Self::Const(_) => None,
}
}
pub(crate) fn get_const(&self) -> Option<&T> {
match self {
Self::Const(v) => Some(v),
Self::Var(_) => None,
}
}
}
#[derive(Clone, Debug)]

@ -1,16 +1,8 @@
use anyhow::Result;
use itertools::Itertools;
use crate::data::expr::{get_op, Expr};
use crate::query::compile::Atom;
impl Atom {
pub(crate) fn is_disjunction(&self) -> bool {
matches!(self, Atom::Disjunction(_))
}
pub(crate) fn is_conjunction(&self) -> bool {
matches!(self, Atom::Conjunction(_))
}
pub(crate) fn negation_normal_form(self) -> Self {
match self {
a @ (Atom::AttrTriple(_) | Atom::Rule(_) | Atom::Predicate(_)) => a,

@ -143,7 +143,11 @@ fn creation() {
"rule": "?",
"args": [["?a"],
{"not_exists": ["?a", "person.last_name", "Goodman"]},
{"pred": "Neq", "args": ["?n", {"pred": "StrCat", "args": ["A", "l", "i", "c", "e"]}]},
{"disj": [
{"pred": "Eq", "args": ["?n", {"pred": "StrCat", "args": ["A", "l", "i", "c", "e"]}]},
{"pred": "Eq", "args": ["?n", "Bob"]},
{"pred": "Eq", "args": ["?n", 12345]},
]},
{"rule": "ff", "args": [{"person.id": "alice_amorist"}, "?a"]},
["?a", "person.first_name", "?n"]
]

Loading…
Cancel
Save