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?
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
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments