@@ -651,7 +651,7 @@ def audit(
651651 snapshot .snapshot_id ,
652652 wap_id ,
653653 )
654- self ._wap_publish_snapshot (snapshot , wap_id , deployability_index )
654+ self .wap_publish_snapshot (snapshot , wap_id , deployability_index )
655655
656656 return results
657657
@@ -806,8 +806,10 @@ def _evaluate_snapshot(
806806 }
807807
808808 wap_id : t .Optional [str ] = None
809- if snapshot .is_materialized and (
810- model .wap_supported or adapter .wap_supported (target_table_name )
809+ if (
810+ snapshot .is_materialized
811+ and target_table_exists
812+ and (model .wap_supported or adapter .wap_supported (target_table_name ))
811813 ):
812814 wap_id = random_id ()[0 :8 ]
813815 logger .info ("Using WAP ID '%s' for snapshot %s" , wap_id , snapshot .snapshot_id )
@@ -823,6 +825,7 @@ def _evaluate_snapshot(
823825 create_render_kwargs = create_render_kwargs ,
824826 rendered_physical_properties = rendered_physical_properties ,
825827 deployability_index = deployability_index ,
828+ target_table_name = target_table_name ,
826829 is_first_insert = is_first_insert ,
827830 batch_index = batch_index ,
828831 )
@@ -896,6 +899,17 @@ def create_snapshot(
896899 if on_complete is not None :
897900 on_complete (snapshot )
898901
902+ def wap_publish_snapshot (
903+ self ,
904+ snapshot : Snapshot ,
905+ wap_id : str ,
906+ deployability_index : t .Optional [DeployabilityIndex ],
907+ ) -> None :
908+ deployability_index = deployability_index or DeployabilityIndex .all_deployable ()
909+ table_name = snapshot .table_name (is_deployable = deployability_index .is_deployable (snapshot ))
910+ adapter = self .get_adapter (snapshot .model_gateway )
911+ adapter .wap_publish (table_name , wap_id )
912+
899913 def _render_and_insert_snapshot (
900914 self ,
901915 start : TimeLike ,
@@ -907,6 +921,7 @@ def _render_and_insert_snapshot(
907921 create_render_kwargs : t .Dict [str , t .Any ],
908922 rendered_physical_properties : t .Dict [str , exp .Expression ],
909923 deployability_index : DeployabilityIndex ,
924+ target_table_name : str ,
910925 is_first_insert : bool ,
911926 batch_index : int ,
912927 ) -> None :
@@ -916,7 +931,6 @@ def _render_and_insert_snapshot(
916931 logger .info ("Inserting data for snapshot %s" , snapshot .snapshot_id )
917932
918933 model = snapshot .model
919- table_name = snapshot .table_name (is_deployable = deployability_index .is_deployable (snapshot ))
920934 adapter = self .get_adapter (model .gateway )
921935 evaluation_strategy = _evaluation_strategy (snapshot , adapter )
922936
@@ -930,7 +944,7 @@ def _render_and_insert_snapshot(
930944 def apply (query_or_df : QueryOrDF , index : int = 0 ) -> None :
931945 if index > 0 :
932946 evaluation_strategy .append (
933- table_name = table_name ,
947+ table_name = target_table_name ,
934948 query_or_df = query_or_df ,
935949 model = snapshot .model ,
936950 snapshot = snapshot ,
@@ -948,10 +962,10 @@ def apply(query_or_df: QueryOrDF, index: int = 0) -> None:
948962 "Inserting batch (%s, %s) into %s'" ,
949963 time_like_to_str (start ),
950964 time_like_to_str (end ),
951- table_name ,
965+ target_table_name ,
952966 )
953967 evaluation_strategy .insert (
954- table_name = table_name ,
968+ table_name = target_table_name ,
955969 query_or_df = query_or_df ,
956970 is_first_insert = is_first_insert ,
957971 model = snapshot .model ,
@@ -1278,17 +1292,6 @@ def _cleanup_snapshot(
12781292 if on_complete is not None :
12791293 on_complete (table_name )
12801294
1281- def _wap_publish_snapshot (
1282- self ,
1283- snapshot : Snapshot ,
1284- wap_id : str ,
1285- deployability_index : t .Optional [DeployabilityIndex ],
1286- ) -> None :
1287- deployability_index = deployability_index or DeployabilityIndex .all_deployable ()
1288- table_name = snapshot .table_name (is_deployable = deployability_index .is_deployable (snapshot ))
1289- adapter = self .get_adapter (snapshot .model_gateway )
1290- adapter .wap_publish (table_name , wap_id )
1291-
12921295 def _audit (
12931296 self ,
12941297 audit : Audit ,
0 commit comments