Skip to content

Commit

Permalink
fix(frontend): add subquery rewrite for parameter rewriter (#15095)
Browse files Browse the repository at this point in the history
Co-authored-by: ZENOTME <[email protected]>
  • Loading branch information
ZENOTME and ZENOTME authored Feb 28, 2024
1 parent 5051a8f commit 09f5e9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/frontend/src/binder/bind_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ impl ExprRewriter for ParamRewriter {
}
}

fn rewrite_subquery(&mut self, mut subquery: crate::expr::Subquery) -> ExprImpl {
subquery.query.rewrite_exprs_recursive(self);
subquery.into()
}

fn rewrite_parameter(&mut self, parameter: crate::expr::Parameter) -> ExprImpl {
let data_type = parameter.return_type();

Expand Down Expand Up @@ -224,4 +229,17 @@ mod test {
),
);
}

#[tokio::test]
async fn subquery() {
expect_actual_eq(
create_expect_bound("select (select '1')"),
create_actual_bound(
"select (select $1)",
vec![],
vec![Some("1".into())],
vec![Format::Text],
),
);
}
}
14 changes: 14 additions & 0 deletions src/tests/e2e_extended_mode/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl TestSuite {
self.simple_cancel(true).await?;
self.complex_cancel(false).await?;
self.complex_cancel(true).await?;
self.subquery_with_param().await?;
Ok(())
}

Expand Down Expand Up @@ -541,4 +542,17 @@ impl TestSuite {
new_client.execute("drop table t3", &[]).await?;
Ok(())
}

async fn subquery_with_param(&self) -> anyhow::Result<()> {
let client = self.create_client(false).await?;

let res = client
.query("select (select $1::SMALLINT)", &[&1024_i16])
.await
.unwrap();

assert_eq!(res[0].get::<usize, i16>(0), 1024_i16);

Ok(())
}
}

0 comments on commit 09f5e9a

Please sign in to comment.