Ë
    èlÖi7B  ã                   óz  — d dl Z d dlZd dlZd dlmZ d dl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mZmZmZmZmZmZ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%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8 erd dl9Z9ee:e;f   Z<eZ= G d„ de j|                  ¬«      Z?y)é    N)Úsleep)ÚSpawnContext)ÚRLock)Ú	get_ident)ÚAnyÚCallableÚContextManagerÚDictÚHashableÚIterableÚListÚOptionalÚTupleÚTypeÚUnionÚTYPE_CHECKING)Úget_node_info)Ú
fire_event)ÚDbtInternalErrorÚNotImplementedError)Úcast_to_str)ÚMacroQueryStringSetter)ÚAdapterRequiredConfigÚAdapterResponseÚ
ConnectionÚConnectionStateÚ
IdentifierÚ
LazyHandle)ÚAdapterLogger)ÚConnectionClosedÚConnectionClosedInCleanupÚConnectionLeftOpenÚConnectionLeftOpenInCleanupÚConnectionReusedÚNewConnectionÚRollbackÚRollbackFailed)ÚFailedToConnectErrorÚInvalidConnectionErrorc                   ó0  — e Zd ZU dZeZeed<   dede	ddfd„Z
deeef   ddfd	„Zedefd
„«       Zdefd„Zdeddfd„Zdee   fd„Zd2d„Zd2d„Zd2d„Zej4                  dedefd„«       Zd3dee   defd„Ze	 	 	 d4dedeg e f   de!de"e#e$      de%de&ee%ge'f   e'f   de%defd„«       Z(ej4                  dee)e      fd„«       Z*eej4                  dedefd„«       «       Z+d2d „Z,d2d!„Z-ej4                  d2d"„«       Z.ej4                  d2d#„«       Z/ededdfd$„«       Z0ededdfd%„«       Z1ededdfd&„«       Z2ededefd'„«       Z3d2d(„Z4dedefd)„Z5ej4                  	 	 	 d5ded*e6d+e6d,ee%   de7e8d-f   f
d.„«       Z9dede7eef   fd/„Z:ed0e&e%ef   defd1„«       Z;y)6ÚBaseConnectionManagera  Methods to implement:
        - exception_handler
        - cancel_open
        - open
        - begin
        - commit
        - clear_transaction
        - execute

    You must also set the 'TYPE' class attribute with a class-unique constant
    string.
    ÚTYPEÚprofileÚ
mp_contextÚreturnNc                 óX   — || _         i | _        |j                  «       | _        d | _        y ©N)r-   Úthread_connectionsr   ÚlockÚquery_header)Úselfr-   r.   s      úb/var/www/html/strategist-ai/venv_dbt/lib/python3.12/site-packages/dbt/adapters/base/connections.pyÚ__init__zBaseConnectionManager.__init__K   s)   € ØˆŒØ>@ˆÔØ%×+Ñ+Ó-ˆŒ	Ø>BˆÕó    Úquery_header_contextc                 ó:   — t        | j                  |«      | _        y r1   )r   r-   r4   )r5   r9   s     r6   Úset_query_headerz&BaseConnectionManager.set_query_headerQ   s   € Ü2°4·<±<ÐAUÓVˆÕr8   c                  ó>   — t        j                  «       t        «       fS r1   )ÚosÚgetpidr   © r8   r6   Úget_thread_identifierz+BaseConnectionManager.get_thread_identifierT   s   € ô �y‰y‹{œI›KÐ'Ð'r8   c                 óÞ   — | j                  «       }| j                  5  || j                  vrt        |t	        | j                  «      «      ‚| j                  |   cd d d «       S # 1 sw Y   y xY wr1   )r@   r3   r2   r)   Úlist©r5   Úkeys     r6   Úget_thread_connectionz+BaseConnectionManager.get_thread_connectionZ   s`   € Ø×(Ñ(Ó*ˆØ�Y‰Yñ 	0Ø˜$×1Ñ1Ñ1Ü,¨S´$°t×7NÑ7NÓ2OÓPÐPØ×*Ñ*¨3Ñ/÷	0÷ 	0ò 	0ús   �<A#Á#A,Úconnc                 ót   — | j                  «       }|| j                  v rt        d«      ‚|| j                  |<   y )Nz;In set_thread_connection, existing connection exists for {})r@   r2   r   )r5   rF   rD   s      r6   Úset_thread_connectionz+BaseConnectionManager.set_thread_connectiona   s:   € Ø×(Ñ(Ó*ˆØ�$×)Ñ)Ñ)Ü"Ð#`ÓaÐaØ'+ˆ×Ñ Ò$r8   c                 óœ   — | j                  «       }| j                  5  | j                  j                  |«      cd d d «       S # 1 sw Y   y xY wr1   )r@   r3   r2   ÚgetrC   s     r6   Úget_if_existsz#BaseConnectionManager.get_if_existsg   s@   € Ø×(Ñ(Ó*ˆØ�Y‰Yñ 	4Ø×*Ñ*×.Ñ.¨sÓ3÷	4÷ 	4ò 	4ús   �AÁAc                 óœ   — | j                  «       }| j                  5  || j                  v r| j                  |= d d d «       y # 1 sw Y   y xY wr1   )r@   r3   r2   rC   s     r6   Úclear_thread_connectionz-BaseConnectionManager.clear_thread_connectionl   sH   € Ø×(Ñ(Ó*ˆØ�Y‰Yñ 	1Ø�d×-Ñ-Ñ-Ø×+Ñ+¨CÐ0÷	1÷ 	1ñ 	1ús   �AÁAc                 ó¤   — | j                  «       }|�>|j                  r| j                  |«       | j                  «        | j	                  «        yy)z Clear any existing transactions.N)rE   Útransaction_openÚ	_rollbackÚbeginÚcommit©r5   rF   s     r6   Úclear_transactionz'BaseConnectionManager.clear_transactionr   sB   € à×)Ñ)Ó+ˆØÐØ×$Ò$Ø—‘˜tÔ$Ø�J‰JŒLØ�K‰K�Mð	 r8   c                 ó€   — | j                  «       }|�,|j                  r|j                  r| j                  |«       y y y y r1   )rK   ÚhandlerO   rP   rS   s     r6   Úrollback_if_openz&BaseConnectionManager.rollback_if_open{   s;   € Ø×!Ñ!Ó#ˆØÐ §¢°×0EÒ0EØ�N‰N˜4Õ ð 1F Ðr8   Úsqlc                 ó   — t        d«      ‚)a8  Create a context manager that handles exceptions caused by database
        interactions.

        :param str sql: The SQL string that the block inside the context
            manager is executing.
        :return: A context manager that handles exceptions raised by the
            underlying database.
        z8`exception_handler` is not implemented for this adapter!©r   ©r5   rX   s     r6   Úexception_handlerz'BaseConnectionManager.exception_handler€   s   € ô "Ð"\Ó]Ð]r8   Únamec                 ó|  — |€dn|}| j                  «       }|r |j                  |k(  r|j                  dk(  r|S |€œt        t	        | j
                  «      |t        j                  dd| j                  j                  ¬«      }t        | j                  «      |_        | j                  |«       t        t        || j
                  t!        «       ¬«      «       |S |j                  dk7  rt        | j                  «      |_        |j                  |k7  r-|j                  xs d}||_        t        t#        ||¬«      «       |S )	zØCalled by 'acquire_connection' in BaseAdapter, which is called by
        'connection_named'.
        Creates a connection for this thread if one doesn't already
        exist, and will rename an existing connection.NÚmasterÚopenF)Útyper]   ÚstaterO   rV   Úcredentials)Ú	conn_nameÚ	conn_typeÚ	node_infoÚ )Úorig_conn_namerd   )rK   r]   rb   r   r   r,   r   ÚINITr-   rc   r   r`   rV   rH   r   r%   r   r$   )r5   r]   rd   rF   rh   s        r6   Úset_connection_namez)BaseConnectionManager.set_connection_nameŒ   s  € ð &* \™°tˆ	ð ×!Ñ!Ó#ˆá�D—I‘I Ò*¨t¯z©z¸VÒ/CàˆKàˆ<äÜ §	¡	Ó*ØÜ%×*Ñ*Ø!&ØØ ŸL™L×4Ñ4ôˆDô % T§Y¡YÓ/ˆDŒKà×&Ñ& tÔ,ÜÜ¨	¸T¿Y¹YÔR_ÓRaÔbôð ˆð �z‰z˜VÒ#Ü(¨¯©Ó3�”Ø�y‰y˜IÒ%Ø&*§i¡i¢o°2�Ø%�”	ÜÔ+¸>ÐU^Ô_Ô`àˆr8   Ú
