chilly-midnight-51093
05/09/2023, 3:52 PMcrooked-jordan-29960
05/09/2023, 4:23 PMself. is too big, you can chunk the data to parquet files in the upstream task, and read them downstream using the cloud-to-table pattern in this blog.
More context
Calling self.artifact=my_table serializes the contents of my_table and pushes the bytes to cloud storage which can become relatively slow with big tables/dfs. The reason to use self. is to benefit from Metaflow's versioning across tasks run on different machines. For smallish datasets, there is a negligible cost to versioning artifacts like this and the benefits make debugging and monitoring much easier. But as the data size grows, and benefits of the fast data pattern kick in more, and the serialization cost of self. grows.
By the way, "the cost" of serialization here is described above like an opportunity cost relative to the fast data pattern, since it is actually pretty fast to serialize and move artifacts within the same cloud - the thing that matters more is that the table is one big blob, as opposed to N parquet files that can be read/written/operated on in parallel.chilly-midnight-51093
05/09/2023, 4:43 PMcrooked-jordan-29960
05/09/2023, 5:03 PMchilly-midnight-51093
05/09/2023, 5:18 PMchilly-midnight-51093
05/10/2023, 12:00 AMcrooked-jordan-29960
05/10/2023, 1:17 AMfrom metaflow import FlowSpec, step
class F(FlowSpec):
@step
def start(self):
self.next(self.end)
@step
def end(self):
from metaflow import S3
import io
buf = io.BytesIO()
buf.write(b"How many bytes do you think this message is? Check in the S3 bucket metadata!")
buf.seek(0)
with S3(run=self) as s3:
url = s3.put('data', buf)
print(url)
if __name__ == '__main__':
F()
Also for small dataframes or chunks AWSWrangler is nice!
import awswrangler as wr
wr.pandas.to_parquet(
dataframe=df,
path="s3://...",
dataset=True,
mode="overwrite", # Could be append, overwrite or overwrite_partitions
database="my_database", # Optional, only with you want it available on Athena/Glue Catalog
table="my_table",
partition_cols=["PARTITION_COL_NAME"])chilly-midnight-51093
05/10/2023, 2:22 PM