Ë
    Ìi$  ã                   óØ   — d dl Z d dlmZmZmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZmZmZmZ  e j(                  e«      Z G d„ dee   ee   «      Z G d	„ d
ee   ee   «      Zy)é    N)ÚGenericÚListÚSequence)ÚSemanticManifestTÚSemanticModel)ÚSemanticModelReference)Ú
EntityType)ÚFileContextÚSemanticManifestValidationRuleÚSemanticModelContextÚSemanticModelValidationHelpersÚ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   fd	„«       «       Zy
)ÚSemanticModelValidityWindowRulez[Checks validity windows in semantic models to ensure they comply with runtime requirements.zKchecking correctness of the time dimension validity parameters in the model©Úwhats_being_doneÚsemantic_manifestÚreturnc                 óv   — g }| j                   D ]'  }|j                  t        j                  |¬«      «       Œ) |S )zKChecks the validity param definitions in every semantic model in the model.©Úsemantic_model)Úsemantic_modelsÚextendr   Ú_validate_semantic_model©r   Úissuesr   s      út/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/dbt_semantic_interfaces/validations/semantic_models.pyÚvalidate_manifestz1SemanticModelValidityWindowRule.validate_manifest   sC   € ð )+ˆà/×?Ñ?ò 	sˆNØ�M‰MÔ9×RÑRÐbpÐRÓqÕrð	sð ˆó    z]checking the semantic model's validity parameters for compatibility with runtime requirementsr   c                 óî  — g }| j                   D �cg c]  }|j                  €Œ|‘Œ }}|s|S t        t        j                  | j
                  ¬«      t        | j                  ¬«      ¬«      }d}|D �cg c]  }|j                  ‘Œ }}|D �cg c]2  }|j                  sŒ|j                  j                  sŒ'|j                  ‘Œ4 }}|D �cg c]2  }|j                  sŒ|j                  j                  sŒ'|j                  ‘Œ4 }}t        |«      }	t        |«      }
t        |«      dk(  r@|	dk(  r;|
dk(  r6t        |d| j                  › d|d   › d	|› d
�¬«      }|j                  |«       n�t        |«      dk7  r>t        |d| j                  › dt        |«      › d|› d|› �¬«      }|j                  |«       nC|	dk7  s|
dk7  r9g }t        |d| j                  › d|› d|› d|› d|› �
¬«      }|j                  |«       | j                  D �cg c]1  }|j                  t        j                   t        j"                  fv sŒ0|‘Œ3 }}t%        | j                  D �cg c]  }|j                  t        j&                  u ‘Œ  c}«      sGt        |d| j                  › d|D �cg c]  }|j                  ‘Œ c}› d�¬«      }|j                  |«       |r,t        |d| j                  › d�¬«      }|j                  |«       | j(                  rU| j(                  D �cg c]  }|j                  ‘Œ }}t        |d| j                  › d|› d|› d�¬«      }|j                  |«       |S c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )z_Runs assertions on semantic models with validity parameters set on one or more time dimensions.©Úmetadata©Úsemantic_model_name©Úfile_contextr   zÇSemantic models using dimension validity params to define a validity window must have exactly two time dimensions with validity params specified - one marked `is_start` and the other marked `is_end`.é   zSemantic model zA has a single validity param dimension that defines its window: `r   z4`. This is not a currently supported configuration! z¯ If you have one column defining a window, as in a daily snapshot table, you can define a separate dimension and increment the time value in the `expr` field as a work-around.©ÚcontextÚmessageé   z has z4 dimensions defined with validity params. They are: z‡. There must be either zero or two! If you wish to define a validity window for this semantic model, please follow these requirements: z| has two validity param dimensions defined, but does not have exactly one each marked with is_start and is_end! Dimensions: z. is_start dimensions: z. is_end dimensions: z. a   has validity param dimensions defined, but does not have an entity with type `natural` set. The natural key for this semantic model is what we use to process a validity window join. Primary or unique entities, if any, might be suitable for use as natural keys: (z).zú has validity param dimensions defined and also has one or more entities designated as `primary` or `unique`. This is not yet supported, as we do not currently process joins against these key types for semantic models with validity windows specified.z¤ has both measures and validity param dimensions defined. This is not currently supported! Please remove either the measures or the validity params. Measure names: z". Validity param dimension names: ú.)Ú
dimensionsÚvalidity_paramsr   r
   Úfrom_metadatar$   r   ÚnameÚis_startÚis_endÚlenr   ÚappendÚentitiesÚtyper	   ÚPRIMARYÚUNIQUEÚanyÚNATURALÚmeasures)r   r   ÚdimÚvalidity_param_dimsr+   ÚrequirementsÚvalidity_param_dimension_namesÚstart_dim_namesÚend_dim_namesÚnum_start_dimsÚnum_end_dimsÚerrorÚentityÚprimary_or_unique_entitiesÚmeasureÚmeasure_namess                   r   r   z8SemanticModelValidityWindowRule._validate_semantic_model"   s¿  € ð )+ˆà.<×.GÑ.GÖk sÈ3×K^ÑK^ÑKjšsÐkÐÐká"ØˆMä&Ü$×2Ñ2¸N×<SÑ<SÔTÜ1Àn×FYÑFYÔZô
