From 4bd1185ff99a150fdad4efa90e021d6ef6ba8dea Mon Sep 17 00:00:00 2001 From: Micha de Vries Date: Sat, 20 Jul 2024 15:19:08 +0200 Subject: [PATCH] Fix querying complex edge table (#4391) --- core/src/dbs/processor.rs | 6 +++--- lib/tests/relate.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/core/src/dbs/processor.rs b/core/src/dbs/processor.rs index 003c4df2..86603919 100644 --- a/core/src/dbs/processor.rs +++ b/core/src/dbs/processor.rs @@ -427,7 +427,7 @@ impl<'a> Processor<'a> { Dir::In => e .what .iter() - .map(|v| v.to_string()) + .map(|v| v.0.to_owned()) .map(|v| { ( graph::ftprefix(ns, db, tb, id, &e.dir, &v), @@ -439,7 +439,7 @@ impl<'a> Processor<'a> { Dir::Out => e .what .iter() - .map(|v| v.to_string()) + .map(|v| v.0.to_owned()) .map(|v| { ( graph::ftprefix(ns, db, tb, id, &e.dir, &v), @@ -451,7 +451,7 @@ impl<'a> Processor<'a> { Dir::Both => e .what .iter() - .map(|v| v.to_string()) + .map(|v| v.0.to_owned()) .flat_map(|v| { vec![ ( diff --git a/lib/tests/relate.rs b/lib/tests/relate.rs index e80ced14..3e4fa1d9 100644 --- a/lib/tests/relate.rs +++ b/lib/tests/relate.rs @@ -180,3 +180,30 @@ async fn relate_with_param_or_subquery() -> Result<(), Error> { assert_eq!(tmp, val); Ok(()) } + +#[tokio::test] +async fn relate_with_complex_table() -> Result<(), Error> { + let sql = " + CREATE a:1, a:2; + RELATE a:1->`-`:`-`->a:2; + select ->`-` as rel 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(), 3); + // + 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: `-`:`-`, in: a:1, out: a:2 }]"); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse("[{ rel: [`-`:`-`] }]"); + assert_eq!(tmp, val); + // + Ok(()) +}