Compare commits
1 commit
master
...
rnewman/tx
Author | SHA1 | Date | |
---|---|---|---|
|
11b11533c0 |
3 changed files with 59 additions and 6 deletions
|
@ -33,6 +33,7 @@ use types::{
|
||||||
ColumnConstraint,
|
ColumnConstraint,
|
||||||
EmptyBecause,
|
EmptyBecause,
|
||||||
Inequality,
|
Inequality,
|
||||||
|
QueryValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
use Known;
|
use Known;
|
||||||
|
@ -150,16 +151,34 @@ impl ConjoiningClauses {
|
||||||
|
|
||||||
// These arguments must be variables or instant/numeric constants.
|
// These arguments must be variables or instant/numeric constants.
|
||||||
// TODO: static evaluation. #383.
|
// TODO: static evaluation. #383.
|
||||||
let constraint = ColumnConstraint::Inequality {
|
let constraint = comparison.to_constraint(left_v, right_v);
|
||||||
operator: comparison,
|
|
||||||
left: left_v,
|
|
||||||
right: right_v,
|
|
||||||
};
|
|
||||||
self.wheres.add_intersection(constraint);
|
self.wheres.add_intersection(constraint);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Inequality {
|
||||||
|
fn to_constraint(&self, left: QueryValue, right: QueryValue) -> ColumnConstraint {
|
||||||
|
match *self {
|
||||||
|
Inequality::TxAfter |
|
||||||
|
Inequality::TxBefore => {
|
||||||
|
// TODO: both ends of the range must be inside the tx partition!
|
||||||
|
// If we know the partition map -- and at this point we do, it's just
|
||||||
|
// not passed to this function -- then we can generate two constraints,
|
||||||
|
// or clamp a fixed value.
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnConstraint::Inequality {
|
||||||
|
operator: *self,
|
||||||
|
left: left,
|
||||||
|
right: right,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod testing {
|
mod testing {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -287,6 +287,10 @@ pub enum Inequality {
|
||||||
// Ref operators.
|
// Ref operators.
|
||||||
Unpermute,
|
Unpermute,
|
||||||
Differ,
|
Differ,
|
||||||
|
|
||||||
|
// Tx operators.
|
||||||
|
TxAfter,
|
||||||
|
TxBefore,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Inequality {
|
impl Inequality {
|
||||||
|
@ -301,6 +305,9 @@ impl Inequality {
|
||||||
|
|
||||||
Unpermute => "<",
|
Unpermute => "<",
|
||||||
Differ => "<>",
|
Differ => "<>",
|
||||||
|
|
||||||
|
TxAfter => ">",
|
||||||
|
TxBefore => "<",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,6 +321,9 @@ impl Inequality {
|
||||||
|
|
||||||
"unpermute" => Some(Inequality::Unpermute),
|
"unpermute" => Some(Inequality::Unpermute),
|
||||||
"differ" => Some(Inequality::Differ),
|
"differ" => Some(Inequality::Differ),
|
||||||
|
|
||||||
|
"tx-after" => Some(Inequality::TxAfter),
|
||||||
|
"tx-before" => Some(Inequality::TxBefore),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,7 +342,9 @@ impl Inequality {
|
||||||
ts
|
ts
|
||||||
},
|
},
|
||||||
&Unpermute |
|
&Unpermute |
|
||||||
&Differ => {
|
&Differ |
|
||||||
|
&TxAfter |
|
||||||
|
&TxBefore => {
|
||||||
ValueTypeSet::of_one(ValueType::Ref)
|
ValueTypeSet::of_one(ValueType::Ref)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -351,6 +363,9 @@ impl Debug for Inequality {
|
||||||
|
|
||||||
&Unpermute => "<",
|
&Unpermute => "<",
|
||||||
&Differ => "<>",
|
&Differ => "<>",
|
||||||
|
|
||||||
|
&TxAfter => ">",
|
||||||
|
&TxBefore => "<",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1115,3 +1115,22 @@ fn test_project_aggregates() {
|
||||||
WHERE `datoms00`.a = 99)");
|
WHERE `datoms00`.a = 99)");
|
||||||
assert_eq!(args, vec![]);
|
assert_eq!(args, vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tx_before_and_after() {
|
||||||
|
let schema = prepopulated_typed_schema(ValueType::Long);
|
||||||
|
let query = r#"[:find ?x :where [?x _ _ ?tx] [(tx-after ?tx 12345)]]"#;
|
||||||
|
let SQLQuery { sql, args } = translate(&schema, query);
|
||||||
|
assert_eq!(sql, "SELECT DISTINCT \
|
||||||
|
`datoms00`.e AS `?x` \
|
||||||
|
FROM `datoms` AS `datoms00` \
|
||||||
|
WHERE `datoms00`.tx > 12345");
|
||||||
|
assert_eq!(args, vec![]);
|
||||||
|
let query = r#"[:find ?x :where [?x _ _ ?tx] [(tx-before ?tx 12345)]]"#;
|
||||||
|
let SQLQuery { sql, args } = translate(&schema, query);
|
||||||
|
assert_eq!(sql, "SELECT DISTINCT \
|
||||||
|
`datoms00`.e AS `?x` \
|
||||||
|
FROM `datoms` AS `datoms00` \
|
||||||
|
WHERE `datoms00`.tx < 12345");
|
||||||
|
assert_eq!(args, vec![]);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue