SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function

huangapple go评论56阅读模式
英文:

SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function

问题

以下是翻译好的部分:

在SnowFlake Python表中执行Python代码时,如果没有包含以下函数:

def main(session: snowpark.Session):
    return fake('en_US','celltype',{})

我会得到错误:
SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function

如果我包含上述函数,代码将成功执行。

因此,有人可以解释以下函数的目的吗?

def main(session: snowpark.Session):

我猜我也需要一些关于 'handlers' 的理解。

完整的代码如下:

import snowflake.snowpark as snowpark
from faker import Faker
import wheel_loader

def fake(locale, provider, parameters):
    wheel_loader.load('faker_biology-0.6.0-py3-none-any.whl')
    from faker_biology.physiology import CellType
    if type(parameters).__name__ == 'sqlNullWrapper':
        parameters = {}
    fake = Faker(locale=locale)
    fake.add_provider(CellType)
    return fake.format(formatter=provider, **parameters)

def main(session: snowpark.Session):
    return fake('en_US', 'celltype', {})

请注意,代码中的函数 main 似乎是用于执行特定操作的入口点。

英文:

While executing Python code in SnowFlake Python sheet without the function

def main(session: snowpark.Session):
    return fake('en_US','celltype',{})

I get the error:
SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function

If I include the above function the code executes successfully.

Therefore, can someone explain the purpose of the function

def main(session: snowpark.Session):

I guess I need some understanding on 'handlers' as well.

The full code is as follows:

import snowflake.snowpark as snowpark

from faker import Faker
import wheel_loader

    
def fake(locale,provider,parameters):
    wheel_loader.load('faker_biology-0.6.0-py3-none-any.whl')

    from faker_biology.physiology import CellType
      
    if type(parameters).__name__=='sqlNullWrapper':
        parameters = {}
    fake = Faker(locale=locale)
    fake.add_provider(CellType)
    return fake.format(formatter=provider,**parameters)

def main(session: snowpark.Session):
    return fake('en_US','celltype',{})

答案1

得分: 1

主函数是Python工作表的默认入口点。

在Python工作表中编写Snowpark代码

在处理程序函数中编写Snowpark Python代码:

import snowflake.snowpark as snowpark

def main(session: snowpark.Session):
    # 在这里编写您的代码

默认处理程序函数是 main,但您可以在工作表的设置中更改它。

使用在样板代码中提供的 session 对象,通过Snowpark API库访问Snowflake中的数据。例如,您可以为表创建一个DataFrame或执行SQL语句。

SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function


重要提示:截至发布此帖子时,处理函数的签名不允许更多参数:

def fake(session: snowpark.Session, locale, provider, parameters):

SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function

英文:

main is the default entry point for Python Worksheet.

> Writing Snowpark Code in Python Worksheets
>
> Write your Snowpark Python code inside the handler function:
>
>
> import snowflake.snowpark as snowpark
>
> def main(session: snowpark.Session):
> # your code goes here
>
> The default handler function is main, but you can change it in the Settings for the worksheet.
>
> Use the session object provided in the boilerplate code to access data in Snowflake with the Snowpark API libraries. For example, you can create a DataFrame for a table or execute a SQL statement

SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function


Important: signature of handling function (as a moment of writing this post) does not allow more arguments:

def fake(session: snowpark.Session, locale,provider,parameters):

SnowFlake PythonSheet Error :Could not find handler function. Python worksheet must contain a handler function

huangapple
  • 本文由 发表于 2023年5月13日 19:55:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定