Ë
    Ìi?  ã                   óü   — d dl mZmZ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mZ d dlmZmZ d dlmZ d d	l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" d„ Z#d„ Z$ G d„ de«      Z% G d„ de%«      Z&y)é    )ÚListÚOptionalÚSetÚTuple)Úselected_resources)ÚManifest)ÚGraphMemberNode)ÚPreviousState)ÚNoNodesForSelectionCriteriaÚSelectorReportInvalidSelector)ÚDbtInternalErrorÚInvalidSelectorError)ÚNodeType)Ú
fire_eventÚwarn_or_erroré   )ÚGraphÚUniqueId)Ú
GraphQueue)ÚMethodManager)ÚIndirectSelectionÚSelectionCriteriaÚSelectionSpecc                 ób   — t        | D �cg c]  }|j                  d«      d   ‘Œ c}«      S c c}w )Nú.r   )ÚsetÚsplit)ÚnodesÚnodes     úS/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/dbt/graph/selector.pyÚget_package_namesr!      s(   € Ü¨uÖ5 t�—
‘
˜3“ Ó"Ò5Ó6Ð6ùÒ5s   Š,c                 ó|   — | j                   t        j                  k(  ry| j                   t        j                  k(  ryy)zæIf a node is not selected itself, but its parent(s) are, it may qualify
    for indirect selection.
    Today, only Test nodes can be indirectly selected. In the future,
    other node types or invocation flags might qualify.
    TF)Úresource_typer   ÚTestÚUnit)r   s    r    Úcan_select_indirectlyr&      s1   € ð ×ÑœXŸ]™]Ò*ØØ	×	Ñ	œxŸ}™}Ò	,Øàó    c                   ó*  ‡ — e Zd ZdZ	 	 d!dededee   deddf
ˆ fd„Z	d	e
e   d
ede
e   fd„Zd
edee
e   e
e   f   fd„Zd
ede
e   de
e   fd„Z	 d"d
ededee
e   e
e   f   fd„Z	 d"d
ededee
e   e
e   f   fd„Zdedefd„Zdedefd„Zdedefd„Zdedefd„Zde
e   de
e   fd„Zej6                  fde
e   dedee
e   e
e   f   fd„Z e«       ej6                  fde
e   de
e   dede
e   fd„Zd"d
edede
e   fd„Zd"d
edede fd „Z!ˆ xZ"S )#ÚNodeSelectorz4The node selector is aware of the graph and manifestNÚgraphÚmanifestÚprevious_stateÚinclude_empty_nodesÚreturnc                 óþ   •— t         ‰| �  ||«       || _        || _        | j                  j	                  «       D �ch c]  }| j                  |«      sŒ|’Œ }}| j                  j                  |«      | _        y c c}w ©N)ÚsuperÚ__init__Ú
full_graphr-   r   Ú_is_graph_memberÚsubgraphr*   )Úselfr*   r+   r,   r-   Ú	unique_idÚgraph_membersÚ	__class__s          €r    r2   zNodeSelector.__init__'   sw   ø€ ô 	‰Ñ˜ >Ô2Ø!&ˆŒØ)<ˆÔ ð
 (,§¡×'<Ñ'<Ó'>ö
Ø#À$×BWÑBWÐXaÕBbŠIð
ˆð 
ð —_‘_×-Ñ-¨mÓ<ˆ�
ùò
s   ¼A:ÁA:Úincluded_nodesÚspecc                 ó˜   — | j                  |j                  |j                  «      }t        |j	                  ||j
                  «      «      S )zsSelect the explicitly included nodes, using the given spec. Return
        the selected set of unique IDs.
        )Ú
