@@ -579,3 +579,80 @@ def test_load_microbatch_with_ref_no_filter(
579579 context .render (microbatch_two_snapshot_fqn , start = "2025-01-01" , end = "2025-01-10" ).sql ()
580580 == 'SELECT "microbatch"."cola" AS "cola", "microbatch"."ds" AS "ds" FROM "local"."main"."microbatch" AS "microbatch"'
581581 )
582+
583+
584+ @pytest .mark .slow
585+ def test_node_name_populated_for_dbt_models (dbt_dummy_postgres_config : PostgresConfig ) -> None :
586+ model_config = ModelConfig (
587+ name = "test_model" ,
588+ package_name = "test_package" ,
589+ sql = "SELECT 1 as id" ,
590+ database = "test_db" ,
591+ schema_ = "test_schema" ,
592+ alias = "test_model" ,
593+ )
594+
595+ context = DbtContext ()
596+ context .project_name = "test_project"
597+ context .target = dbt_dummy_postgres_config
598+
599+ # check after convert to SQLMesh model that node_name is populated correctly
600+ sqlmesh_model = model_config .to_sqlmesh (context )
601+ assert sqlmesh_model .node_name == "model.test_package.test_model"
602+
603+
604+ @pytest .mark .slow
605+ def test_load_model_dbt_node_name (tmp_path : Path ) -> None :
606+ yaml = YAML ()
607+ dbt_project_dir = tmp_path / "dbt"
608+ dbt_project_dir .mkdir ()
609+ dbt_model_dir = dbt_project_dir / "models"
610+ dbt_model_dir .mkdir ()
611+
612+ model_contents = "SELECT 1 as id, 'test' as name"
613+ model_file = dbt_model_dir / "simple_model.sql"
614+ with open (model_file , "w" , encoding = "utf-8" ) as f :
615+ f .write (model_contents )
616+
617+ dbt_project_config = {
618+ "name" : "test_project" ,
619+ "version" : "1.0.0" ,
620+ "config-version" : 2 ,
621+ "profile" : "test" ,
622+ "model-paths" : ["models" ],
623+ }
624+ dbt_project_file = dbt_project_dir / "dbt_project.yml"
625+ with open (dbt_project_file , "w" , encoding = "utf-8" ) as f :
626+ yaml .dump (dbt_project_config , f )
627+
628+ sqlmesh_config = {
629+ "model_defaults" : {
630+ "start" : "2025-01-01" ,
631+ }
632+ }
633+ sqlmesh_config_file = dbt_project_dir / "sqlmesh.yaml"
634+ with open (sqlmesh_config_file , "w" , encoding = "utf-8" ) as f :
635+ yaml .dump (sqlmesh_config , f )
636+
637+ dbt_data_dir = tmp_path / "dbt_data"
638+ dbt_data_dir .mkdir ()
639+ dbt_data_file = dbt_data_dir / "local.db"
640+ dbt_profile_config = {
641+ "test" : {
642+ "outputs" : {"duckdb" : {"type" : "duckdb" , "path" : str (dbt_data_file )}},
643+ "target" : "duckdb" ,
644+ }
645+ }
646+ db_profile_file = dbt_project_dir / "profiles.yml"
647+ with open (db_profile_file , "w" , encoding = "utf-8" ) as f :
648+ yaml .dump (dbt_profile_config , f )
649+
650+ context = Context (paths = dbt_project_dir )
651+
652+ # find the model by its sqlmesh fully qualified name
653+ model_fqn = '"local"."main"."simple_model"'
654+ assert model_fqn in context .snapshots
655+
656+ # Verify that node_name is the equivalent dbt one
657+ model = context .snapshots [model_fqn ].model
658+ assert model .node_name == "model.test_project.simple_model"
0 commit comments