Skip to content

fix(optimizer): ban using subquery in non-table-in-out function. #14748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/frontend/planner_test/tests/testdata/input/subquery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,8 @@
select Array(select 1 union select 2);
expected_outputs:
- batch_plan
- name: Only table-in-out functions can have subquery parameters. issue 14734
sql: |
SELECT anon_1.f1 AS "IntegerRange(0, -2, 1)" FROM unnest(CASE WHEN (nullif(1, 0) IS NOT NULL AND sign(1) = sign( -2 - 0)) THEN array_remove(array((SELECT generate_series(0, -2, 1) AS generate_series_1)), -2) ELSE CAST(ARRAY[] AS SMALLINT[]) END) AS anon_1(f1);
expected_outputs:
- binder_error
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@
- name: Only table-in-out functions can have subquery parameters.
sql: |
SELECT * FROM generate_series(1, (select 1));
binder_error: 'Invalid input syntax: Only table-in-out functions can have subquery parameters, generate_series only accepts constant parameters'
binder_error: 'Invalid input syntax: Only table-in-out functions can have subquery parameters. The table function has subquery parameters is generate_series'
- name: While this one is allowed.
sql: |
SELECT generate_series(1, (select 1));
Expand All @@ -894,3 +894,7 @@
└─BatchHashAgg { group_key: [1:Int32], aggs: [] }
└─BatchExchange { order: [], dist: HashShard(1:Int32) }
└─BatchValues { rows: [[1:Int32], [2:Int32]] }
- name: Only table-in-out functions can have subquery parameters. issue 14734
sql: |
SELECT anon_1.f1 AS "IntegerRange(0, -2, 1)" FROM unnest(CASE WHEN (nullif(1, 0) IS NOT NULL AND sign(1) = sign( -2 - 0)) THEN array_remove(array((SELECT generate_series(0, -2, 1) AS generate_series_1)), -2) ELSE CAST(ARRAY[] AS SMALLINT[]) END) AS anon_1(f1);
binder_error: 'Invalid input syntax: Only table-in-out functions can have subquery parameters. The table function has subquery parameters is unnest'
8 changes: 2 additions & 6 deletions src/frontend/src/binder/relation/table_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,10 @@ impl Binder {
let func = func?;

if let ExprImpl::TableFunction(func) = &func {
if func
.args
.iter()
.any(|arg| matches!(arg, ExprImpl::Subquery(_)))
{
if func.args.iter().any(|arg| arg.has_subquery()) {
// Same error reports as DuckDB.
return Err(ErrorCode::InvalidInputSyntax(
format!("Only table-in-out functions can have subquery parameters, {} only accepts constant parameters", func.name()),
format!("Only table-in-out functions can have subquery parameters. The table function has subquery parameters is {}", func.name()),
)
.into());
}
Expand Down