英文:
snowflake with snowpark error: sql() missing 1 required positional argument: 'query'
问题
我正在尝试在Snowpark上执行一些简单的代码,但出现了错误。我熟悉这个错误,只是不确定为什么会出现这个错误:
代码如下:
# Python工作表需要Snowpark包。
# 你可以通过选择Packages控制并导入更多包来添加更多包。
import snowflake.snowpark as snowpark
from snowflake.snowpark.functions import col
from snowflake.snowpark.session import Session
df = Session.sql('select * from snowflake_sample_data.tpch_sf10.lineitem')
我收到以下错误:
英文:
I am trying to execute some simple code on Snowpark, but getting an error. I am familiar with the error, just not sure why I should be getting the error:
The code is as follows:
# The Snowpark package is required for Python Worksheets.
# You can add more packages by selecting them using the Packages control and then importing them.
import snowflake.snowpark as snowpark
from snowflake.snowpark.functions import col
from snowflake.snowpark.session import Session
df = Session.sql('select * from snowflake_sample_data.tpch_sf10.lineitem')
I'm getting the following error:
Any thoughts?
答案1
得分: 1
以下是您要翻译的内容:
当使用Python工作表时,您需要使用已提供的“session”:
第一个参数是“self”,这就是它抱怨缺少“query”的原因。
sql()
不是静态/类方法。
尝试在Python工作表内创建另一个会话也会失败:
import snowflake.snowpark as snowpark
from snowflake.snowpark.session import Session
df = Session.builder.create().sql('select* from snowflake_sample_data.tpch_sf10.lineitem')
尝试在“main”之外使用“session”:
解决方案:
import snowflake.snowpark as snowpark
def main(session: snowpark.Session):
df = session.sql('select top 10 * from snowflake_sample_data.tpch_sf10.lineitem')
return df
英文:
When using Python Worksheet you need to use session
that is already provided:
The first argument is "self", that is the reason it is complaining about missing "query".
sql()
is NOT a static/class method.
> snowflake.snowpark.Session.sql
>
> def sql(self, query: str, params: Optional[Sequence[Any]] = None)-> DataFrame
Trying to create another session inside Python Worksheet will also fail:
import snowflake.snowpark as snowpark
from snowflake.snowpark.session import Session
df = Session.builder.create().sql('select* from snowflake_sample_data.tpch_sf10.lineitem')
> snowflake.connector.errors.ProgrammingError: Connection was already created. We don't allow user to create their own connection inside a stored procedure. Please use the connection in the provided session from the handler.
Trying to use session
outside main
:
Solution:
import snowflake.snowpark as snowpark
def main(session: snowpark.Session):
df = session.sql('select top 10 * from snowflake_sample_data.tpch_sf10.lineitem')
return df
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论