Skip to content

Commit

Permalink
fix(binder): only table-in-out functions can have subquery parameters (
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 authored Oct 27, 2023
1 parent 00df635 commit 6b7f863
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/frontend/planner_test/tests/testdata/input/subquery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,13 @@
expected_outputs:
- batch_plan
- stream_plan
- name: Only table-in-out functions can have subquery parameters.
sql: |
SELECT * FROM generate_series(1, (select 1));
expected_outputs:
- binder_error
- name: While this one is allowed.
sql: |
SELECT generate_series(1, (select 1));
expected_outputs:
- batch_plan
13 changes: 13 additions & 0 deletions src/frontend/planner_test/tests/testdata/output/subquery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,16 @@
└─StreamHopWindow { time_col: t1.ts, slide: 00:10:00, size: 00:30:00, output: all }
└─StreamFilter { predicate: IsNotNull(t1.ts) }
└─StreamTableScan { table: t1, columns: [t1.k, t1.ts], pk: [t1.k], dist: UpstreamHashShard(t1.k) }
- 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'
- name: While this one is allowed.
sql: |
SELECT generate_series(1, (select 1));
batch_plan: |-
BatchProject { exprs: [GenerateSeries(1:Int32, $0)] }
└─BatchProjectSet { select_list: [GenerateSeries(1:Int32, $0)] }
└─BatchNestedLoopJoin { type: LeftOuter, predicate: true, output: all }
├─BatchValues { rows: [[]] }
└─BatchValues { rows: [[1:Int32]] }
16 changes: 15 additions & 1 deletion src/frontend/src/binder/relation/table_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::binder::bind_context::Clause;
use crate::catalog::system_catalog::pg_catalog::{
PG_GET_KEYWORDS_FUNC_NAME, PG_KEYWORDS_TABLE_NAME,
};
use crate::expr::Expr;
use crate::expr::{Expr, ExprImpl};

impl Binder {
/// Binds a table function AST, which is a function call in a relation position.
Expand Down Expand Up @@ -125,6 +125,20 @@ impl Binder {
self.pop_context()?;
let func = func?;

if let ExprImpl::TableFunction(func) = &func {
if func
.args
.iter()
.any(|arg| matches!(arg, ExprImpl::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()),
)
.into());
}
}

// bool indicates if the field is hidden
let mut columns = if let DataType::Struct(s) = func.return_type() {
// If the table function returns a struct, it will be flattened into multiple columns.
Expand Down

0 comments on commit 6b7f863

Please sign in to comment.