Ë
    ÌiG  ã                   óœ   — d dl mZmZmZmZ d dlmZmZmZ d dl	m
Z
mZ d dlmZmZ d dlmZmZmZmZmZmZmZmZ  G d„ dee   ee   «      Zy)	é    )ÚDictÚGenericÚListÚSequence)Ú	DimensionÚSemanticManifestTÚSemanticModel)ÚDimensionReferenceÚSemanticModelElementReference)ÚDimensionTypeÚTimeGranularity)ÚDimensionInvariantsÚFileContextÚSemanticManifestValidationRuleÚSemanticModelElementContextÚSemanticModelElementTypeÚValidationErrorÚValidationIssueÚvalidate_safelyc                   óÜ   — e Zd ZdZe ed¬«      dedee   fd„«       «       Z	e ed¬«      de
d	eeef   d
edee   fd„«       «       Ze ed¬«      d
edeeef   dedee   fd„«       «       Zy)ÚDimensionConsistencyRulezßChecks for consistent dimension properties in the semantic models in a model.

    * Dimensions with the same name should be of the same type.
    * Dimensions with the same name should be either all partitions or not.
    z7running model validation ensuring dimension consistency)Úwhats_being_doneÚsemantic_manifestÚreturnc                 óÂ   — i }i }g }| j                   D ]I  }|t        j                  ||d¬«      z  }|j                  D ]  }|t        j	                  |||¬«      z  }Œ ŒK |S )NT)Úsemantic_modelÚdimension_to_invariantÚupdate_invariant_dict)Ú	dimensionÚtime_dims_to_granularityr   )Úsemantic_modelsr   Ú_validate_semantic_modelÚ
dimensionsÚ_validate_dimension)r   r   r    Úissuesr   r   s         út/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/dbt_semantic_interfaces/validations/dimension_const.pyÚvalidate_manifestz*DimensionConsistencyRule.validate_manifest    s˜   € ð QSÐØNPÐ Ø(*ˆà/×?Ñ?ò 
	ˆNØÔ.×GÑGØ-ÐF\Ðtxð Hó ñ ˆFð ,×6Ñ6ò �	ØÔ2×FÑFØ'Ø-EØ#1ð Gó ñ ‘ñð
	ð ˆó    zqchecking that time dimensions of the same name that are not primary have the same time granularity specificationsr   r    r   c                 óz  — g }t        t        j                  |j                  ¬«      t	        |j
                  | j
                  ¬«      t        j                  ¬«      }| j                  t        j                  k(  rÂ| j                  |vr´| j                  r¨| j                  j                  || j                  <   | j                  �y| j                  j                  || j                     k7  rS|| j                     }|j                  t        |d| j
                  › d|j
                  › d|j
                  › d�¬«      «       |S )	aÈ  Check that time dimensions of the same name and aren't primary have the same time granularity.

        Args:
            dimension: the dimension to check
            time_dims_to_granularity: a dict from the dimension to the time granularity it should have
            semantic_model: the associated semantic model. Used for generated issue messages
        Throws: MdoValidationError if there is an inconsistent dimension in the semantic model.
        ©Úmetadata©Úsemantic_model_nameÚelement_name©Úfile_contextÚsemantic_model_elementÚelement_typezaTime granularity must be the same for time dimensions with the same name. Problematic dimension: z in semantic model with name: `z`. Expected granularity is ú.©ÚcontextÚmessage)r   r   Úfrom_metadatar+   r   Únamer   Ú	DIMENSIONÚtyper   ÚTIMEÚ	referenceÚtype_paramsÚtime_granularityÚappendr   )r   r    r   r%   r5   Úexpected_granularitys         r&   r$   z,DimensionConsistencyRule._validate_dimension4   s(  € ð$ )+ˆÜ-Ü$×2Ñ2¸N×<SÑ<SÔTÜ#@Ø$2×$7Ñ$7ÀiÇnÁnô$ô 2×;Ñ;ô
