snowflake-connector-python icon indicating copy to clipboard operation
snowflake-connector-python copied to clipboard

SNOW-670332: Creating procedure using functions with variable arguments (*args)

Open krish-adi opened this issue 3 years ago • 9 comments

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?

  1. 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]
$$;
  1. 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 avatar Sep 29 '22 09:09 krish-adi

@krish-adi : Can you post this in https://github.com/snowflakedb/snowpark-python instead? I'm going to close this one.

sfc-gh-sfan avatar Sep 29 '22 16:09 sfc-gh-sfan

Sorry I misread, but this really has nothing to do with either the connector or snowpark api. Let's just keep it here.

sfc-gh-sfan avatar Sep 29 '22 16:09 sfc-gh-sfan

I'll delete the one I posted in snowpark then.

krish-adi avatar Sep 29 '22 16:09 krish-adi

@krish-adi : sorry for the confusion, we could keep it here.

sfc-gh-sfan avatar Sep 29 '22 16:09 sfc-gh-sfan

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?

sfc-gh-sfan avatar Sep 29 '22 16:09 sfc-gh-sfan

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.

krish-adi avatar Sep 29 '22 17:09 krish-adi

@sfc-gh-sfan Does the SP server check the arguments of the handler function? We can remove this validation.

sfc-gh-yixie avatar Sep 29 '22 21:09 sfc-gh-yixie

@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.

sfc-gh-sfan avatar Sep 29 '22 22:09 sfc-gh-sfan

And again, thanks for raising it to us!

sfc-gh-sfan avatar Sep 29 '22 23:09 sfc-gh-sfan