Snowflake snowpark python worksheet udf

361 Views Asked by At

@udf(name='a_plus_b', input_types=[IntegerType(), IntegerType()], return_type=IntegerType(), is_permanent=False, replace=True) def a_plus_b(a: int, b: int) -> int: return a+b

def main(session: snowpark.Session):

df.with_column('Somme',a_plus_b( col('a'),col('b') ) )

return df

here is the error in my @udf registration. Traceback (most recent call last): Worksheet, line 8, in <module> File "snowflake/snowpark/functions.py", line 6693, in udf session = session or snowflake.snowpark.session._get_active_session() File "snowflake/snowpark/session.py", line 179, in _get_active_session raise SnowparkClientExceptionMessages.SERVER_NO_DEFAULT_SESSION() snowflake.snowpark.exceptions.SnowparkSessionException: (1403): No default Session is found. Please create a session before you call function 'udf' or use decorator '@udf'.

can someone helpme me please.

1

There are 1 best solutions below

1
soorej s On BEST ANSWER
def main(session: snowpark.Session):

     @udf(name='a_plus_b', input_types=[IntegerType(), IntegerType()], return_type=IntegerType(), is_permanent=False, replace=True)
     def a_plus_b(a: int, b: int) -> int: return a+b

     df.with_column('Somme',a_plus_b( col('a'),col('b') ) )

return df