Alex Furrier
05/25/2021, 9:20 PMfrom 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:
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
Kevin Kho
Alex Furrier
05/26/2021, 5:04 PM