Skip to content

Instantly share code, notes, and snippets.

@skrawcz
Last active July 19, 2024 17:16
Show Gist options
  • Save skrawcz/83a77343b1a9774b77fabde35b00ce07 to your computer and use it in GitHub Desktop.
Save skrawcz/83a77343b1a9774b77fabde35b00ce07 to your computer and use it in GitHub Desktop.
Shows how to potentially get around boilerplate config loading code by parameterizing it
# %%cell_to_module config_plate --display
from hamilton.function_modifiers import parameterize, source, value
class TablePaths:
pass # your code here
table_names = ["vendor", "predictions"] # update this
@parameterize(
**{
f"{name}_paths": {"table_name": value(name)}
for name in table_names
}
)
def table_paths(table_paths: TablePaths, table_name: str) -> dict:
_table = getattr(table_paths, table_name)
return {
f"{table_name}_catalog": _table.catalog,
f"{table_name}_schema": _table.schema,
f"{table_name}_table": _table.table,
}
@parameterize(
**{
f"{name}_{part}": {"general_dict": source(f"{name}_paths"), "field_name": value(part)}
for name in table_names
for part in ["catalog", "schema", "table"]
}
)
def parameterized_extract_fields(general_dict: dict, field_name: str) -> str:
return general_dict[field_name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment