Skip to content

Instantly share code, notes, and snippets.

@wrgoldstein
Created May 3, 2024 16:10
Show Gist options
  • Save wrgoldstein/5d9f27d83986140e7029bcb853577d17 to your computer and use it in GitHub Desktop.
Save wrgoldstein/5d9f27d83986140e7029bcb853577d17 to your computer and use it in GitHub Desktop.
import pathlib
import string
import itertools
import random
from typing import Callable
roots = "select 100 as id"
def sql(nodes):
return "UNION ALL".join(["select 100 as id from {{ ref('%s') }}" % n for n in nodes])
def make_roots():
for s in string.ascii_lowercase:
pathlib.Path(f"models/{s}.sql").write_text(roots)
def write_models_from_refs(iterable):
for i,j in iterable:
pathlib.Path(f"models/{i}{j}.sql").write_text(sql([i,j]))
def make_pairwise(l):
stems = [p.stem for p in pathlib.Path("models/").glob("*.sql")]
stems = sorted(stems, key=lambda x: random.random())
l1 = list(filter(lambda x: len(x) == l, stems))
refs = itertools.pairwise(l1)
write_models_from_refs(refs)
make_roots()
make_pairwise(1)
make_pairwise(1)
make_pairwise(2)
make_pairwise(2)
make_pairwise(2)
make_pairwise(2)
make_pairwise(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment