Skip to content

Commit

Permalink
fix(optimizer): ban using subquery in non-table-in-out function. (#14748
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chenzl25 authored Jan 24, 2024
1 parent 7853be6 commit 6b7f37a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
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

0 comments on commit 6b7f37a

Please sign in to comment.