Viktor
09/17/2024, 12:37 PMurl_regexes
• urls
• queries
I would like to parameterize the left-most input textwidget_location str, which is the file name to use, for each of these three branches,
so this currently one path becomes three separate ingress pipes.
What is the best way to do this?
The sequence
textwidget_location -> ... -> textwidget_load
is in a separate module.
Viktor
09/17/2024, 2:19 PM%%cell_to_module -m textwidget_store
from hamilton.function_modifiers import load_from, save_to, source
ttws = source("textwidget_location")
@load_from.pickle(path=ttws, inject_="textwidget_value")
def textwidget_load(textwidget_value: str='') -> str:
'''loading a stored textarea widget'''
return textwidget_value
@save_to.pickle(path=ttws, output_name_="textwidget_save")
def textwidget_save_preprocess(textwidget_value: str='') -> str:
'''saving a stored textarea widget'''
return textwidget_valueStefan Krawczyk
09/17/2024, 4:03 PMStefan Krawczyk
09/17/2024, 4:06 PMStefan Krawczyk
09/17/2024, 4:17 PMdef textwidget_location(paths: list[str]) -> Parallelizable[str]:
for path in paths:
yield path
@load_from.pickle(path=source("textwidget_location"), inject_="textwidget_value")
def textwidget_load(textwidget_value: str='') -> str:
'''loading a stored textarea widget'''
return textwidget_value
...
def collected_data(... : Collect[dict]) -> ...:
# you need a collect to aggregate things back -- this could be at the end, or in the middleViktor
09/17/2024, 6:36 PMtextwidget_load node in the textwidget_store module (subdag?), but with their own file source request, so to say.
I would be able to use pipe with the textwidget_load node, if only the file source parameter wasn't on the separate load_from node coming from the decorator …
I wonder, how this works with Hamilton, when the parameter needs to be applied on a higher upstream node, than the dependency node.
Will look into the videos.Viktor
09/17/2024, 6:42 PMStefan Krawczyk
09/17/2024, 7:00 PMfile_1_result = dr.execute(["urls_regexes"], inputs={"textdwidget_location": file_1})
file_2_result = dr.execute(["urls_multiline"], inputs={"textdwidget_location": file_2})
file_3_result = dr.execute(["preprocessed_queries"], inputs={"textdwidget_location": file_3})
So you’d need to manage the output desired with the correct input file.Viktor
09/17/2024, 7:05 PMViktor
09/17/2024, 7:10 PMViktor
09/17/2024, 7:10 PMStefan Krawczyk
09/17/2024, 7:10 PMViktor
09/17/2024, 7:12 PMViktor
09/17/2024, 7:13 PMViktor
09/17/2024, 7:13 PMViktor
09/17/2024, 7:13 PMStefan Krawczyk
09/17/2024, 7:18 PM@load_from.pickle(path=source("textwidget_location_1"), inject_="textwidget_value")
def textwidget_load_1(textwidget_value: str='') -> str:
'''loading a stored textarea widget'''
return textwidget_value
@load_from.pickle(path=source("textwidget_location_2"), inject_="textwidget_value")
def textwidget_load_2(textwidget_value: str='') -> str:
'''loading a stored textarea widget'''
return textwidget_value
@load_from.pickle(path=source("textwidget_location_3"), inject_="textwidget_value")
def textwidget_load_3(textwidget_value: str='') -> str:
'''loading a stored textarea widget'''
return textwidget_value
# then downstream you'd depend on the correct one above ^
2. You could do subdag that mirrors what I did executing the DAG three times
@subdag(..., inputs={"textdwidget_location": source("filelocation1")})
def file_1_result(urls_regexes: str) -> ...
return urls_regexes
@subdag(..., inputs={"textdwidget_location": source("filelocation2")})
def file_2_result(urls_multiline: str) -> ...
return urls_multiline
...
# then you'd join these
def dimension_filters(file_1_result: str, ..) -> ...
3. You could do just a subdag over the data loading — you’d then still need to rewire the downstream functions to depend on that subdag function like in (1).Viktor
09/17/2024, 7:31 PM