Ë
    èlÖig*  ã                   óD  — d dl mZmZmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z(m)Z)m*Z* d dl+m,Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3m4Z4m5Z5  G d„ d«      Z6y)é    )ÚListÚOptionalÚSet)Údeprecations)ÚLEGACY_TIME_SPINE_GRANULARITYÚLEGACY_TIME_SPINE_MODEL_NAMEÚ'MINIMUM_REQUIRED_TIME_SPINE_GRANULARITY)ÚManifest)Ú	ModelNode)ÚArtifactWrittenÚSemanticValidationFailure)ÚParsingError)Ú	get_flags)Ú
write_file)Ú
EventLevel)Ú
fire_event)ÚPydanticMetric)ÚPydanticNodeRelation)ÚPydanticProjectConfiguration)ÚPydanticSavedQuery)ÚPydanticSemanticManifest)ÚPydanticSemanticModel)ÚPydanticTimeSpineÚ(PydanticTimeSpineCustomGranularityColumnÚPydanticTimeSpinePrimaryColumn)Ú#PydanticTimeSpineTableConfiguration)ÚTimeGranularity)ÚSemanticManifestValidator)ÚFileContextÚValidationErrorÚValidationIssueContextc                   ó@   — e Zd Zdeddfd„Zdefd„Zdefd„Zde	fd„Z
y)	ÚSemanticManifestÚmanifestÚreturnNc                 ó   — || _         y ©N)r$   )Úselfr$   s     új/var/www/html/strategist-ai/venv_dbt/lib/python3.12/site-packages/dbt/contracts/graph/semantic_manifest.pyÚ__init__zSemanticManifest.__init__/   s	   € Ø ˆ�ó    c           	      ó.  — | j                   j                  r| j                   j                  sy| j                  «       }t	        t
           «       }|j                  |«      }t        |j                  «      }t        «       }|j                  xs g D ]=  }dD ]6  }t        |j                  |«      }|sŒ|j                  |j                  «       Œ8 Œ? |rqt        «       j                  du rt!        j"                  d«       nEdj%                  |«      }	|j'                  t)        t+        t-        «       |	d¬«      d|	› d	�¬
