I'm running into some issues with the built in Sno...
# ask-community
a
I'm running into some issues with the built in Snowflake task. Is there documentation on how to use it? Specifically I'm running into the following issue: I'm using the task SnowflakeQuery to execute a query. I'm doing that like so:
Copy code
from prefect.tasks.snowflake.snowflake import SnowflakeQuery

sf_task = SnowflakeQuery(query=SNOWFLAKE_QUERY,
               user=SNOWFLAKE_USER,
               password=SNOWFLAKE_PASSWORD,
               account=SNOWFLAKE_ACCOUNT,
               warehouse=SNOWFLAKE_ACCOUNT,
               database=SNOWFLAKE_DATABASE,
               role=SNOWFLAKE_ROLE,
               schema=SNOWFLAKE_SCHEMA)
ret = sf_task.run()
Going off the source code I would expect that to return the query data in an iterable. This based off the code within
SnowflakeQuery
that creates a cursor, connects, executes the query and then returns the
.fetchall()
method of an executed Snowflake cursor (basing my understanding of that from this) What is actually returned by
sf_task.run()
is the Snowflake cursor which appears to have already executed the query (it's of type
snowflake.connector.cursor.SnowflakeCursor
with a closed connection state). However, there is metadata in
ret.description
which is a list of tuples. I've tried this with a few different queries that should return data and it's the same result. Any idea what's going on? I may be doing something obviously wrong but not seeing it. I'm able to get the data using the Snowflake connector and executing myself:
Copy code
import snowflake.connector
import pandas as pd

#create connection
conn=snowflake.connector.connect(
               user=SNOWFLAKE_USER,
               password=SNOWFLAKE_PASSWORD,
               account=SNOWFLAKE_ACCOUNT,
               warehouse=SNOWFLAKE_ACCOUNT,
               database=SNOWFLAKE_DATABASE,
               role=SNOWFLAKE_ROLE,
               schema=SNOWFLAKE_SCHEMA)

                
#create cursor
curs=conn.cursor()

#execute SQL statement
cur = curs.execute(SNOWFLAKE_QUERY)

#load it to df
df = pd.DataFrame.from_records(iter(cur), columns=[x[0] for x in cur.description])
df
k
Hey @Alex Furrier, I was the last one who edited the SnowflakeQuery task. If I remember it right, it returns an iterable as you described. What version of Prefect are you on? This update was in 0.14.14. The closed cursor was before this I think.
a
@Kevin Kho This was the issue. Worked after upgrading. Thanks!
👍 1