connectionÚconnectÚloggerÚretryable_exceptionsÚretry_limitÚretry_timeoutÚ	_attemptsc                 óÒ  — t        |«      r ||«      n|}|dk  rt        d«      ‚|dk  s|t        j                  «       kD  r'd|_        t
        j                  |_        t        d«      ‚	  |«       |_        t
        j                  |_        |S # t        |«      $ r�}	|dk  r0d|_        t
        j                  |_        t        t        |	«      «      ‚|j                  d| j                  › d|› d|› d|	› �«       t        |«       | j                  ||||d	z
  |||d	z   ¬
«      cY d}	~	S d}	~	wt        $ r5}	d|_        t
        j                  |_        t        t        |	«      «      ‚d}	~	ww xY w)aÝ  Given a Connection, set its handle by calling connect.

        The calls to connect will be retried up to retry_limit times to deal with transient
        connection errors. By default, one retry will be attempted if retryable_exceptions is set.

        :param Connection connection: An instance of a Connection that needs a handle to be set,
            usually when attempting to open it.
        :param connect: A callable that returns the appropiate connection handle for a
            given adapter. This callable will be retried retry_limit times if a subclass of any
            Exception in retryable_exceptions is raised by connect.
        :type connect: Callable[[], AdapterHandle]
        :param AdapterLogger logger: A logger to emit messages on retry attempts or errors. When
            handling expected errors, we call debug, and call warning on unexpected errors or when
            all retry attempts have been exhausted.
        :param retryable_exceptions: An iterable of exception classes that if raised by
            connect should trigger a retry.
        :type retryable_exceptions: Iterable[Type[Exception]]
        :param int retry_limit: How many times to retry the call to connect. If this limit
            is exceeded before a successful call, a FailedToConnectError will be raised.
            Must be non-negative.
        :param retry_timeout: Time to wait between attempts to connect. Can also take a
            Callable that takes the number of attempts so far, beginning at 0, and returns an int
            or float to be passed to time.sleep.
        :type retry_timeout: Union[Callable[[int], SleepTime], SleepTime] = 1
        :param int _attempts: Parameter used to keep track of the number of attempts in calling the
            connect function across recursive calls. Passed as an argument to retry_timeout if it
            is a Callable. This parameter should not be set by the initial caller.
        :raises dbt.adapters.exceptions.FailedToConnectError: Upon exhausting all retry attempts without
            successfully acquiring a handle.
        :return: The given connection with its appropriate state and handle attributes set
            depending on whether we successfully acquired a handle or not.
        r   z;retry_timeout cannot be negative or return a negative time.Nzretry_limit cannot be negativez0Got a retryable error when attempting to open a z connection.
