Bug fix: empty array on index (#3745)

This commit is contained in:
Emmanuel Keller 2024-03-21 17:08:20 +00:00 committed by GitHub
parent 2b4fb84511
commit ab3582d057
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 6 deletions

View file

@ -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;
}

View file

@ -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(())
}