Brian K
04/15/2024, 7:12 PMfetch_many
(or anything really) from the SnowflakeConnector
with a yield instead of return.
@task
def fetch_data(block_name: str) -> list:
all_rows = []
with SnowflakeConnector.load(block_name) as connector:
while True:
batch = connector.fetch_many("SELECT * FROM MY_BIG_TABLE", size=10000)
if len(batch) == 0:
break
all_rows.append(batch) # why append????
return all_rows
This works fine but if I try doing something like this:
@task
def fetch_data(block_name: str):
with SnowflakeConnector.load(block_name) as connector:
while True:
batch = connector.fetch_many("SELECT * FROM MY_BIG_TABLE", size=10000)
if len(batch) == 0:
break
yield batch
I get a ton of errors steaming from the SnowflakeConnector as 'coroutine' object does not support the context manager protocol
We are able to yield
from prefect tasks in general and wondering why these seems to really not like being a generatorStephen Lloyd
04/24/2024, 5:51 AM