z! attempts remaining. Retrying in z seconds.
Error:
é   )rk   rl   rm   ro   rp   rn   rq   )Úcallabler(   ÚsysÚgetrecursionlimitrV   r   ÚFAILrb   ÚOPENÚtupleÚstrÚdebugr,   r   Úretry_connectionÚ	Exception)
Úclsrk   rl   rm   rn   ro   rp   rq   ÚtimeoutÚes
             r6   r|   z&BaseConnectionManager.retry_connectionµ   ss  € ôV /7°}Ô.E‘- 	Ô*È=ˆØ�QŠ;Ü&ØMóð ð ˜Š?˜k¬C×,AÑ,AÓ,CÒCà $ˆJÔÜ.×3Ñ3ˆJÔÜ&Ð'GÓHÐHð	/Ù '£	ˆJÔÜ.×3Ñ3ˆJÔØÐøäÐ)Ó*ò 	Ø˜aÒØ$(�
Ô!Ü#2×#7Ñ#7�
Ô Ü*¬3¨q«6Ó2Ð2à�L‰LØBÀ3Ç8Á8À*ÈNØ�-Ð@ÀÀ	ð JØ˜#ðôô �'ŒNØ×'Ñ'Ø%ØØØ'¨!™OØ+Ø%9Ø# a™-ð (ó õ ûô ò 	/Ø $ˆJÔÜ.×3Ñ3ˆJÔÜ&¤s¨1£vÓ.Ð.ûð	/ús+   Á*"B ÂE&ÂBD%ÄE&Ä%E&Ä10E!Å!E&c                 ó   — t        d«      ‚)z6Cancel all open connections on the adapter. (passable)z2`cancel_open` is not implemented for this adapter!rZ   ©r5   s    r6   Úcancel_openz!BaseConnectionManager.cancel_open  s   € ô "Ð"VÓWÐWr8   c                 ó   — t        d«      ‚)a/  Open the given connection on the adapter and return it.

        This may mutate the given connection (in particular, its state and its
        handle).

        This should be thread-safe, or hold the lock if necessary. The given
        connection should not be in either in_use or available.
        z+`open` is not implemented for this adapter!rZ   ©r~   rk   s     r6   r`   zBaseConnectionManager.open  s   € ô "Ð"OÓPÐPr8   c                 óà   — | j                   5  | j                  «       }|€
	 d d d «       y 	 d d d «       	 | j                  «       y # 1 sw Y   ŒxY w# t        $ r | j	                  «        ‚ w xY wr1   )r3   rK   Úcloser}   rM   rS   s     r6   ÚreleasezBaseConnectionManager.release  ss   € Ø�Y‰Yñ 	Ø×%Ñ%Ó'ˆDØˆ|Ø÷	ð 	à÷	ð
	ð �J‰J�tÕ÷	ð 	ûô ò 	à×(Ñ(Ô*Øð	ús   �A´A ÁAÁA-c           	      ó˜  — | j                   5  | j                  j                  «       D ]r  }|j                  dvr)t	        t        t        |j                  «      ¬«      «       n(t	        t        t        |j                  «      ¬«      «       | j                  |«       Œt | j                  j                  «        d d d «       y # 1 sw Y   y xY w)N>   ÚinitÚclosed)rd   )r3   r2   Úvaluesrb   r   r#   r   r]   r!   r‡   Úclear©r5   rk   s     r6   Úcleanup_allz!BaseConnectionManager.cleanup_all.  sœ   € Ø�Y‰Yñ 		,Ø"×5Ñ5×<Ñ<Ó>ò '�
Ø×#Ñ#Ð+=Ñ=ÜÔ:Ä[ÐQ[×Q`ÑQ`ÓEaÔbÕcäÔ8Ä;ÈzÏÉÓC_Ô`ÔaØ—
‘
˜:Õ&ð'ð ×#Ñ#×)Ñ)Ô+÷		,÷ 		,ñ 		,ús   �B*C Ã C	c                 ó   — t        d«      ‚)zBegin a transaction. (passable)z,`begin` is not implemented for this adapter!rZ   r‚   s    r6   rQ   zBaseConnectionManager.begin:  s   € ô "Ð"PÓQÐQr8   c                 ó   — t        d«      ‚)z Commit a transaction. (passable)z-`commit` is not implemented for this adapter!rZ   r‚   s    r6   rR   zBaseConnectionManager.commit?  s   € ô "Ð"QÓRÐRr8   c           	      óà   — 	 |j                   j                  «        y# t        $ rG t        t	        t        |j                  «      t        j                  «       t        «       ¬«      «       Y yw xY w)z&Perform the actual rollback operation.)rd   Úexc_inforf   N)
rV   Úrollbackr}   r   r'   r   r]   Ú	tracebackÚ
format_excr   r…   s     r6   Ú_rollback_handlez&BaseConnectionManager._rollback_handleD  sU   € ð		Ø×Ñ×&Ñ&Õ(øÜò 	ÜÜÜ)¨*¯/©/Ó:Ü&×1Ñ1Ó3Ü+›oôöð	ús   ‚ �AA-Á,A-c                 ó*  — t        |j                  d«      rLt        t        t	        |j
                  «      t        «       ¬«      «       |j                  j                  «        yt        t        t	        |j
                  «      t        «       ¬«      «       y)z#Perform the actual close operation.r‡   ©rd   rf   N)	ÚhasattrrV   r   r    r   r]   r   r‡   r"   r…   s     r6   Ú_close_handlez#BaseConnectionManager._close_handleR  sg   € ô �:×$Ñ$ gÔ.ÜÜ ¬;°z·±Ó+GÔS`ÓSbÔcôð ×Ñ×#Ñ#Õ%äÜ"Ü)¨*¯/©/Ó:ÄmÃoôõr8   c                 óä   — |j                   du rt        d|j                  › d�«      ‚t        t	        t        |j                  «      t        «       ¬«      «       | j                  |«       d|_         y)zRoll back the given connection.Fz-Tried to rollback transaction on connection "z!", but it does not have one open!r™   N)rO   r   r]   r   r&   r   r   r—   r…   s     r6   rP   zBaseConnectionManager._rollbackb  si   € ð ×&Ñ&¨%Ñ/Ü"ðØ—O‘OÐ$Ð$EðGóð ô
 	”8¤k°*·/±/Ó&BÌmËoÔ^Ô_Ø×Ñ˜ZÔ(à&+ˆ
Õ#r8   c                 óp  — |j                   t        j                  t        j                  hv r|S |j                  rN|j
                  rBt        t        t        |j                  «      t        «       ¬«      «       | j                  |«       d|_        | j                  |«       t        j                  |_         |S )Nr™   F)rb   r   ÚCLOSEDri   rO   rV   r   r&   r   r]   r   r—   r›   r…   s     r6   r‡   zBaseConnectionManager.closep  sŽ   € ð ×Ñ¤× 6Ñ 6¼×8LÑ8LÐMÑMØÐà×&Ò&¨:×+<Ò+<Ü”x¬+°j·o±oÓ*FÔR_ÓRaÔbÔcØ× Ñ  Ô,Ø&+ˆ
