Remove faulty flatten (#4463)

This commit is contained in:
Micha de Vries 2024-08-05 19:06:54 +02:00 committed by GitHub
parent 6d2f4a9833
commit 36d83ebccf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 86 additions and 4 deletions

View file

@ -250,10 +250,20 @@ impl Value {
.run(|stk| stm.compute(stk, ctx, opt, None)) .run(|stk| stm.compute(stk, ctx, opt, None))
.await? .await?
.all(); .all();
stk.run(|stk| v.get(stk, ctx, opt, None, path.next())) let res = stk
.await? .run(|stk| v.get(stk, ctx, opt, None, path.next()))
.flatten() .await?;
.ok() // We only want to flatten the results if the next part
// is a graph part. Reason being that if we flatten fields,
// the results of those fields (which could be arrays) will
// be merged into each other. So [1, 2, 3], [4, 5, 6] would
// become [1, 2, 3, 4, 5, 6]. This slice access won't panic
// as we have already checked the length of the path.
Ok(if let Part::Graph(_) = path[1] {
res.flatten()
} else {
res
})
} }
} }
} }

View file

@ -1224,3 +1224,75 @@ async fn select_destructure() -> Result<(), Error> {
// //
Ok(()) Ok(())
} }
#[tokio::test]
async fn select_field_from_graph_no_flattening() -> Result<(), Error> {
let sql = "
CREATE a:1, a:2;
RELATE a:1->b:1->a:2 SET list = [1, 2, 3];
RELATE a:1->b:2->a:2 SET list = [4, 5, 6];
SELECT VALUE ->b.list FROM a:1;
";
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(), 4);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{ id: a:1 },
{ id: a:2 }
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: b:1,
in: a:1,
out: a:2,
list: [1, 2, 3]
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: b:2,
in: a:1,
out: a:2,
list: [4, 5, 6]
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
[
[
1,
2,
3
],
[
4,
5,
6
]
]
]",
);
assert_eq!(tmp, val);
//
Ok(())
}