ˆð
oð 	ð ?RÖ)R°s¨#¯(«(Ð)RÐ&Ð)Rà 3ö
Ø°s×7JÓ7JÈs×ObÑOb×OkÓOkˆC�H‹Hð
ˆð 
ð .AÖw cÀC×DWÓDWÐ\_×\oÑ\o×\vÓ\v˜Ÿ›ÐwˆÐwÜ˜_Ó-ˆÜ˜=Ó)ˆäÐ"Ó# qÒ(¨^¸qÒ-@À\ÐUVÒEVô $Øà% n×&9Ñ&9Ð%:ð ; Ø >¸qÑ AÐBÐBvØ#�nð %uðvôˆEð �M‰M˜%Õ ÜÐ$Ó%¨Ò*Ü#Øà% n×&9Ñ&9Ð%:¸%ÄÐDWÓ@XÐ?Yð Z2Ø2PÐ1Qð R%à%1 Nð4ôˆEð �M‰M˜%Õ Ø˜qÒ  L°AÒ$5à ˆOÜ#Øà% n×&9Ñ&9Ð%:ð ;Zà5Ð6Ð6MÈoÐM^Ð^sØ$�o R¨ ~ð7ôˆEð �M‰M˜%Ô ð "0×!8Ñ!8ö&
Ø¸F¿K¹KÌJ×L^ÑL^Ô`j×`qÑ`qÐKrÒ<rŠFð&
Ð"ð &
ô ÀN×D[ÑD[Ö\¸&�F—K‘K¤:×#5Ñ#5Ò5Ò\Ô]Ü#Øà% n×&9Ñ&9Ð%:ð ;-ð IcÖ-c¸f¨f¯k«kÒ-cÐ,dÐdfðhôˆEð �M‰M˜%Ô á%Ü#Øà% n×&9Ñ&9Ð%:ð ;!ð "ôˆEð �M‰M˜%Ô à×"Ò"à9G×9PÑ9PÖQ¨g˜WŸ\›\ÐQˆMÐQÜ#Øà% n×&9Ñ&9Ð%:ð ;&à&3 _Ð4VØ5Ð6°að9ôˆEð �M‰M˜%Ô àˆùòI lùò *Sùò
ùò xùòT&
ùò ]ùò .dùò& RsR   ‘M£MÁ2MÂMÂMÂ4MÃMÃMÃ1MÈ1M#È4M#É#M(ÊM-ÌM2N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   r    r   r   © r!   r   r   r      sw   „ ÙeàÙÐ&sÔtðÐ->ð À8ÈOÑC\ò ó uó ðð Ùðôðh°ð hÀ8ÈOÑC\ò hó	ó ñ
hr!   r   c                   ó€   — 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   fd	„«       «       Zy
)ÚSemanticModelDefaultsRulez#Checks defaults in semantic models.z8running model validation ensuring the defaults are validr   r   r   c                 óv   — g }| j                   D ]'  }|j                  t        j                  |¬«      «       Œ) |S )Nr   )r   r   rR   Ú$_validate_default_agg_time_dimensionr   s      r   r    z+SemanticModelDefaultsRule.validate_manifest•   sA   € ð )+ˆà/×?Ñ?ò 	yˆNØ�M‰MÔ3×XÑXÐhvÐXÓwÕxð	yàˆr!   zDchecking validity of the semantic model's default agg_time_dimensionr   c           
      ó€  — g }| j                   �| j                   j                  €g S | j                   j                  }t        j                  || ¬«      sj|j	                  t        t        t        j                  | j                  ¬«      t        | j                  ¬«      ¬«      d|› d| j                  › d�¬«      «       |S )	N)Útime_dimension_namer   r#   r%   r'   z5Default aggregation time dimension was specified as 'zC' which doesn't exist as a time dimension in semantic model named 'z'.r*   )ÚdefaultsÚagg_time_dimensionr   Útime_dimension_in_modelr6   r   r   r
   r1   r$   r   r2   )r   r   Údefault_agg_time_dimensions      r   rT   z>SemanticModelDefaultsRule._validate_default_agg_time_dimensionž   sÀ   € ð )+ˆà×"Ñ"Ð*¨n×.EÑ.E×.XÑ.XÐ.`ØˆIà%3×%<Ñ%<×%OÑ%OÐ"ä-×EÑEØ :È>õ
ð �M‰MÜÜ0Ü%0×%>Ñ%>È×H_ÑH_Ô%`Ü'=ÐR`×ReÑReÔ'fôð TÐTnÐSoð pRØR`×ReÑReÐQfÐfhðjôô	ð ˆr!   N)rK   rL   rM   rN   rO   r   r   r   r   r    r   rT   rP   r!   r   rR   rR   ’   sq   „ Ù-àÙÐ&`ÔaðÐ->ð À8ÈOÑC\ò ó bó ðð ÙÐ&lÔmð¸]ð ÈxÐXgÑOhò ó nó ñr!   rR   )ÚloggingÚtypingr   r   r   Ú!dbt_semantic_interfaces.protocolsr   r   Ú"dbt_semantic_interfaces.referencesr   Ú"dbt_semantic_interfaces.type_enumsr	   Ú5dbt_semantic_interfaces.validations.validator_helpersr
   r   r   r   r   r   r   Ú	getLoggerrK   Úloggerr   rR   rP   r!   r   ú<module>rc      su   ðÛ ß *Ñ *ç NÝ EÝ 9÷÷ ñ ð 
ˆ×	Ñ	˜8Ó	$€ô{Ð&DÐEVÑ&WÐY`ÐarÑYsô {ô|$Ð >Ð?PÑ QÐSZÐ[lÑSmõ $r!   