Ô#à×Ñ˜*Ô%Ü*×1Ñ1ˆ
ÔàÐr8   c                 óJ   — | j                  «       }|r| j                  «        yy)z?If the named connection exists, commit the current transaction.N)rK   rR   rŽ   s     r6   Úcommit_if_has_connectionz.BaseConnectionManager.commit_if_has_connection€  s!   € à×'Ñ'Ó)ˆ
ÙØ�K‰K�Mð r8   c                 óT   — | j                   €|S | j                   j                  |«      S r1   )r4   Úaddr[   s     r6   Ú_add_query_commentz(BaseConnectionManager._add_query_comment†  s*   € Ø×ÑÐ$ØˆJØ× Ñ ×$Ñ$ SÓ)Ð)r8   Ú
auto_beginÚfetchÚlimitzagate.Tablec                 ó   — t        d«      ‚)a·  Execute the given SQL.

        :param str sql: The sql to execute.
        :param bool auto_begin: If set, and dbt is not currently inside a
            transaction, automatically begin one.
        :param bool fetch: If set, fetch results.
        :param int limit: If set, limits the result set
        :return: A tuple of the query status and results (empty if fetch=False).
        :rtype: Tuple[AdapterResponse, agate.Table]
        z.`execute` is not implemented for this adapter!rZ   )r5   rX   r¤   r¥   r¦   s        r6   ÚexecutezBaseConnectionManager.execute‹  s   € ô$ "Ð"RÓSÐSr8   c                 ó   — t        d«      ‚)a¦  
        This was added here because base.impl.BaseAdapter.get_column_schema_from_query expects it to be here.
        That method wouldn't work unless the adapter used sql.impl.SQLAdapter, sql.connections.SQLConnectionManager
        or defined this method on <Adapter>ConnectionManager before passing it in to <Adapter>Adapter.

        See https://github.com/dbt-labs/dbt-core/issues/8396 for more information.
        z7`add_select_query` is not implemented for this adapter!rZ   r[   s     r6   Úadd_select_queryz&BaseConnectionManager.add_select_queryŸ  s   € ô "Ð"[Ó\Ð\r8   Ú	type_codec                 ó   — t        d«      ‚)zBGet the string representation of the data type from the type_code.z=`data_type_code_to_name` is not implemented for this adapter!rZ   )r~   r«   s     r6   Údata_type_code_to_namez,BaseConnectionManager.data_type_code_to_name©  s   € ô "Ð"aÓbÐbr8   )r/   Nr1   )rs   rs   r   )FFN)<Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚNotImplementedr,   rz   Ú__annotations__r   r   r7   r
   r   r;   Ústaticmethodr   r@   r   rE   rH   r   rK   rM   rT   rW   ÚabcÚabstractmethodr	   r\   rj   Úclassmethodr   ÚAdapterHandler   r   r   r}   Úintr   Ú	SleepTimer|   r   rƒ   r`   rˆ   r�   rQ   rR   r—   r›   rP   r‡   r    r£   Úboolr   r   r¨   rª   r­   r?   r8   r6   r+   r+   ;   sŠ  … ñð €Dˆ#ÓðCÐ 5ð CÀ<ð CÐTXó CðW°T¸#¸s¸(±^ð WÈó Wð ð( 8ò (ó ð(ð
0 zó 0ð,¨*ð ,¸ó ,ð4˜x¨
Ñ3ó 4ó
1óó!ð
 	×Ñð	^ Sð 	^¨^ò 	^ó ð	^ñ'¨°©ð 'Àó 'ðR ð ØFGØñU/àðU/ð ˜"˜mÐ+Ñ,ðU/ð ð	U/ð
 ' t¨I¡Ñ7ðU/ð ðU/ð ˜X s e¨YÐ&6Ñ7¸ÐBÑCðU/ð ðU/ð 
òU/ó ðU/ðn 	×ÑðX˜X d¨3¡iÑ0ò Xó ðXð Ø×Ñð	Q˜jð 	Q¨Zò 	Qó ó ð	Qóó
,ð 	×ÑòRó ðRð 	×ÑòSó ðSð ð¨*ð ¸ò ó ðð ð zð °dò ó ðð ð, :ð ,°$ò ,ó ð,ð ð˜zð ¨jò ó ðóð* cð *¨có *ð
 	×Ñð !ØØ#ñTàðTð ðTð ð	Tð
 ˜‰}ðTð 
ˆ Ð-Ñ	.òTó ðTð&] Cð ]¨E°*¸c°/Ñ,Bó ]ð ðc¨u°S¸#°X©ð cÀ3ò có ñcr8   r+   )Ú	metaclass)@rµ   r=   ru   Útimer   r•   Úmultiprocessing.contextr   Úmultiprocessing.synchronizer   Ú	threadingr   Útypingr   r   r	   r
   r   r   r   r   r   r   r   r   Údbt_common.events.contextvarsr   Údbt_common.events.functionsr   Údbt_common.exceptionsr   r   Údbt_common.utilsr   Údbt.adapters.base.query_headersr   Ú!dbt.adapters.contracts.connectionr   r   r   r   r   r   Údbt.adapters.events.loggingr   Údbt.adapters.events.typesr    r!   r"   r#   r$   r%   r&   r'   Údbt.adapters.exceptionsr(   r)   Úagater¹   Úfloatrº   r¸   ÚABCMetar+   r?   r8   r6   ú<module>rÎ      s•   ðÛ 
Û 	Û 
Ý Û Ý 0Ý -Ý ÷÷ ÷ ó õ 8Ý 2ß GÝ (å B÷÷ õ 6÷	÷ 	ó 	÷ QáÛð �#�u�*Ñ€	Ø€ôrc c§k¡kö rcr8   