Support of IN operator in the planner (#3640)
This commit is contained in:
parent
e637a538d2
commit
686a140d80
2 changed files with 60 additions and 6 deletions
|
@ -316,12 +316,11 @@ impl<'a> TreeBuilder<'a> {
|
||||||
(Operator::Contain, v, IdiomPosition::Left) => {
|
(Operator::Contain, v, IdiomPosition::Left) => {
|
||||||
Some(IndexOperator::Equality(v.clone()))
|
Some(IndexOperator::Equality(v.clone()))
|
||||||
}
|
}
|
||||||
(Operator::ContainAny, Value::Array(a), IdiomPosition::Left) => {
|
(
|
||||||
Some(IndexOperator::Union(a.clone()))
|
Operator::ContainAny | Operator::ContainAll | Operator::Inside,
|
||||||
}
|
Value::Array(a),
|
||||||
(Operator::ContainAll, Value::Array(a), IdiomPosition::Left) => {
|
IdiomPosition::Left,
|
||||||
Some(IndexOperator::Union(a.clone()))
|
) => Some(IndexOperator::Union(a.clone())),
|
||||||
}
|
|
||||||
(
|
(
|
||||||
Operator::LessThan
|
Operator::LessThan
|
||||||
| Operator::LessThanOrEqual
|
| Operator::LessThanOrEqual
|
||||||
|
|
|
@ -1246,3 +1246,58 @@ async fn select_with_uuid_value() -> Result<(), Error> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn select_with_in_operator() -> Result<(), Error> {
|
||||||
|
let dbs = new_ds().await?;
|
||||||
|
let ses = Session::owner().with_ns("test").with_db("test");
|
||||||
|
|
||||||
|
let sql = "
|
||||||
|
DEFINE INDEX user_email_idx ON user FIELDS email;
|
||||||
|
CREATE user:1 CONTENT { email: 'a@b' };
|
||||||
|
CREATE user:2 CONTENT { email: 'c@d' };
|
||||||
|
SELECT * FROM user WHERE email IN ['a@b', 'e@f'] EXPLAIN;
|
||||||
|
SELECT * FROM user WHERE email INSIDE ['a@b', 'e@f'] EXPLAIN;
|
||||||
|
SELECT * FROM user WHERE email IN ['a@b', 'e@f'];
|
||||||
|
SELECT * FROM user WHERE email INSIDE ['a@b', 'e@f'];
|
||||||
|
";
|
||||||
|
let mut res = dbs.execute(&sql, &ses, None).await?;
|
||||||
|
|
||||||
|
assert_eq!(res.len(), 7);
|
||||||
|
skip_ok(&mut res, 3)?;
|
||||||
|
|
||||||
|
for _ in 0..2 {
|
||||||
|
let tmp = res.remove(0).result?;
|
||||||
|
let val = Value::parse(
|
||||||
|
r#"[
|
||||||
|
{
|
||||||
|
detail: {
|
||||||
|
plan: {
|
||||||
|
index: 'user_email_idx',
|
||||||
|
operator: 'union',
|
||||||
|
value: ['a@b', 'e@f']
|
||||||
|
},
|
||||||
|
table: 'user'
|
||||||
|
},
|
||||||
|
operation: 'Iterate Index'
|
||||||
|
}
|
||||||
|
]"#,
|
||||||
|
);
|
||||||
|
assert_eq!(format!("{:#}", tmp), format!("{:#}", val));
|
||||||
|
}
|
||||||
|
|
||||||
|
for _ in 0..2 {
|
||||||
|
let tmp = res.remove(0).result?;
|
||||||
|
let val = Value::parse(
|
||||||
|
r#"[
|
||||||
|
{
|
||||||
|
'id': user:1,
|
||||||
|
'email': 'a@b'
|
||||||
|
}
|
||||||
|
]"#,
|
||||||
|
);
|
||||||
|
assert_eq!(format!("{:#}", tmp), format!("{:#}", val));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue