snowflake-connector-python
snowflake-connector-python copied to clipboard
SNOW-670332: Creating procedure using functions with variable arguments (*args)
Trying to create a UDF using the snowflake connector by executing this statement. This seems to work for creating a UDF, but not for a Store Procedure. It seems that, while the statement is executed, there is an AST Parser that is executed to check for the arguments.
I would like to take in variable arguments, so that I could modify my function depending on the requirements. Is there a way to achieve what I am trying to do, or by pass the limitation?
- What did you do?
create or replace procedure var_arg_proc(arg_1 STRING)
returns STRING
language python
runtime_version = '3.8'
packages = ('snowflake-snowpark-python')
handler = 'my_function'
AS
$$
from snowflake.snowpark.session import Session
def my_function(session: Session, *args):
return arg[0]
$$;
- Can you set logging to DEBUG and collect the logs?
100357 (P0000): Python function is defined with 1 arguments (including session), but stored procedure definition
contains 1 arguments. Python function arguments are expected to be session and stored procedure defined
arguments in function VAR_ARG_PROC with handler my_function
@krish-adi : Can you post this in https://github.com/snowflakedb/snowpark-python instead? I'm going to close this one.
Sorry I misread, but this really has nothing to do with either the connector or snowpark api. Let's just keep it here.
I'll delete the one I posted in snowpark then.
@krish-adi : sorry for the confusion, we could keep it here.
Using *args in general does not make sense because the definition of the UDF/SP contains the number of arguments as well. I'm a bit surprised that it would work with python UDF. How would you pass in variable arguments if the definition of the UDF only takes one argument?
When I define the UDF/SP I programmatically add or remove the arguments using string manipulation.
But, when I actually write the handler, I don't want to do this. And I pass *args to the function. This works fine with a handler for functions, but not for a SP handler. For now, I've resorted to use string manipulation.
@sfc-gh-sfan Does the SP server check the arguments of the handler function? We can remove this validation.
@sfc-gh-yixie : Yes. I just checked and it seems like in UDF the check considered varargs, but not SP. We should improve our validation, instead of removing it. I added an internal ticket for it and we will try to address this in the next couple of weeks. Please be aware that the snowflake release itself also takes time.
And again, thanks for raising it to us!