snowflake with snowpark error: sql() missing 1 required positional argument: 'query'

Patterson

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:

enter image description here

Any thoughts?

Lukasz Szozda

When using Python Worksheet you need to use session that is already provided:

enter image description here

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:

enter image description here


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

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

"TYPE ERROR MISSING 1 REQUIRED POSITIONAL ARGUMENT"

Getting read_data() missing 1 required positional argument: 'query' error even after passing the query in Python

missing 1 required positional argument

geopy TypeError : geocode() missing 1 required positional argument: 'query'

Why am I getting a 'missing 1 required positional argument:' error?

Getting this error in django "login() missing 1 required positional argument: 'user' "

ERROR: typeerror when() missing 1 required positional argument 'value' in PySpark

Error lambda missing 1 required positional argument when using with QPushButton

Python 3.6 TYPE ERROR: missing 1 required positional argument

Python error: missing 1 required positional argument: 'self'

pyspark dataframe error: _() missing 1 required positional argument: 'col'

Selenium Error: Missing 1 required positional argument: 'url'

How do fix the "missing 1 required positional argument: 'self'" error?

Python Error " <method> missing 1 required positional argument: 'self' "

Error "TypeError: FirstForm() missing 1 required positional argument: 'request'"

Function in Class error: TypeError: function() missing 1 required positional argument:

How to remove this error?fit() missing 1 required positional argument: 'y'

Error:__init__() missing 1 required positional argument: 'rec'

Code gives missing 1 required positional argument error

TypeError: mute_error() missing 1 required positional argument: 'ctx'

Why do I get error "missing 1 required positional argument"?

Missing 1 required positional argument: 'self' missing

Django missing 1 required positional argument

TypeError: post() missing 1 required positional argument

ArrayField missing 1 required positional argument

Multiprocessing, missing 1 required positional argument: 'response'

setUpClass() missing 1 required positional argument: 'cls'

save() missing 1 required positional argument 'self'

function model() missing 1 required positional argument