ˆð �>‰>œ]×/Ñ/Ò/Ø×"Ñ"Ð*BÑBÀy×G\ÒG\Ø@I×@UÑ@U×@fÑ@fÐ(¨×)<Ñ)<Ñ=ð ×)Ñ)Ð5Ø!×-Ñ-×>Ñ>ÐBZÐ[d×[nÑ[nÑBoÒoà+CÀI×DWÑDWÑ+XÐ(Ø—M‘MÜ'Ø$+ð'6Ø6?·n±nÐ5Eð F Ø .× 3Ñ 3Ð4Ð4OÐPd×PiÑPiÐOjÐjkð%môôð ˆr(   zTchecking that the semantic model has dimensions consistent with the given invariantsr   r   c                 ó.  — g }| j                   D �]‚  }|j                  |j                  «      }|€7|r4t        |j                  |j
                  xs d«      }|||j                  <   ŒWŒX|j
                  xs d}t        t        j                  | j                  ¬«      t        | j                  |j                  ¬«      t        j                  ¬«      }|j                  |j                  k7  rQ|j                  t        |d| j                  › d|j                  › d|j                  › d|j                  › d	�	¬
«      «       |j
                  |k7  s�Œ<|j                  t        |d| j                  › d|j                  › d|j
                  › d|› d�	¬
«      «       �Œ… |S )aä  Checks that the given semantic model has dimensions consistent with the given invariants.

        Args:
            semantic_model: the semantic model to check
            dimension_to_invariant: a dict from the dimension name to the properties it should have
            update_invariant_dict: whether to insert an entry into the dict if the given dimension name doesn't exist.
        Throws: MdoValidationError if there is an inconsistent dimension in the semantic model.
        Fr*   r,   r/   zIn semantic model `z `, type conflict for dimension `z` - already in model as type `z` but got `ú`r4   z4, conflicting is_partition attribute for dimension `z+` - already in model with is_partition as `z``)r#   Úgetr<   r   r:   Úis_partitionr   r   r7   r+   r   r8   r   r9   r?   r   )r   r   r   r%   r   Údimension_invariantrD   r5   s           r&   r"   z1DimensionConsistencyRule._validate_semantic_modelc   s¨  € ð" )+ˆà'×2Ñ2ó )	ˆIØ"8×"<Ñ"<¸Y×=PÑ=PÓ"QÐà"Ð*Ù(Ü*=¸i¿n¹nÈi×NdÑNdÒNmÐhmÓ*nÐ'ØBUÐ*¨9×+>Ñ+>Ñ?Øð ð %×1Ñ1Ò:°UˆLä1Ü(×6Ñ6À×@WÑ@WÔXÜ'DØ(6×(;Ñ(;È)Ï.É.ô(ô 6×?Ñ?ôˆGð #×'Ñ'¨9¯>©>Ò9Ø—‘Ü#Ø 'Ø"5°n×6IÑ6IÐ5Jð KØ%ŸN™NÐ+Ð+IÐJ]×JbÑJbÐIcð dØ%ŸN™NÐ+¨1ð!.ôôð #×/Ñ/°<Ô?Ø—‘Ü#Ø 'Ø"5°n×6IÑ6IÐ5Jð K&Ø&/×&9Ñ&9Ð%:ð ;2Ø2E×2RÑ2RÐ1Sð TØ(˜>¨ð!-ôöðC)	ðV ˆr(   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   r'   r   r   r
   r   r	   r$   r   Úboolr"   © r(   r&   r   r      sò   „ ñð ÙÐ&_Ô`ðÐ->ð À8ÈOÑC\ò ó aó ðð$ Ùð8ôð(Øð(à"&Ð'9¸?Ð'JÑ"Kð(ð &ð(ð 
�/Ñ	"ò	(ó	ó ð
(ðT ÙØoôð:Ø%ð:à $Ð%7Ð9LÐ%LÑ Mð:ð  $ð:ð 
�/Ñ	"ò	:óó ñ:r(   r   N)Útypingr   r   r   r   Ú!dbt_semantic_interfaces.protocolsr   r   r	   Ú"dbt_semantic_interfaces.referencesr
   r   Ú"dbt_semantic_interfaces.type_enumsr   r   Ú5dbt_semantic_interfaces.validations.validator_helpersr   r   r   r   r   r   r   r   r   rL   r(   r&   ú<module>rR      sM   ðß 0Ó 0÷ñ ÷
÷ N÷	÷ 	ó 	ôHÐ=Ð>OÑPÐRYÐZkÑRlõ Hr(   