get_methodÚmethodÚmethod_argumentsr   ÚsearchÚvalue)r6   r:   r;   r>   s       r    Úselect_includedzNodeSelector.select_included9   s8   € ð —‘ §¡¨d×.CÑ.CÓDˆÜ�6—=‘= °·±Ó<Ó=Ð=r'   c                 óö  — | j                   j                  «       }	 | j                  ||«      }| j                  ||«      }||z  }|j                  t        j                  k(  r|t        «       fS | j                  ||j                  ¬«      \  }}||fS # t        $ r] dj	                  | j
                  «      }t        t        ||j                  |j                  ¬«      «       t        «       t        «       fcY S w xY w)zÌGet all nodes specified by the single selection criteria.

        - collect the directly included nodes
        - find their specified relatives
        - perform any selector-specific expansion
        z, )Úvalid_selectorsÚspec_methodÚraw_spec)ÚselectedÚindirect_selection)r*   r   rB   r   ÚjoinÚSELECTOR_METHODSr   r   r>   Úrawr   Úcollect_specified_neighborsrH   r   ÚEmptyÚexpand_selection)	r6   r;   r   Ú	collectedrD   Ú	neighborsrG   Údirect_nodesÚindirect_nodess	            r    Úget_nodes_from_criteriaz$NodeSelector.get_nodes_from_criteriaD   sø   € ð —
‘
× Ñ Ó"ˆð		 Ø×,Ñ,¨U°DÓ9ˆIð ×4Ñ4°T¸9ÓEˆ	Ø˜yÑ(ˆð ×"Ñ"Ô&7×&=Ñ&=Ò=ØœS›U�?Ð"à+/×+@Ñ+@Ø!°d×6MÑ6Mð ,Aó ,Ñ(ˆL˜.ð   Ð/Ð/øô' $ò 	 Ø"Ÿi™i¨×(=Ñ(=Ó>ˆOÜÜ-Ø$3ÀÇÁÐW[×W_ÑW_ôôô
 “5œ#›%�<Òð	 ús   œB ÂA#C8Ã7C8rG   c                 ó’  — t        «       }|j                  r*|j                  | j                  j	                  |«      «       |j
                  r7|j                  }|j                  | j                  j                  ||«      «       |j                  r7|j                  }|j                  | j                  j                  ||«      «       |S )a
  Given the set of models selected by the explicit part of the
        selector (like "tag:foo"), apply the modifiers on the spec ("+"/"@").
        Return the set of additional nodes that should be collected (which may
        overlap with the selected set).
        )r   Úchildrens_parentsÚupdater*   Úselect_childrens_parentsÚparentsÚparents_depthÚselect_parentsÚchildrenÚchildren_depthÚselect_children)r6   r;   rG   Ú
additionalÚdepths        r    rL   z(NodeSelector.collect_specified_neighborsf   s™   € ô %(£Eˆ
Ø×!Ò!Ø×Ñ˜dŸj™j×AÑAÀ(ÓKÔLà�<Š<Ø×&Ñ&ˆEØ×Ñ˜dŸj™j×7Ñ7¸À%ÓHÔIà�=Š=Ø×'Ñ'ˆEØ×Ñ˜dŸj™j×8Ñ8¸À5ÓIÔJØÐr'   Úwarn_on_no_nodesc                 ó$  — t        |t        «      r| j                  |«      \  }}||fS |j                  D �cg c]  }| j	                  ||¬«      ‘Œ }}g }g }|D ]*  \  }	}
|j                  |	«       |j                  |	|
z  «       Œ, |j                  |«      }|j                  |«      }| j                  |||j                  «      }|j                  r8t        |«      dk(  r*|r(t        t        t        |j                  «      ¬«      «       ||fS c c}w )zàIf the spec is a composite spec (a union, difference, or intersection),
        recurse into its selections and combine them. If the spec is a concrete
        selection criteria, resolve that using the given graph.
        ©r;   r`   r   )Úspec_raw)Ú
isinstancer   rS   Ú
componentsÚselect_nodes_recursivelyÚappendÚcombinedÚincorporate_indirect_nodesrH   Úexpect_existsÚlenr   r   ÚstrrK   )r6   r;   r`   rQ   rR   Ú	componentÚbundlesÚdirect_setsÚindirect_setsÚdirectÚindirectÚinitial_directs               r    rf   z%NodeSelector.select_nodes_recursively{   s!  € ô �dÔ-Ô.Ø+/×+GÑ+GÈÓ+MÑ(ˆL˜.ð0 ˜^Ð+Ð+ð) "&§¡öàð ×-Ñ-°9ÐO_Ð-Õ`ðˆGð ð
 ˆKØˆMà$+ò 8Ñ �˜Ø×"Ñ" 6Ô*Ø×$Ñ$ V¨hÑ%6Õ7ð8ð "Ÿ]™]¨;Ó7ˆNØ!Ÿ]™]¨=Ó9ˆNà×:Ñ:Ø °×0GÑ0GóˆLð ×!Ò!¤c¨,Ó&7¸1Ò&<ÑAQÜÔ9Ä3ÀtÇxÁxÃ=ÔQÔRà˜^Ð+Ð+ùò-s   ·Dc                 óX   — | j                  ||¬«      \  }}|j                  |«      }||fS )a  Select the nodes in the graph according to the spec.

        This is the main point of entry for turning a spec into a set of nodes:
        - Recurse through spec, select by criteria, combine by set operation
        - Return final (unfiltered) selection set
        rb   )rf   Ú