«      «       |j.                  j0                  }
|j.                  j2                  }t5        d„ |
D «       «      }t        «       j6                  du r|r|st!        j"                  d«       |j8                  D ]!  }t;        t=        |j>                  ¬«      «       Œ# |D ]0  }t;        t=        |j>                  ¬«      t@        jB                  «       Œ2 | S )NT)ÚwindowÚgrain_to_dateFz%mf-cumulative-type-params-deprecationz, Úmetric)Úfile_contextÚobject_nameÚobject_typezÓCumulative fields `type_params.window` and `type_params.grain_to_date` should be nested under `type_params.cumulative_type_params.window` and `type_params.cumulative_type_params.grain_to_date`. Invalid metrics: zk. See documentation on behavior changes: https://docs.getdbt.com/reference/global-configs/behavior-changes.)ÚcontextÚmessagec              3   óp   K  — | ].  }|j                   j                  t        j                  k(  sŒ+|–— Œ0 y ­wr'   )Úprimary_columnÚtime_granularityr   ÚDAY)Ú.0Úcs     r)   ú	<genexpr>z,SemanticManifest.validate.<locals>.<genexpr>e   s.   è ø€ ò &
Ø a×&6Ñ&6×&GÑ&GÌ?×K^ÑK^Ó&^ŒAñ&
ùs   ‚,6¯6z'mf-timespine-without-yaml-configuration)Úmsg)"r$   ÚmetricsÚsemantic_modelsÚ_get_pydantic_semantic_manifestr   r   Úvalidate_semantic_manifestÚlistÚerrorsÚsetÚgetattrÚtype_paramsÚaddÚnamer   Ú%require_nested_cumulative_type_paramsr   ÚwarnÚjoinÚappendr    r!   r   Úproject_configurationÚtime_spinesÚtime_spine_table_configurationsÚanyÚ-require_yaml_configuration_for_mf_time_spinesÚwarningsr   r   r4   r   ÚERROR)r(   Úsemantic_manifestÚ	validatorÚvalidation_resultsÚvalidation_result_errorsÚmetrics_using_old_paramsr/   ÚfieldÚtype_params_field_valueÚnamesrM   Úlegacy_time_spinesÚtime_spines_contain_dayÚwarningÚerrors                  r)   ÚvalidatezSemanticManifest.validate2   s  € ð �}‰}×$Ò$¨D¯M©M×,IÒ,IØà ×@Ñ@ÓBÐÜ-Ô.FÑGÓIˆ	Ø&×AÑAÐBSÓTÐÜ#'Ð(:×(AÑ(AÓ#BÐ ä-0«UÐ Ø'×/Ñ/Ò5°2ò 	>ˆFØ4ò >�Ü*1°&×2DÑ2DÀeÓ*LÐ'â*Ø,×0Ñ0°·±Õ=ñ	>ð	>ñ $Ü‹{×@Ñ@ÀEÑIÜ×!Ñ!Ø;õð Ÿ	™	Ð":Ó;�Ø(×/Ñ/Ü#Ü 6ä)4«Ø(-Ø(0ô	!ð #vð  w|ð  v}ð  }hð  !iôô
ð (×=Ñ=×IÑIˆà×3Ñ3×SÑSð 	ô #&ñ &
Ø"ô&
ó #
Ðô ‹K×EÑEÈÑNÙ"Ù+ä×ÑØ9ôð *×2Ñ2ò 	GˆGÜÔ0°W·_±_ÔEÕFð	Gð .ò 	WˆEÜÔ0°U·]±]ÔCÄZ×EUÑEUÕVð	Wð ,Ð+Ð+r+   Ú	file_pathc                 ó°   — | j                  «       }|j                  «       }t        ||«       t        t	        | j
                  j                  |¬«      «       y )N)Úartifact_typeÚartifact_path)r?   Újsonr   r   r   Ú	__class__Ú__name__)r(   r`   rS   rd   s       r)   Úwrite_json_to_filez#SemanticManifest.write_json_to_filey   sC   € Ø ×@Ñ@ÓBÐØ ×%Ñ%Ó'ˆÜ�9˜dÔ#Ü”?°·±×1HÑ1HÐXaÔbÕcr+   c                 ó¸  — g }d }| j                   j                  j                  «       D �]s  }t        |t        «      r|j
                  sŒ!|j
                  }d }|j                  j                  «       D ]  }|j                  |j                  k(  sŒ|} n |st        d«      ‚|j                  st        d«      ‚t        t        |j                  |j                  |j                  |j                   ¬«      t#        |j                  |j                  ¬«      |j$                  D �cg c]#  }t'        |j                  |j(                  ¬«      ‘Œ% c}¬«      }|j+                  |«       |r-|j                  j-                  «       |j-                  «       k  s�Œh|j                  }�Œv t/        g |¬«      }	t1        g g |	¬«      }
| j                   j2                  j                  «       D ]>  }|
j2                  j+                  t5        j6                  |j9                  «       «      «       Œ@ | j                   j:                  j                  «       D ]>  }|
j:                  j+                  t=        j6                  |j9                  «       «      «       Œ@ | j                   j>                  j                  «       D ]>  }|
j>                  j+                  tA        j6                  |j9                  «       «      «       Œ@ d }| j                   j2                  rÓ| j                   jB                  jE                  tF        d d | j                   «      }|r-|r%tI        j,                  «       |j-                  «       k  rtH        }|r%|j-                  «       tK        j,                  «       kD  rt        d	«      ‚|r:|j
                  €.tM        |j                   d
tH        ¬«      }|g|
jN                  _(        |
S c c}w )Nz„Expected to find time spine standard granularity column in model columns, but did not. This should have been caught in YAML parsing.z‡Expected to find granularity set for time spine standard granularity column, but did not. This should have been caught in YAML parsing.)ÚaliasÚschema_nameÚdatabaseÚrelation_name)rG   r7   )rG   Úcolumn_name)Únode_relationr6   Úcustom_granularities)rN   rM   )r=   r>   rL   zìThe semantic layer requires a time spine model with granularity DAY or smaller in the project, but none was found. Guidance on creating this model can be found on our docs site (https://docs.getdbt.com/docs/build/metricflow-time-spine).Údate_day)Úlocationrm   Úgrain))r$   ÚnodesÚvaluesÚ
isinstancer   Ú
time_spineÚcolumnsrG   Ústandard_granularity_columnr   Úgranularityr   r   ri   Úschemark   rl   r   ro   r   rm   rK   Úto_intr   r   r>   r   Ú	parse_objÚto_dictr=   r   Úsaved_queriesr   Ú
ref_lookupÚfindr   r   r	   ÚLegacyTimeSpinerL   rN   )r(   Úpydantic_time_spinesÚminimum_time_spine_granularityÚnoderv   rx   ÚcolumnÚcustom_granularityÚpydantic_time_spineÚproject_configÚpydantic_semantic_manifestÚsemantic_modelr/   Úsaved_queryÚlegacy_time_spine_modelÚlegacy_time_spines                   r)   r?   z0SemanticManifest._get_pydantic_semantic_manifest   s’  € Ø8:ÐØDHÐ&Ø—M‘M×'Ñ'×.Ñ.Ó0ó ,	YˆDÜ˜t¤YÔ/°D·O²OØØŸ™ˆJØ*.Ð'ØŸ,™,×-Ñ-Ó/ò �Ø—;‘; *×"HÑ"HÓHØ28Ð/Ùðñ
 /Ü"ðDóð ð /×:Ò:Ü"ðDóð ô #4Ü2ØŸ*™*Ø $§¡Ø!Ÿ]™]Ø"&×"4Ñ"4ô	ô  >Ø#×?Ñ?Ø%@×%LÑ%Lô ð /9×.MÑ.Mö	&ð +ô =Ø/×4Ñ4ÐBT×B`ÑB`öò&ô#Ðð$ !×'Ñ'Ð(;Ô<á2Ø.×:Ñ:×AÑAÓCØ0×7Ñ7Ó9ô:ð 2M×1XÑ1XÒ.ðY,	Yô\ 6Ø,.Ð<Pô
ˆô &>Ø¨À.ô&
Ð"ð #Ÿm™m×;Ñ;×BÑBÓDò 	ˆNØ&×6Ñ6×=Ñ=Ü%×/Ñ/°×0FÑ0FÓ0HÓIõð	ð
 —m‘m×+Ñ+×2Ñ2Ó4ò 	bˆFØ&×.Ñ.×5Ñ5´n×6NÑ6NÈvÏ~É~ÓO_Ó6`Õað	bð  Ÿ=™=×6Ñ6×=Ñ=Ó?ò 	ˆKØ&×4Ñ4×;Ñ;Ü"×,Ñ,¨[×-@Ñ-@Ó-BÓCõð	ð
 8<ÐØ�=‰=×(Ò(Ø&*§m¡m×&>Ñ&>×&CÑ&CÜ,¨d°D¸$¿-¹-ó'Ð#ñ 'á6Ü4×;Ñ;Ó=Ø4×;Ñ;Ó=ò>ô 6SÐ2ñ 3Ø1×8Ñ8Ó:Ü9×@Ñ@ÓBòCô #ðRóð ñ 'Ð+B×+MÑ+MÐ+UÜ$3Ø4×BÑBØ *Ü7ô%Ð!ð &ðdÐ*×@Ñ@Ô`ð *Ð)ùòO&s   Ä!(O)rf   Ú
__module__Ú__qualname__r
   r*   Úboolr_   Ústrrg   r   r?   © r+   r)   r#   r#   .   sA   „ ð! ð !¨dó !ðE,˜$ó E,ðNd¨Có dði*Ð1Iô i*r+   r#   N)7Útypingr   r   r   Údbtr   Údbt.constantsr   r   r	   Údbt.contracts.graph.manifestr
   Údbt.contracts.graph.nodesr   Údbt.events.typesr   r   Údbt.exceptionsr   Ú	dbt.flagsr   Údbt_common.clients.systemr   Údbt_common.events.base_typesr   Údbt_common.events.functionsr   Ú.dbt_semantic_interfaces.implementations.metricr   Ú5dbt_semantic_interfaces.implementations.node_relationr   Ú=dbt_semantic_interfaces.implementations.project_configurationr   Ú3dbt_semantic_interfaces.implementations.saved_queryr   Ú9dbt_semantic_interfaces.implementations.semantic_manifestr   Ú6dbt_semantic_interfaces.implementations.semantic_modelr   Ú2dbt_semantic_interfaces.implementations.time_spiner   r   r   ÚFdbt_semantic_interfaces.implementations.time_spine_table_configurationr   r�   Ú"dbt_semantic_interfaces.type_enumsr   Ú?dbt_semantic_interfaces.validations.semantic_manifest_validatorr   Ú5dbt_semantic_interfaces.validations.validator_helpersr   r    r!   r#   r’   r+   r)   ú<module>r©      s}   ðß &Ñ &å ÷ñ õ
 2Ý /ß GÝ 'Ý Ý 0Ý 3Ý 2Ý IÝ Võõ Sõõ Y÷ñ õ
õ ?õ÷ñ ÷z*ò z*r+   