@@ -201,7 +201,7 @@ def test_load_microbatch_all_defined(
201201 concurrent_batches=true
202202 )
203203 }}
204-
204+
205205 SELECT 1 as cola, '2025-01-01' as ds
206206 """
207207 microbatch_model_file = model_dir / "microbatch.sql"
@@ -633,3 +633,80 @@ def test_dbt_jinja_macro_undefined_variable_error(create_empty_project):
633633 assert "Failed to update model schemas" in error_message
634634 assert "Could not render jinja for" in error_message
635635 assert "Undefined macro/variable: 'columns' in macro: 'select_columns'" in error_message
636+
637+
638+ @pytest .mark .slow
639+ def test_node_name_populated_for_dbt_models (dbt_dummy_postgres_config : PostgresConfig ) -> None :
640+ model_config = ModelConfig (
641+ name = "test_model" ,
642+ package_name = "test_package" ,
643+ sql = "SELECT 1 as id" ,
644+ database = "test_db" ,
645+ schema_ = "test_schema" ,
646+ alias = "test_model" ,
647+ )
648+
649+ context = DbtContext ()
650+ context .project_name = "test_project"
651+ context .target = dbt_dummy_postgres_config
652+
653+ # check after convert to SQLMesh model that node_name is populated correctly
654+ sqlmesh_model = model_config .to_sqlmesh (context )
655+ assert sqlmesh_model .node_name == "model.test_package.test_model"
656+
657+
658+ @pytest .mark .slow
659+ def test_load_model_dbt_node_name (tmp_path : Path ) -> None :
660+ yaml = YAML ()
661+ dbt_project_dir = tmp_path / "dbt"
662+ dbt_project_dir .mkdir ()
663+ dbt_model_dir = dbt_project_dir / "models"
664+ dbt_model_dir .mkdir ()
665+
666+ model_contents = "SELECT 1 as id, 'test' as name"
667+ model_file = dbt_model_dir / "simple_model.sql"
668+ with open (model_file , "w" , encoding = "utf-8" ) as f :
669+ f .write (model_contents )
670+
671+ dbt_project_config = {
672+ "name" : "test_project" ,
673+ "version" : "1.0.0" ,
674+ "config-version" : 2 ,
675+ "profile" : "test" ,
676+ "model-paths" : ["models" ],
677+ }
678+ dbt_project_file = dbt_project_dir / "dbt_project.yml"
679+ with open (dbt_project_file , "w" , encoding = "utf-8" ) as f :
680+ yaml .dump (dbt_project_config , f )
681+
682+ sqlmesh_config = {
683+ "model_defaults" : {
684+ "start" : "2025-01-01" ,
685+ }
686+ }
687+ sqlmesh_config_file = dbt_project_dir / "sqlmesh.yaml"
688+ with open (sqlmesh_config_file , "w" , encoding = "utf-8" ) as f :
689+ yaml .dump (sqlmesh_config , f )
690+
691+ dbt_data_dir = tmp_path / "dbt_data"
692+ dbt_data_dir .mkdir ()
693+ dbt_data_file = dbt_data_dir / "local.db"
694+ dbt_profile_config = {
695+ "test" : {
696+ "outputs" : {"duckdb" : {"type" : "duckdb" , "path" : str (dbt_data_file )}},
697+ "target" : "duckdb" ,
698+ }
699+ }
700+ db_profile_file = dbt_project_dir / "profiles.yml"
701+ with open (db_profile_file , "w" , encoding = "utf-8" ) as f :
702+ yaml .dump (dbt_profile_config , f )
703+
704+ context = Context (paths = dbt_project_dir )
705+
706+ # find the model by its sqlmesh fully qualified name
707+ model_fqn = '"local"."main"."simple_model"'
708+ assert model_fqn in context .snapshots
709+
710+ # Verify that node_name is the equivalent dbt one
711+ model = context .snapshots [model_fqn ].model
712+ assert model .node_name == "model.test_project.simple_model"
0 commit comments