difference)r6   r;   r`   rQ   rR   Úindirect_onlys         r    Úselect_nodeszNodeSelector.select_nodes�   sB   € ð (,×'DÑ'DØÐ(8ð (Eó (
Ñ$ˆ�nð '×1Ñ1°,Ó?ˆØ˜]Ð*Ð*r'   r7   c                 ót  — || j                   j                  v r/| j                   j                  |   }|j                  j                  S || j                   j                  v ry|| j                   j
                  v r/| j                   j
                  |   }|j                  j                  S || j                   j                  v r/| j                   j                  |   }|j                  j                  S || j                   j                  v r/| j                   j                  |   }|j                  j                  S || j                   j                  v r/| j                   j                  |   }|j                  j                  S || j                   j                  v r/| j                   j                  |   }|j                  j                  S || j                   j                  v r/| j                   j                  |   }|j                  j                  S | j                   j                  |   }	|	j                  j                  S )NT)r+   ÚsourcesÚconfigÚenabledÚ	exposuresÚ	functionsÚmetricsÚsemantic_modelsÚ
unit_testsÚsaved_queriesr   )
r6   r7   ÚsourceÚfunctionÚmetricÚsemantic_modelÚ	unit_testÚsaved_queryÚexposurer   s
             r    r4   zNodeSelector._is_graph_member¬   s»  € Ø˜Ÿ™×-Ñ-Ñ-Ø—]‘]×*Ñ*¨9Ñ5ˆFØ—=‘=×(Ñ(Ð(Ø˜$Ÿ-™-×1Ñ1Ñ1ØØ˜$Ÿ-™-×1Ñ1Ñ1Ø—}‘}×.Ñ.¨yÑ9ˆHØ—?‘?×*Ñ*Ð*Ø˜$Ÿ-™-×/Ñ/Ñ/Ø—]‘]×*Ñ*¨9Ñ5ˆFØ—=‘=×(Ñ(Ð(Ø˜$Ÿ-™-×7Ñ7Ñ7Ø!Ÿ]™]×:Ñ:¸9ÑEˆNØ!×(Ñ(×0Ñ0Ð0Ø˜$Ÿ-™-×2Ñ2Ñ2ØŸ™×0Ñ0°Ñ;ˆIØ×#Ñ#×+Ñ+Ð+Ø˜$Ÿ-™-×5Ñ5Ñ5ØŸ-™-×5Ñ5°iÑ@ˆKØ×%Ñ%×-Ñ-Ð-Ø˜$Ÿ-™-×1Ñ1Ñ1Ø—}‘}×.Ñ.¨yÑ9ˆHØ—?‘?×*Ñ*Ð*à—=‘=×&Ñ& yÑ1ˆDØ—;‘;×&Ñ&Ð&r'   c                 ó~   — || j                   j                  v r%| j                   j                  |   }|j                  S y©NF)r+   r   Úempty©r6   r7   r   s      r    Ú_is_empty_nodezNodeSelector._is_empty_nodeÈ   s5   € Ø˜Ÿ™×+Ñ+Ñ+Ø—=‘=×&Ñ& yÑ1ˆDØ—:‘:Ðàr'   r   c                  ó   — y)z�Determine if a node is a match for the selector. Non-match nodes
        will be excluded from results during filtering.
        T© ©r6   r   s     r    Únode_is_matchzNodeSelector.node_is_matchÏ   s   € ð r'   c                 óh  — || j                   j                  v r| j                   j                  |   }�no|| j                   j                  v r| j                   j                  |   }�n<|| j                   j                  v r| j                   j                  |   }�n	|| j                   j                  v r| j                   j                  |   }n×|| j                   j
                  v r| j                   j
                  |   }n¥|| j                   j                  v r| j                   j                  |   }ns|| j                   j                  v r| j                   j                  |   }nA|| j                   j                  v r| j                   j                  |   }nt        d|› d�«      ‚| j                  |«      S )NzNode z not found in the manifest!)r+   r   ry   r|   r}   r~   r   r€   r�   r   r‘   rŒ   s      r    Ú	_is_matchzNodeSelector._is_matchÕ   sX  € à˜Ÿ™×+Ñ+Ñ+Ø—=‘=×&Ñ& yÑ1ŠDØ˜$Ÿ-™-×/Ñ/Ñ/Ø—=‘=×(Ñ(¨Ñ3ŠDØ˜$Ÿ-™-×1Ñ1Ñ1Ø—=‘=×*Ñ*¨9Ñ5ŠDØ˜$Ÿ-™-×1Ñ1Ñ1Ø—=‘=×*Ñ*¨9Ñ5‰DØ˜$Ÿ-™-×/Ñ/Ñ/Ø—=‘=×(Ñ(¨Ñ3‰DØ˜$Ÿ-™-×7Ñ7Ñ7Ø—=‘=×0Ñ0°Ñ;‰DØ˜$Ÿ-™-×2Ñ2Ñ2Ø—=‘=×+Ñ+¨IÑ6‰DØ˜$Ÿ-™-×5Ñ5Ñ5Ø—=‘=×.Ñ.¨yÑ9‰Dä" U¨9¨+Ð5PÐ#QÓRÐRØ×!Ñ! $Ó'Ð'r'   c                 óˆ   — |D �ch c]2  }| j                  |«      r| j                  s| j                  |«      s|’Œ4 c}S c c}w )zWReturn the subset of selected nodes that is a match for this
        selector.
        )r“   r-   r�   )r6   rG   r7   s      r    Úfilter_selectionzNodeSelector.filter_selectionë   sF   € ð &ö
àØ�~‰~˜iÔ(Ø×)Ò)°×1DÑ1DÀYÔ1Oò ò
ð 	
ùò 
s   …7?rH   c                 óò  — t        |«      }t        «       }t        «       }|t        j                  k(  rM|j                  | j                  j                  |«      «      j                  | j                  j                  «      }| j                  j                  |«      D �]V  }|| j                  j                  v s|| j                  j                  v sŒ5|| j                  j                  v r| j                  j                  |   }n1|| j                  j                  v r| j                  j                  |   }t        «      sŒ¤|t        j                  k(  s!t        |j                  «      t        |«      k  r|j                  |«       Œê|t        j                  k(  r4t        |j                  «      t        |«      k  r|j                  |«       �Œ1|t        j                  k(  r�ŒF|j                  |«       �ŒY ||fS r0   )r   r   Ú	BuildableÚunionr*   rZ   r+   ry   Úselect_successorsr   r€   r&   ÚEagerÚdepends_on_nodesÚaddrM   )r6   rG   rH   rQ   rR   Úselected_and_parentsr7   r   s           r    rN   zNodeSelector.expand_selectionö   s£  € ô4 ˜8“}ˆÜ›ˆÜ"›uÐØÔ!2×!<Ñ!<Ò<Ø#+§>¡>°$·*±*×2KÑ2KÈHÓ2UÓ#V×#\Ñ#\Ø—‘×%Ñ%ó$Ð ð Ÿ™×5Ñ5°hÓ?ó 	6ˆIØ˜DŸM™M×/Ñ/Ñ/°9ÀÇÁ×@XÑ@XÒ3XØ §¡× 3Ñ 3Ñ3ØŸ=™=×.Ñ.¨yÑ9‘DØ $§-¡-×":Ñ":Ñ:ØŸ=™=×3Ñ3°IÑ>�Dô )¨Õ.à)Ô->×-DÑ-DÒDÌØ×-Ñ-óIä˜X›òI'ð %×(Ñ(¨Õ3Ø+Ô/@×/JÑ/JÒJÌsØ×-Ñ-óPäÐ1Ó2òP3ð %×(Ñ(¨Ö3Ø+Ô/@×/FÑ/FÒFÙà&×*Ñ*¨9Ö5ð+	6ð. ˜^Ð+Ð+r'   rQ   rR   c                 ó¢  — t        |«      t        |«      k(  r|S t        |«      }|t        j                  k(  rn|D ]g  }|| j                  j                  v sŒ| j                  j                  |   }t        |j
                  «      t        |«      k  sŒW|j                  |«       Œi |S |t        j                  k(  r–|j                  | j                  j                  |«      «      }|D ]g  }|| j                  j                  v sŒ| j                  j                  |   }t        |j
                  «      t        |«      k  sŒW|j                  |«       Œi |S r0   )r   r   ÚCautiousr+   r   r›   rœ   r—   r˜   r*   rZ   )r6   rQ   rR   rH   rG   r7   r   r�   s           r    ri   z'NodeSelector.incorporate_indirect_nodes1  s$  € ô ˆ|Ó¤ NÓ 3Ò3ØÐä�|Ó$ˆàÔ!2×!;Ñ!;Ò;Ø+ò 0�	Ø §¡× 3Ñ 3Ò3ØŸ=™=×.Ñ.¨yÑ9�DÜ˜4×0Ñ0Ó1´S¸³]ÓBØ Ÿ™ YÕ/ð	0ð ˆð  Ô#4×#>Ñ#>Ò>Ø#+§>¡>°$·*±*×2KÑ2KÈHÓ2UÓ#VÐ Ø+ò 0�	Ø §¡× 3Ñ 3Ò3ØŸ=™=×.Ñ.¨yÑ9�DÜ˜4×0Ñ0Ó1´SÐ9MÓ5NÓNØ Ÿ™ YÕ/ð	0ð ˆr'   c                 óT   — | j                  ||¬«      \  }}| j                  |«      }|S )af  get_selected runs through the node selection process:

        - node selection. Based on the include/exclude sets, the set
            of matched unique IDs is returned
            - includes direct + indirect selection (for tests)
        - filtering:
            - selectors can filter the nodes after all of them have been
              selected
        rb   )rw   r•   )r6   r;   r`   Úselected_nodesrv   Úfiltered_nodess         r    Úget_selectedzNodeSelector.get_selectedP  s<   € ð )-×(9Ñ(9ØÐ(8ð ):ó )
Ñ%ˆ˜ð ×.Ñ.¨~Ó>ˆàÐr'   Úpreserve_edgesc                 óÈ   — | j                  |«      }t        j                  |«       | j                  j	                  |«      }t        |j                  | j                  ||«      S )z^Returns a queue over nodes in the graph that tracks progress of
        dependencies.
        )r£   r   Úset_selected_resourcesr3   Úget_subset_graphr   r*   r+   )r6   r;   r¤   r¡   Ú	new_graphs        r    Úget_graph_queuezNodeSelector.get_graph_queuea  sO   € ð
 ×*Ñ*¨4Ó0ˆä×1Ñ1°.ÔAà—O‘O×4Ñ4°^ÓDˆ	ä˜)Ÿ/™/¨4¯=©=¸.È.ÓYÐYr'   rŠ   )T)#Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r
   Úboolr2   r   r   r   rB   r   rS   rL   r   rf   rw   r4   r�   r	   r‘   r“   r•   r   rš   rN   r   ri   r£   r   r©   Ú__classcell__©r9   s   @r    r)   r)   $   s[  ø„ Ù>ð 37Ø$)ñ=àð=ð ð=ð ! Ñ/ð	=ð
 "ð=ð 
õ=ð$	>à˜H™ð	>ð  ð	>ð 
ˆX‰ó		>ð 0Ø%ð 0à	ˆs�8‰}˜c (™mÐ+Ñ	,ó 0ðDØ%ðØ14°X±ðà	ˆX‰óð, =Añ ,Ø!ð ,Ø59ð ,à	ˆs�8‰}˜c (™mÐ+Ñ	,ó ,ðF =Añ+Ø!ð+Ø59ð+à	ˆs�8‰}˜c (™mÐ+Ñ	,ó+ð'¨(ð '°tó 'ð8¨ð °Tó ð /ð °dó ð( 8ð (°ó (ð,	
¨¨X©ð 	
¸3¸x¹=ó 	
ð 1B×0GÑ0Gñ9,à�h‘-ð9,ð .ð9,ð 
ˆs�8‰}˜c (™mÐ+Ñ	,ó	9,ñ| ),«Ø0A×0GÑ0Gñ	à˜(‘mðð ˜H™ðð .ð	ð
 
ˆX‰óñ> ð À$ð ÐRUÐV^ÑR_ó ñ"Z Mð ZÀ4ð ZÐS]÷ Zr'   r)   c                   óN   ‡ — e Zd Z	 d
dededee   dee   de	ddfˆ fd„Z
d	„ Zˆ xZS )ÚResourceTypeSelectorr*   r+   r,   Úresource_typesr-   r.   Nc                 óL   •— t         ‰| �  ||||¬«       t        |«      | _        y )N)r*   r+   r,   r-   )r1   r2   r   r³   )r6   r*   r+   r,   r³   r-   r9   s         €r    r2   zResourceTypeSelector.__init__p  s2   ø€ ô 	‰ÑØØØ)Ø 3ð	 	ô 	
ô .1°Ó-@ˆÕr'   c                 ó2   — |j                   | j                  v S r0   )r#   r³   r�   s     r    r‘   z"ResourceTypeSelector.node_is_match€  s   € Ø×!Ñ! T×%8Ñ%8Ð8Ð8r'   )F)rª   r«   r¬   r   r   r   r
   r   r   r®   r2   r‘   r¯   r°   s   @r    r²   r²   o  s\   ø„ ð %*ñAàðAð ðAð ! Ñ/ð	Að
 ˜X™ðAð "ðAð 
õAö 9r'   r²   N)'Útypingr   r   r   r   Údbtr   Údbt.contracts.graph.manifestr   Údbt.contracts.graph.nodesr	   Údbt.contracts.stater
   Údbt.events.typesr   r   Údbt.exceptionsr   r   Údbt.node_typesr   Údbt_common.events.functionsr   r   r*   r   r   Úqueuer   Úselector_methodsr   Úselector_specr   r   r   r!   r&   r)   r²   r�   r'   r    ú<module>rÂ      sY   ðß -Ó -å "Ý 1Ý 5Ý -ß Wß AÝ #ß Aç "Ý Ý +ß NÑ Nò7òôHZ�=ô HZôV
9˜<õ 9r'   