Bugfix: Compute futures in query conditions (#3118)

This commit is contained in:
Mees Delzenne 2023-12-19 10:17:48 +01:00 committed by GitHub
parent 2db5968d0a
commit 953e496e7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View file

@ -15,7 +15,11 @@ impl<'a> Document<'a> {
// Check where condition // Check where condition
if let Some(cond) = stm.conds() { if let Some(cond) = stm.conds() {
// Check if the expression is truthy // Check if the expression is truthy
if !cond.compute(ctx, opt, txn, Some(&self.current)).await?.is_truthy() { if !cond
.compute(ctx, &opt.new_with_futures(true), txn, Some(&self.current))
.await?
.is_truthy()
{
// Ignore this document // Ignore this document
return Err(Error::Ignore); return Err(Error::Ignore);
} }

View file

@ -161,7 +161,8 @@ impl<'a> Document<'a> {
// Check where condition // Check where condition
if let Some(cond) = stm.conds() { if let Some(cond) = stm.conds() {
// Check if the expression is truthy // Check if the expression is truthy
if !cond.compute(ctx, opt, txn, Some(doc)).await?.is_truthy() {
if !cond.compute(ctx, &opt.new_with_futures(true), txn, Some(doc)).await?.is_truthy() {
// Ignore this document // Ignore this document
return Err(Error::Ignore); return Err(Error::Ignore);
} }

View file

@ -1074,3 +1074,32 @@ async fn select_only() -> Result<(), Error> {
// //
Ok(()) Ok(())
} }
#[tokio::test]
async fn select_on_future() -> Result<(), Error> {
let insert_query = "
CREATE person SET name = \"Hana\", age = 10, can_drive = <future>{ age > 17 };
CREATE person SET name = \"Hendrick\", age = 18, can_drive = <future>{ age > 17 };
";
let dbs = new_ds().await?;
let ses = Session::owner().with_ns("test").with_db("test");
dbs.execute(insert_query, &ses, None).await?;
let select_query_true = "
SELECT name FROM person WHERE can_drive
";
let mut res = dbs.execute(select_query_true, &ses, None).await?;
let tmp = res.remove(0).result?;
let val = Value::parse("[{ name: \"Hendrick\" }]");
assert_eq!(tmp, val);
let select_query_false = "
SELECT name FROM person WHERE !can_drive
";
let mut res = dbs.execute(select_query_false, &ses, None).await?;
let tmp = res.remove(0).result?;
let val = Value::parse("[{ name: \"Hana\" }]");
assert_eq!(tmp, val);
Ok(())
}