Skip to content

Instantly share code, notes, and snippets.

@JHibbard
Last active May 10, 2024 04:10
Show Gist options
  • Save JHibbard/a94c266471e95b0e859972b374700cd4 to your computer and use it in GitHub Desktop.
Save JHibbard/a94c266471e95b0e859972b374700cd4 to your computer and use it in GitHub Desktop.
Example function for generating normalized table URIs reflecting the medallion architecture
from pathlib import Path
def make_table_uris(name: str, basepath: str='.'):
"""Example function for generating normalized table URIs
Args:
name: name of table to generate table URIs for
basepath: directory to nest table URIs under
Returns:
dictionary of table uris indexed by landing, bronze, silver, and gold
to reflect the medallion architecture
"""
base = Path(basepath, name).absolute()
return {
'landing': base.joinpath('landing').as_posix(),
'bronze': base.joinpath(f'{name}_bronze').as_posix(),
'silver': base.joinpath(f'{name}_silver').as_posix(),
'gold': base.joinpath(f'{name}').as_posix(),
}
"""
# Example Output
>> table_uris = make_table_uris(name='sales', basepath='/delta/tables/')
>> table_uris
{
'landing': '/delta/tables/sales/landing',
'bronze': '/delta/tables/sales/sales_bronze',
'silver': '/delta/tables/sales/sales_silver',
'gold': '/delta/tables/sales/sales'
}
# Indexing into a specific name:
>> table_uris['silver']
'/delta/tables/sales/sales_silver'
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment