@@ -8233,6 +8233,49 @@ def entrypoint(evaluator):
82338233 )
82348234
82358235
8236+ def test_dynamic_blueprinting (tmp_path : Path ) -> None :
8237+ init_example_project (tmp_path , dialect = "duckdb" , template = ProjectTemplate .EMPTY )
8238+
8239+ dynamic_template = tmp_path / "models/dynamic_template.sql"
8240+ dynamic_template .parent .mkdir (parents = True , exist_ok = True )
8241+ dynamic_template .write_text (
8242+ """
8243+ MODEL (
8244+ name @customer.some_table,
8245+ kind FULL,
8246+ blueprints @gen_blueprints(),
8247+ );
8248+
8249+ SELECT
8250+ @field_a,
8251+ @{field_b} AS field_b
8252+ FROM @customer.some_source
8253+
8254+ """
8255+ )
8256+
8257+ gen_blueprints = tmp_path / "macros/gen_blueprints.py"
8258+ gen_blueprints .parent .mkdir (parents = True , exist_ok = True )
8259+ gen_blueprints .write_text (
8260+ """from sqlmesh import macro
8261+
8262+ @macro()
8263+ def gen_blueprints(evaluator):
8264+ return (
8265+ "((customer := customer1, field_a := x, field_b := y),"
8266+ " (customer := customer2, field_a := z, field_b := w))"
8267+ )"""
8268+ )
8269+
8270+ ctx = Context (
8271+ config = Config (model_defaults = ModelDefaultsConfig (dialect = "duckdb" )), paths = tmp_path
8272+ )
8273+
8274+ assert len (ctx .models ) == 2
8275+ assert '"memory"."customer1"."some_table"' in ctx .models
8276+ assert '"memory"."customer2"."some_table"' in ctx .models
8277+
8278+
82368279@time_machine .travel ("2020-01-01 00:00:00 UTC" )
82378280def test_dynamic_date_spine_model (assert_exp_eq ):
82388281 @macro ()
0 commit comments