
    5                     B   d Z ddlZddlZddl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 eZej                   dkD  rej"                  Z G d d	      Z	 	 	 dd
ej&                  deeeej&                        eeeej&                        df   f   dee   dee   deddfdZy)z BQ CLI helper functions for IDs.    N)AnyOptionalTupleTypeUnion)app)bq_error)
stringutil)      c                      e Zd ZdZd Z G d dej                        Z G d de      Z G d de      Z	 G d	 d
e      Z
 G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Zy))*ApiClientHelperzGStatic helper methods and classes not provided by the discovery client.c                     t        d      )Nz/Cannot instantiate static class ApiClientHelper)NotImplementedError)selfunused_argsunused_kwdss       platform/bq/utils/bq_id_utils.py__init__zApiClientHelper.__init__   s    
O
PP    c                   z    e Zd ZdZ e       Z e       ZdZd Ze	de
dd fd       Zd Zd Zd	 Zd
 Zd Zd Zd Zy)ApiClientHelper.Referencez7Base class for Reference objects returned by apiclient. c                 x   t        |       t        j                  k(  rd| _        t	        d      | j
                  D ]I  }|j                  |d      s%t        d|d| j                  j                        t        | |||          K | j                  D ]%  }|j                  |d      st        | |||          ' y )Nunimplementedz;Cannot instantiate abstract class ApiClientHelper.Referencer   zMissing required argument z to )typer   	Referencetypenamer   _required_fieldsget
ValueError	__class____name__setattr_optional_fields)r   kwdsnames      r   r   z"ApiClientHelper.Reference.__init__   s    	d00	0,!I
 	
 ''$xxb!t~~..0  	dDJ' ( ''$88D"
$d4j
) (r   r&   returnc                 X     t         fd|j                         D              }  di |S )zFactory method for this class.c              3   z   K   | ]2  \  }}|j                   j                  j                        v r||f 4 y wN)r   unionr%   ).0kvclss      r   	<genexpr>z3ApiClientHelper.Reference.Create.<locals>.<genexpr>2   s@      "da#&&,,S-A-ABB a&"s   8; )dictitems)r0   r&   argss   `  r   Createz ApiClientHelper.Reference.Create/   s0      jjl d
 [4[r   c                 ^    t        | j                  j                  | j                              S r+   )iterr   r,   r%   r   s    r   __iter__z"ApiClientHelper.Reference.__iter__9   s$    $''--d.C.CDEEr   c                     || j                   v r|| j                  v r| j                  |   S y || j                  v r| j                  |   S t        |      r+   )r%   __dict__r   KeyError)r   keys     r   __getitem__z%ApiClientHelper.Reference.__getitem__<   sU    	%%	%$--s#
#	%%	%}}S!!SMr   c                 *    t        t        |             S r+   )hashstrr9   s    r   __hash__z"ApiClientHelper.Reference.__hash__F   s    #d)_r   c                 ^    t        | j                  j                  | j                              S r+   )lenr   r,   r%   r9   s    r   __len__z!ApiClientHelper.Reference.__len__I   s$    &&,,T-B-BCDDr   c                 X    t        j                  | j                  t        |       z        S r+   )r
   
ensure_str_format_strr3   r9   s    r   __str__z!ApiClientHelper.Reference.__str__L   s"    ""4#3#3d4j#@AAr   c                 &    | j                   d| dS )Nz '')r   r9   s    r   __repr__z"ApiClientHelper.Reference.__repr__O   s    --..r   c                      t        |      t         fd j                  j                   j                        D              S )Nc              3   ^   K   | ]$  }t        |d       j                  |d       k(   & y wr+   )getattrr    )r-   r'   dr   s     r   r1   z3ApiClientHelper.Reference.__eq__.<locals>.<genexpr>T   s2      Hd $d
#quuT4'8
8Hs   *-)r3   allr   r,   r%   )r   otherrQ   s   ` @r   __eq__z ApiClientHelper.Reference.__eq__R   s=    
u+a ++11$2G2GH  r   N)r#   
__module____qualname____doc__	frozensetr   r%   rI   r   classmethodr   r6   r:   r?   rC   rF   rJ   rM   rT   r2   r   r   r   r      sh    A { {K*$ C $?  FEB/r   r   c                   R     e Zd ZdZ ed      Z ed      ZdZdZ fdZ	ddZ
 xZS )	ApiClientHelper.JobReferencezA JobReference.)	projectIdjobId)locationz%(projectId)s:%(jobId)sjobc                 L    |d   | _         |d   | _        t        |   di | y )Nr\   r]   r2   )r\   r]   superr   r   r&   r"   s     r   r   z%ApiClientHelper.JobReference.__init__a   s*     -dnWdjgr   c                 V    t         j                  j                  | j                        S Nr\   r   ProjectReferencer6   r\   r9   s    r   GetProjectReferencez0ApiClientHelper.JobReference.GetProjectReferenceh        --44t~~4NNr   r(    ApiClientHelper.ProjectReference)r#   rU   rV   rW   rX   r   r%   rI   r   r   rh   __classcell__r"   s   @r   JobReferencer[   Y   s2     !78 /+KHOr   rn   c                   ^     e Zd ZdZ ed      ZdZdZ fdZde	ddfd	Z
de	d
e	ddfdZ xZS )rk   zA ProjectReference.re   z%(projectId)sprojectc                 8    |d   | _         t        |   di | y )Nr\   r2   )r\   ra   r   rb   s     r   r   z)ApiClientHelper.ProjectReference.__init__r   s     -dngr   
dataset_idr(    ApiClientHelper.DatasetReferencec                 X    t         j                  j                  | j                  |      S Nr\   	datasetId)r   DatasetReferencer6   r\   )r   rr   s     r   GetDatasetReferencez4ApiClientHelper.ProjectReference.GetDatasetReferencex   s+     --44NNj 5  r   table_idApiClientHelper.TableReferencec                 Z    t         j                  j                  | j                  ||      S Nr\   rw   tableId)r   TableReferencer6   r\   )r   rr   rz   s      r   GetTableReferencez2ApiClientHelper.ProjectReference.GetTableReference   s-     ++22NNj( 3  r   )r#   rU   rV   rW   rX   r   rI   r   r   rB   ry   r   rl   rm   s   @r   rg   z ApiClientHelper.ProjectReferencek   sR     0!KH	+),	)r   rg   c                   R     e Zd ZdZ ed      ZdZdZ fdZddZ	de
dd	fd
Z xZS )rs   zA DatasetReference.rv   z%(projectId)s:%(datasetId)sdatasetc                 L    |d   | _         |d   | _        t        |   di | y )Nr\   rw   r2   )r\   rw   ra   r   rb   s     r   r   z)ApiClientHelper.DatasetReference.__init__   s+     -dn -dngr   r(   c                 V    t         j                  j                  | j                        S rd   rf   r9   s    r   rh   z4ApiClientHelper.DatasetReference.GetProjectReference   ri   r   rz   r{   c                 n    t         j                  j                  | j                  | j                  |      S r}   )r   r   r6   r\   rw   )r   rz   s     r   r   z2ApiClientHelper.DatasetReference.GetTableReference   s1     ++22NNdnnh 3  r   rj   )r#   rU   rV   rW   rX   r   rI   r   r   rh   rB   r   rl   rm   s   @r   rx   z ApiClientHelper.DatasetReference   s<     !;</KHO	)r   rx   c                   J     e Zd ZdZ ed      ZdZdZ fdZddZ	d	dZ
 xZS )
