Bug fix: empty array on index (#3745)
This commit is contained in:
parent
2b4fb84511
commit
ab3582d057
2 changed files with 44 additions and 6 deletions
|
@ -132,11 +132,7 @@ impl Combinator {
|
|||
if !f {
|
||||
// Iterator for not flattened values
|
||||
if let Value::Array(v) = v {
|
||||
iterators.push(Box::new(MultiValuesIterator {
|
||||
vals: v.0,
|
||||
done: false,
|
||||
current: 0,
|
||||
}));
|
||||
iterators.push(Box::new(MultiValuesIterator::new(v.0)));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -182,6 +178,28 @@ struct MultiValuesIterator {
|
|||
vals: Vec<Value>,
|
||||
done: bool,
|
||||
current: usize,
|
||||
end: usize,
|
||||
}
|
||||
|
||||
impl MultiValuesIterator {
|
||||
fn new(vals: Vec<Value>) -> Self {
|
||||
let len = vals.len();
|
||||
if len == 0 {
|
||||
Self {
|
||||
vals,
|
||||
done: true,
|
||||
current: 0,
|
||||
end: 0,
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
vals,
|
||||
done: false,
|
||||
current: 0,
|
||||
end: len - 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ValuesIterator for MultiValuesIterator {
|
||||
|
@ -189,7 +207,7 @@ impl ValuesIterator for MultiValuesIterator {
|
|||
if self.done {
|
||||
return false;
|
||||
}
|
||||
if self.current == self.vals.len() - 1 {
|
||||
if self.current == self.end {
|
||||
self.done = true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2672,3 +2672,23 @@ async fn define_table_relation() -> Result<(), Error> {
|
|||
//
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn define_statement_index_empty_array() -> Result<(), Error> {
|
||||
let sql = r"
|
||||
DEFINE TABLE indexTest;
|
||||
INSERT INTO indexTest { arr: [] };
|
||||
DEFINE INDEX idx_arr ON TABLE indexTest COLUMNS arr;
|
||||
";
|
||||
let dbs = new_ds().await?;
|
||||
let ses = Session::owner().with_ns("test").with_db("test");
|
||||
let res = &mut dbs.execute(sql, &ses, None).await?;
|
||||
assert_eq!(res.len(), 3);
|
||||
//
|
||||
for _ in 0..3 {
|
||||
let tmp = res.remove(0).result;
|
||||
assert!(tmp.is_ok());
|
||||
}
|
||||
//
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue