File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -995,6 +995,11 @@ impl ScalarFunctionWrapper {
995995 Self :: parse_placeholder_identifier ( & placeholder. id ) ?;
996996 if placeholder_position < args. len ( ) {
997997 Transformed :: yes ( args[ placeholder_position] . clone ( ) )
998+ } else if placeholder_position >= defaults. len ( ) {
999+ exec_err ! (
1000+ "Invalid placeholder, out of range: {}" ,
1001+ placeholder. id
1002+ ) ?
9981003 } else {
9991004 match defaults[ placeholder_position] {
10001005 Some ( ref default) => Transformed :: yes ( default. clone ( ) ) ,
@@ -1137,6 +1142,23 @@ async fn create_scalar_function_from_sql_statement() -> Result<()> {
11371142 "# ;
11381143 assert ! ( ctx. sql( bad_definition_sql) . await . is_err( ) ) ;
11391144
1145+ // FIXME: Definitions with invalid placeholders are allowed, fail at runtime
1146+ let bad_expression_sql = r#"
1147+ CREATE FUNCTION better_add(DOUBLE, DOUBLE)
1148+ RETURNS DOUBLE
1149+ RETURN $1 + $3
1150+ "# ;
1151+ assert ! ( ctx. sql( bad_expression_sql) . await . is_ok( ) ) ;
1152+
1153+ let err = ctx
1154+ . sql ( "select better_add(2.0, 2.0)" )
1155+ . await ?
1156+ . collect ( )
1157+ . await
1158+ . expect_err ( "unknown placeholder" ) ;
1159+ let expected = "Optimizer rule 'simplify_expressions' failed\n caused by\n Execution error: Invalid placeholder, out of range: $3" ;
1160+ assert ! ( expected. starts_with( & err. strip_backtrace( ) ) ) ;
1161+
11401162 Ok ( ( ) )
11411163}
11421164
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
140140 }
141141 } ;
142142 // Check if the placeholder is in the parameter list
143+ // FIXME: In the CREATE FUNCTION branch, param_type = None should raise an error
143144 let param_type = param_data_types. get ( idx) ;
144145 // Data type of the parameter
145146 debug ! ( "type of param {param} param_data_types[idx]: {param_type:?}" ) ;
You can’t perform that action at this time.
0 commit comments