r{   zA TableReference.r~   z'%(projectId)s:%(datasetId)s.%(tableId)stablec                 `    |d   | _         |d   | _        |d   | _        t        |   di | y )Nr\   rw   r   r2   )r\   rw   r   ra   r   rb   s     r   r   z'ApiClientHelper.TableReference.__init__   6     -dn -dny/dlgr   c                 l    t         j                  j                  | j                  | j                        S ru   )r   rx   r6   r\   rw   r9   s    r   ry   z2ApiClientHelper.TableReference.GetDatasetReference   s-    --44NNdnn 5  r   c                 V    t         j                  j                  | j                        S rd   rf   r9   s    r   rh   z2ApiClientHelper.TableReference.GetProjectReference   ri   r   )r(   rs   rj   )r#   rU   rV   rW   rX   r   rI   r   r   ry   rh   rl   rm   s   @r   r   zApiClientHelper.TableReference   s,     !FG;KH
Or   r   c                   6     e Zd Z ed      ZdZdZ fdZ xZS )ApiClientHelper.ModelReference)r\   rw   modelIdz'%(projectId)s:%(datasetId)s.%(modelId)smodelc                 `    |d   | _         |d   | _        |d   | _        t        |   di | y )Nr\   rw   r   r2   )r\   rw   r   ra   r   rb   s     r   r   z'ApiClientHelper.ModelReference.__init__   r   r   	r#   rU   rV   rX   r   rI   r   r   rl   rm   s   @r   ModelReferencer      s#     !FG;KH r   r   c                   J     e Zd ZdZ ed      ZdZdZdZ fdZ	de
fdZ xZS )	 ApiClientHelper.RoutineReferencezA RoutineReference.)r\   rw   	routineIdz)%(projectId)s:%(datasetId)s.%(routineId)szDprojects/%(projectId)s/datasets/%(datasetId)s/routines/%(routineId)sroutinec                 `    |d   | _         |d   | _        |d   | _        t        |   di | y )Nr\   rw   r   r2   )r\   rw   r   ra   r   rb   s     r   r   z)ApiClientHelper.RoutineReference.__init__   s7     -dn -dn -dngr   r(   c                 2    | j                   t        |       z  S r+   	_path_strr3   r9   s    r   pathz%ApiClientHelper.RoutineReference.path       ^^d4j((r   r#   rU   rV   rW   rX   r   rI   r   r   r   rB   r   rl   rm   s   @r   RoutineReferencer      s7     !HI=KN  H)c )r   r   c                   6     e Zd Z ed      ZdZdZ fdZ xZS )(ApiClientHelper.RowAccessPolicyReference)r\   rw   r   policyIdz4%(projectId)s:%(datasetId)s.%(tableId)s.%(policyId)szrow access policyc                 t    |d   | _         |d   | _        |d   | _        |d   | _        t	        |   di | y )Nr\   rw   r   r   r2   )r\   rw   r   r   ra   r   rb   s     r   r   z1ApiClientHelper.RowAccessPolicyReference.__init__   sB     -dn -dny/dl
+dmgr   r   rm   s   @r   RowAccessPolicyReferencer      s(     9 IK"H r   r   c                   6     e Zd Z ed      ZdZdZ fdZ xZS )'ApiClientHelper.TransferConfigReference)transferConfigNamez%(transferConfigName)sztransfer configc                 8    |d   | _         t        |   di | y )Nr   r2   )r   ra   r   rb   s     r   r   z0ApiClientHelper.TransferConfigReference.__init__   s!    %)*>%?dgr   r   rm   s   @r   TransferConfigReferencer      s#     !89*K H r   r   c                   6     e Zd Z ed      ZdZdZ fdZ xZS )$ApiClientHelper.TransferRunReference)transferRunNamez%(transferRunName)sztransfer runc                 8    |d   | _         t        |   di | y )Nr   r2   )r   ra   r   rb   s     r   r   z-ApiClientHelper.TransferRunReference.__init__   s!    "&'8"9dgr   r   rm   s   @r   TransferRunReferencer      s#     !56'KH r   r   c                   $    e Zd Z ed      ZdZdZy)&ApiClientHelper.NextPageTokenReference)pageTokenIdz%(pageTokenId)sz
page tokenNr#   rU   rV   rX   r   rI   r   r2   r   r   NextPageTokenReferencer      s     !12#KHr   r   c                       e Zd Zy)$ApiClientHelper.TransferLogReferenceN)r#   rU   rV   r2   r   r   TransferLogReferencer     s    r   r   c                   $    e Zd Z ed      ZdZdZy)(ApiClientHelper.EncryptionServiceAccount)serviceAccountz%(serviceAccount)sNr   r2   r   r   EncryptionServiceAccountr     s     !45&K
 Hr   r   c                   4    e Zd Z ed      ZdZdZdZdefdZ	y)$ApiClientHelper.ReservationReference)r\   r^   reservationId,%(projectId)s:%(location)s.%(reservationId)szLprojects/%(projectId)s/locations/%(location)s/reservations/%(reservationId)sreservationr(   c                 2    | j                   t        |       z  S r+   r   r9   s    r   r   z)ApiClientHelper.ReservationReference.path  r   r   N
r#   rU   rV   rX   r   rI   r   r   rB   r   r2   r   r   ReservationReferencer     s)     !KL@K^IH)c )r   r   c                   J     e Zd ZdZ ed      ZdZdZdZ fdZ	de
fdZ xZS )	+ApiClientHelper.CapacityCommitmentReferencez;Helper class to provide a reference to capacity commitment.)r\   r^   capacityCommitmentIdz3%(projectId)s:%(location)s.%(capacityCommitmentId)szZprojects/%(projectId)s/locations/%(location)s/capacityCommitments/%(capacityCommitmentId)szcapacity commitmentc                 `    |d   | _         |d   | _        |d   | _        t        |   di | y )Nr\   r^   r   r2   )r\   r^   r   ra   r   rb   s     r   r   z4ApiClientHelper.CapacityCommitmentReference.__init__#  s9     -dn
+dm'+,B'Cdgr   r(   c                 2    | j                   t        |       z  S r+   r   r9   s    r   r   z0ApiClientHelper.CapacityCommitmentReference.path+  r   r   r   rm   s   @r   CapacityCommitmentReferencer     s7    E 9 HKlI$H)c )r   r   c                   H    e Zd ZdZ ed      ZdZdZdZdZ	de
fdZde
fd	Zy
).ApiClientHelper.ReservationAssignmentReferencez>Helper class to provide a reference to reservation assignment.)r\   r^   r   reservationAssignmentIdzH%(projectId)s:%(location)s.%(reservationId)s.%(reservationAssignmentId)sztprojects/%(projectId)s/locations/%(location)s/reservations/%(reservationId)s/assignments/%(reservationAssignmentId)sr   zreservation assignmentr(   c                 2    | j                   t        |       z  S r+   r   r9   s    r   r   z3ApiClientHelper.ReservationAssignmentReference.path9  r   r   c                 2    | j                   t        |       z  S r+   )_reservation_format_strr3   r9   s    r   reservation_pathz?ApiClientHelper.ReservationAssignmentReference.reservation_path<  s    ))DJ66r   N)r#   rU   rV   rW   rX   r   rI   r   r   r   rB   r   r   r2   r   r   ReservationAssignmentReferencer   .  sF    H M ]K GIL'H)c )7# 7r   r   c                   H    e Zd ZdZ ed      ZdZdZdZdZ	de
fdZde
fd	Zy
)&ApiClientHelper.BiReservationReferencez6Helper class to provide a reference to bi reservation.)r\   r^   z%(projectId)s:%(location)sz;projects/%(projectId)s/locations/%(location)s/biReservationz-projects/%(projectId)s/locations/%(location)szbi reservationr(   c                 2    | j                   t        |       z  S r+   r   r9   s    r   r   z+ApiClientHelper.BiReservationReference.pathH  r   r   c                 2    | j                   t        |       z  S r+   )_create_path_strr3   r9   s    r   create_pathz2ApiClientHelper.BiReservationReference.create_pathK  s    ""T$Z//r   N)r#   rU   rV   rW   rX   r   rI   r   r   r   rB   r   r   r2   r   r   BiReservationReferencer   ?  s>    @ !:;.KMIFH)c )0S 0r   r   c                   J     e Zd ZdZ ed      ZdZdZdZ fdZ	de
fdZ xZS )	)ApiClientHelper.ReservationGroupReferencez9Helper class to provide a reference to reservation group.)r\   r^   reservationGroupIdz1%(projectId)s:%(location)s.%(reservationGroupId)szVprojects/%(projectId)s/locations/%(location)s/reservationGroups/%(reservationGroupId)szreservation groupc                 `    |d   | _         |d   | _        |d   | _        t        |   di | y )Nr\   r^   r   r2   )r\   r^   r   ra   r   rb   s     r   r   z2ApiClientHelper.ReservationGroupReference.__init__X  s9     -dn
+dm%)*>%?dgr   r(   c                 2    | j                   t        |       z  S r+   r   r9   s    r   r   z.ApiClientHelper.ReservationGroupReference.path`  r   r   r   rm   s   @r   ReservationGroupReferencer   N  s7    C 7 FKhI"H)c )r   r   c                   4    e Zd Z ed      ZdZdZdZdefdZ	y)#ApiClientHelper.ConnectionReference)r\   r^   connectionIdz+%(projectId)s.%(location)s.%(connectionId)szJprojects/%(projectId)s/locations/%(location)s/connections/%(connectionId)s
connectionr(   c                 2    | j                   t        |       z  S r+   r   r9   s    r   r   z(ApiClientHelper.ConnectionReference.pathi  r   r   Nr   r2   r   r   ConnectionReferencer   c  s)     !JK?K\IH)c )r   r   N)r#   rU   rV   rW   r   collections_abcMappingr   rn   rg   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r   r   r   r      s    OQA/)) AFOY O$ 6 2Oy O.y ) ),  		 		Y 	y 
	1 	 )Y ))I )*7y 7"0y 0)) )*)I )r   r   objtypes.messagemethodis_usage_errorr(   c                     t        | |      sA|s|r	d|d| }nd| d|}|rt        j                  |      t        j                  |      y)zAEnsure the obj is the correct type, or throw a BigqueryTypeError.zInvalid reference for z: zType of z is not one of N)
isinstancer   
UsageErrorr	   BigqueryTypeError)r   r   r   r   r   s        r   	typecheckr   m  sW     
C		4:C@ 
 47>NN7##&&w// 
 r   )NNF)rW   collectionssystypingr   r   r   r   r   abslr   utilsr	   pyglibr
   r   version_infoabcr   r   rB   boolr   r2   r   r   <module>r      s    &  
 4 4   fOO/Z) Z)F "  0		"	"0Xo//01d8O5567<=	?0 c]0 SM0 0 
0r   