From 1784a1202e75dd7d56639ad213a22daf3808cd84 Mon Sep 17 00:00:00 2001 From: Emmanuel Keller Date: Thu, 7 Mar 2024 16:45:05 +0000 Subject: [PATCH] Check that objects properties are recognized by the query planner (#3643) --- core/src/syn/v1/stmt/define/analyzer.rs | 7 ++--- core/src/syn/v1/stmt/define/database.rs | 7 ++--- core/src/syn/v1/stmt/define/function.rs | 4 +-- core/src/syn/v1/stmt/define/namespace.rs | 7 ++--- core/src/syn/v1/stmt/define/param.rs | 4 ++- core/src/syn/v1/stmt/define/scope.rs | 7 ++--- core/src/syn/v1/stmt/define/table.rs | 7 ++--- core/src/syn/v1/stmt/define/token.rs | 7 ++--- core/src/syn/v1/stmt/define/user.rs | 4 +-- lib/tests/planner.rs | 40 ++++++++++++++++-------- 10 files changed, 52 insertions(+), 42 deletions(-) diff --git a/core/src/syn/v1/stmt/define/analyzer.rs b/core/src/syn/v1/stmt/define/analyzer.rs index c74f8435..f3784449 100644 --- a/core/src/syn/v1/stmt/define/analyzer.rs +++ b/core/src/syn/v1/stmt/define/analyzer.rs @@ -10,10 +10,9 @@ use crate::sql::Ident; use crate::sql::{filter::Filter, statements::DefineAnalyzerStatement, Strand, Tokenizer}; #[cfg(feature = "sql2")] use nom::bytes::complete::tag; -use nom::{ - branch::alt, bytes::complete::tag_no_case, combinator::cut, combinator::opt, multi::many0, - sequence::tuple, -}; +use nom::{branch::alt, bytes::complete::tag_no_case, combinator::cut, multi::many0}; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn analyzer(i: &str) -> IResult<&str, DefineAnalyzerStatement> { let (i, _) = tag_no_case("ANALYZER")(i)?; diff --git a/core/src/syn/v1/stmt/define/database.rs b/core/src/syn/v1/stmt/define/database.rs index cd5f852a..55d33935 100644 --- a/core/src/syn/v1/stmt/define/database.rs +++ b/core/src/syn/v1/stmt/define/database.rs @@ -7,10 +7,9 @@ use super::super::super::{ IResult, }; use crate::sql::{statements::DefineDatabaseStatement, ChangeFeed, Strand}; -use nom::{ - branch::alt, bytes::complete::tag_no_case, combinator::cut, combinator::opt, multi::many0, - sequence::tuple, -}; +use nom::{branch::alt, bytes::complete::tag_no_case, combinator::cut, multi::many0}; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn database(i: &str) -> IResult<&str, DefineDatabaseStatement> { let (i, _) = alt((tag_no_case("DB"), tag_no_case("DATABASE")))(i)?; diff --git a/core/src/syn/v1/stmt/define/function.rs b/core/src/syn/v1/stmt/define/function.rs index e41bd4cb..68f94d54 100644 --- a/core/src/syn/v1/stmt/define/function.rs +++ b/core/src/syn/v1/stmt/define/function.rs @@ -15,10 +15,10 @@ use nom::{ bytes::complete::{tag, tag_no_case}, character::complete::char, combinator::cut, - combinator::opt, multi::many0, - sequence::tuple, }; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn function(i: &str) -> IResult<&str, DefineFunctionStatement> { let (i, _) = tag_no_case("FUNCTION")(i)?; diff --git a/core/src/syn/v1/stmt/define/namespace.rs b/core/src/syn/v1/stmt/define/namespace.rs index 22fb8ce3..f40365c7 100644 --- a/core/src/syn/v1/stmt/define/namespace.rs +++ b/core/src/syn/v1/stmt/define/namespace.rs @@ -6,10 +6,9 @@ use super::super::super::{ IResult, }; use crate::sql::{statements::DefineNamespaceStatement, Strand}; -use nom::{ - branch::alt, bytes::complete::tag_no_case, combinator::cut, combinator::opt, multi::many0, - sequence::tuple, -}; +use nom::{branch::alt, bytes::complete::tag_no_case, combinator::cut, multi::many0}; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn namespace(i: &str) -> IResult<&str, DefineNamespaceStatement> { let (i, _) = alt((tag_no_case("NS"), tag_no_case("NAMESPACE")))(i)?; diff --git a/core/src/syn/v1/stmt/define/param.rs b/core/src/syn/v1/stmt/define/param.rs index b4455856..c931c9b5 100644 --- a/core/src/syn/v1/stmt/define/param.rs +++ b/core/src/syn/v1/stmt/define/param.rs @@ -13,8 +13,10 @@ use crate::{ }; use nom::{ branch::alt, bytes::complete::tag_no_case, character::complete::char, combinator::cut, - combinator::opt, multi::many0, sequence::tuple, Err, + multi::many0, Err, }; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn param(i: &str) -> IResult<&str, DefineParamStatement> { let (i, _) = tag_no_case("PARAM")(i)?; diff --git a/core/src/syn/v1/stmt/define/scope.rs b/core/src/syn/v1/stmt/define/scope.rs index 3f62754a..d8ec395f 100644 --- a/core/src/syn/v1/stmt/define/scope.rs +++ b/core/src/syn/v1/stmt/define/scope.rs @@ -7,10 +7,9 @@ use super::super::super::{ IResult, }; use crate::sql::{statements::DefineScopeStatement, Duration, Strand, Value}; -use nom::{ - branch::alt, bytes::complete::tag_no_case, combinator::cut, combinator::opt, multi::many0, - sequence::tuple, -}; +use nom::{branch::alt, bytes::complete::tag_no_case, combinator::cut, multi::many0}; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn scope(i: &str) -> IResult<&str, DefineScopeStatement> { let (i, _) = tag_no_case("SCOPE")(i)?; diff --git a/core/src/syn/v1/stmt/define/table.rs b/core/src/syn/v1/stmt/define/table.rs index b82dc19c..61688084 100644 --- a/core/src/syn/v1/stmt/define/table.rs +++ b/core/src/syn/v1/stmt/define/table.rs @@ -9,10 +9,9 @@ use super::super::super::{ use crate::sql::{ statements::DefineTableStatement, ChangeFeed, Permission, Permissions, Strand, View, }; -use nom::{ - branch::alt, bytes::complete::tag_no_case, combinator::cut, combinator::opt, multi::many0, - sequence::tuple, -}; +use nom::{branch::alt, bytes::complete::tag_no_case, combinator::cut, multi::many0}; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn table(i: &str) -> IResult<&str, DefineTableStatement> { let (i, _) = tag_no_case("TABLE")(i)?; diff --git a/core/src/syn/v1/stmt/define/token.rs b/core/src/syn/v1/stmt/define/token.rs index 1e44c282..3fc38b3b 100644 --- a/core/src/syn/v1/stmt/define/token.rs +++ b/core/src/syn/v1/stmt/define/token.rs @@ -13,10 +13,9 @@ use crate::{ syn::v1::ParseError, }; use nom::Err; -use nom::{ - branch::alt, bytes::complete::tag_no_case, combinator::cut, combinator::opt, multi::many0, - sequence::tuple, -}; +use nom::{branch::alt, bytes::complete::tag_no_case, combinator::cut, multi::many0}; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn token(i: &str) -> IResult<&str, DefineTokenStatement> { let (i, _) = tag_no_case("TOKEN")(i)?; diff --git a/core/src/syn/v1/stmt/define/user.rs b/core/src/syn/v1/stmt/define/user.rs index 0b26dd02..057eb9fb 100644 --- a/core/src/syn/v1/stmt/define/user.rs +++ b/core/src/syn/v1/stmt/define/user.rs @@ -15,11 +15,11 @@ use nom::{ branch::alt, bytes::complete::tag_no_case, combinator::cut, - combinator::opt, multi::{many0, separated_list1}, - sequence::tuple, Err, }; +#[cfg(feature = "sql2")] +use nom::{combinator::opt, sequence::tuple}; pub fn user(i: &str) -> IResult<&str, DefineUserStatement> { let (i, _) = tag_no_case("USER")(i)?; diff --git a/lib/tests/planner.rs b/lib/tests/planner.rs index 80fa1557..f0d022fb 100644 --- a/lib/tests/planner.rs +++ b/lib/tests/planner.rs @@ -1147,6 +1147,9 @@ async fn select_unique_contains() -> Result<(), Error> { } #[tokio::test] +// This test checks that: +// 1. Datetime are recognized by the query planner +// 2. we can take the value store in a variable async fn select_with_datetime_value() -> Result<(), Error> { let dbs = new_ds().await?; let ses = Session::owner().with_ns("test").with_db("test"); @@ -1201,6 +1204,9 @@ async fn select_with_datetime_value() -> Result<(), Error> { } #[tokio::test] +// This test checks that: +// 1. UUID are recognized by the query planner +// 2. we can take the value from a object stored as a variable async fn select_with_uuid_value() -> Result<(), Error> { let dbs = new_ds().await?; let ses = Session::owner().with_ns("test").with_db("test"); @@ -1208,16 +1214,21 @@ async fn select_with_uuid_value() -> Result<(), Error> { let sql = " DEFINE INDEX sessionUid ON sessions FIELDS sessionUid; CREATE sessions:1 CONTENT { sessionUid: u'00ad70db-f435-442e-9012-1cd853102084' }; + LET $sess = { uuid: u'00ad70db-f435-442e-9012-1cd853102084' }; SELECT * FROM sessions WHERE sessionUid = u'00ad70db-f435-442e-9012-1cd853102084' EXPLAIN; - SELECT * FROM sessions WHERE sessionUid = u'00ad70db-f435-442e-9012-1cd853102084';"; + SELECT * FROM sessions WHERE sessionUid = $sess.uuid EXPLAIN; + SELECT * FROM sessions WHERE sessionUid = u'00ad70db-f435-442e-9012-1cd853102084'; + SELECT * FROM sessions WHERE sessionUid = $sess.uuid; + "; let mut res = dbs.execute(&sql, &ses, None).await?; - assert_eq!(res.len(), 4); - skip_ok(&mut res, 2)?; + assert_eq!(res.len(), 7); + skip_ok(&mut res, 3)?; - let tmp = res.remove(0).result?; - let val = Value::parse( - r#"[ + for _ in 0..2 { + let tmp = res.remove(0).result?; + let val = Value::parse( + r#"[ { detail: { plan: { @@ -1230,19 +1241,22 @@ async fn select_with_uuid_value() -> Result<(), Error> { operation: 'Iterate Index' } ]"#, - ); - assert_eq!(format!("{:#}", tmp), format!("{:#}", val)); + ); + assert_eq!(format!("{:#}", tmp), format!("{:#}", val)); + } - let tmp = res.remove(0).result?; - let val = Value::parse( - r#"[ + for _ in 0..2 { + let tmp = res.remove(0).result?; + let val = Value::parse( + r#"[ { "id": sessions:1, "sessionUid": "00ad70db-f435-442e-9012-1cd853102084" } ]"#, - ); - assert_eq!(format!("{:#}", tmp), format!("{:#}", val)); + ); + assert_eq!(format!("{:#}", tmp), format!("{:#}", val)); + } Ok(()) }