
    Lg;                     &   S SK JrJr  S SKJrJr   S SKJrJrJ	r	J
r
JrJrJrJrJr   S SKJr  S SKJr  SS jrSSS
S\4S jrS
\4S jrS r\4S jrSS jrg! \ a  r\" S\" \5       S35      SeSrCff = f! \ a     " S S	5      r\r NZf = f)    )TableRecordBatch)
Expressionfield)	DeclarationExecNodeOptionsTableSourceNodeOptionsFilterNodeOptionsProjectNodeOptionsAggregateNodeOptionsOrderByNodeOptionsHashJoinNodeOptionsAsofJoinNodeOptionsz@The pyarrow installation is not built with support for 'acero' ()N)ScanNodeOptionsc                   <    \ rS rSr " S S5      r " S S5      rSrg)DatasetModuleStub2   c                       \ rS rSrSrg)DatasetModuleStub.Dataset3    N__name__
__module____qualname____firstlineno____static_attributes__r       -lib/python3.12/site-packages/pyarrow/acero.pyDatasetr   3       r   r!   c                       \ rS rSrSrg)!DatasetModuleStub.InMemoryDataset6   r   Nr   r   r   r    InMemoryDatasetr$   6   r"   r   r&   r   N)r   r   r   r   r!   r&   r   r   r   r    r   r   2   s    	 		 	r   r   TFc           	      ~   [        S[        XUS95      nU R                  R                   Vs/ s H  n[	        U5      PM     nn[         R
                  " U[        S[        U5      5      /5      nU R                  R                  S5      nUb+  [         R
                  " U[        S[        U5      5      /5      nU$ s  snf )Nscanuse_threadsrequire_sequenced_outputprojectfilter)
r   r   schemanamesr   from_sequencer   _scan_optionsgetr
   )datasetr*   r+   declfprojectionsfilter_exprs          r    _dataset_to_declr8   ;   s    v!9 ; <D &-^^%9%9:%958%9K:$$	{9&8&EFGD ''++H5K ((;x):;)GHI
 K ;s   B:c
                    [        U[        [        R                  45      (       d  [	        S[        U5       35      e[        U[        [        R                  45      (       d  [	        S[        U5       35      e0 n
[        U[        [        45      (       d  U/n[        U5       H	  u  pXU'   M     0 n[        U[        [        45      (       d  U/n[        U5       H	  u  pXU'   M     UR                  R                  nUR                  R                  nU S:X  d  U S:X  a  / nOVU S:X  d  U S:X  a  / nOGU S:X  d  U S:X  a  U Vs/ s H  nUU;  d  M  UPM     nnO U S:X  a  U Vs/ s H  nUU
;  d  M  UPM     nn0 n[        U5       H  u  nnUU;   d  M  UUU'   M     0 n[        U5       H  u  nnUU;   d  M  UUU'   M     [        U[        R                  5      (       a
  [        XS	9nO[        S
[        U5      5      n[        U[        R                  5      (       a
  [        X7S	9nO[        S
[        U5      5      nU(       a   [        XXNUU=(       d    SU=(       d    SS9nO[        XUU=(       d    SU=(       d    SS9n[        SUUU/S9nU(       Gal  U S:X  Gae  [        U5      n[        U5      n[!        U5      n/ n/ n[        X-   5       GH   u  nnU[!        U5      :  av  UU;   ap  UR#                  U5        UXJU         nUR#                  [$        R&                  " S[$        R(                  " U5      [$        R(                  " UU-   5      /5      5        M  UU:  a  UU;   a  M  U(       a  UU:  a  UU;   a  UU-  nU(       a  UU:  a  UU;   a  UU-  nUR#                  U5        UR#                  [$        R(                  " U5      5        GM     [        S[+        UU5      5      n[        R,                  " UU/5      nUR/                  US	9nU	[        :X  a  U$ U	[        R0                  :X  a  [        R0                  " U5      $ [	        S5      es  snf s  snf )a  
Perform join of two tables or datasets.

The result will be an output table with the result of the join operation

Parameters
----------
join_type : str
    One of supported join types.
left_operand : Table or Dataset
    The left operand for the join operation.
left_keys : str or list[str]
    The left key (or keys) on which the join operation should be performed.
right_operand : Table or Dataset
    The right operand for the join operation.
right_keys : str or list[str]
    The right key (or keys) on which the join operation should be performed.
left_suffix : str, default None
    Which suffix to add to left column names. This prevents confusion
    when the columns in left and right operands have colliding names.
right_suffix : str, default None
    Which suffix to add to the right column names. This prevents confusion
    when the columns in left and right operands have colliding names.
use_threads : bool, default True
    Whether to use multithreading or not.
coalesce_keys : bool, default False
    If the duplicated keys should be omitted from one of the sides
    in the join result.
output_type: Table or InMemoryDataset
    The output type for the exec plan result.

Returns
-------
result_table : Table or InMemoryDataset
Expected Table or Dataset, got z	left semiz	left antiz
right semiz
right antiinnerz
left outerzright outerr*   table_source )output_suffix_for_leftoutput_suffix_for_righthashjoinoptionsinputsz
full outercoalescer,   Unsupported output type)
isinstancer   dsr!   	TypeErrortypetuplelist	enumerater.   r/   r8   r   r	   r   setlenappendr   _call_fieldr   r0   to_tabler&   ) 	join_typeleft_operand	left_keysright_operand
right_keysleft_suffixright_suffixr*   coalesce_keysoutput_typeleft_keys_orderidxkeyright_keys_orderleft_columnsright_columnscolleft_column_keys_indicescolnameright_column_keys_indicesleft_sourceright_source	join_optsr4   left_columns_setright_columns_setright_operand_indexprojected_col_namesr6   right_key_index
projectionresult_tables                                    r    _perform_joinrq   R   su   P lUBJJ$7889$|:L9MNOOmeRZZ%8999$}:M9NOPP Oi%//K	i(" ) j4-00 \
j) # *  &&,,L!((..M K9#;	l	"i<&?	g	l!:(
(CC7G,GC= 	 
 
m	#'
'C3o+EC< 	 
  "!,/Wi03$W- 0 !#!-0Wj 14%g. 1
 ,

++&|M!.2H2VW-,,'O"2=A
 '*M#.#4"$0$6B
	 (*#.#4"$0$6B
	
 I{L.ID l2 |,.!,/ !,">?HCS&&32J+J#**3/
 #<s34#6""$$Z"))#.
0A0A/?1A2  ++7P0P  C*=$=00;&C S,?%?//<'C#**3/""%%c*E @J !)+7JK

 (($
);<==[=9Le	**	*!!,//122U

s   
QQ$
Q2Qc	                 >   [        U [        [        R                  45      (       d  [	        S[        U 5       35      e[        U[        [        R                  45      (       d  [	        S[        U5       35      e[        U[        [        45      (       d  U/n[        U[        [        45      (       d  U/nUR                  R                   V	s/ s H  n	X/U-   ;  d  M  U	PM     n
n	[        U R                  R                  5      [        U
5      -  nU(       a  [        SR                  U5      5      e[        U [        R                  5      (       a  [        U USS9nO[        S[        U 5      5      n[        U[        R                  5      (       a  [        X7SS9nO[        S[        U5      5      n[!        XXEU5      n[        SXU/S9nUR#                  US9nU[        :X  a  U$ U[        R$                  :X  a  [        R$                  " U5      $ [	        S	5      es  sn	f )
a  
Perform asof join of two tables or datasets.

The result will be an output table with the result of the join operation

Parameters
----------
left_operand : Table or Dataset
    The left operand for the join operation.
left_on : str
    The left key (or keys) on which the join operation should be performed.
left_by: str or list[str]
    The left key (or keys) on which the join operation should be performed.
right_operand : Table or Dataset
    The right operand for the join operation.
right_on : str or list[str]
    The right key (or keys) on which the join operation should be performed.
right_by: str or list[str]
    The right key (or keys) on which the join operation should be performed.
tolerance : int
    The tolerance to use for the asof join. The tolerance is interpreted in
    the same units as the "on" key.
output_type: Table or InMemoryDataset
    The output type for the exec plan result.

Returns
-------
result_table : Table or InMemoryDataset
r:   zOColumns {} present in both tables. AsofJoin does not support column collisions.Tr)   r=   asofjoinrB   r<   rF   )rG   r   rH   r!   rI   rJ   rK   rL   r.   r/   rN   
ValueErrorformatr8   r   r	   r   rS   r&   )rU   left_onleft_byrW   right_onright_by	tolerancer*   r\   rc   rb   columns_collisionsrg   rh   ri   r4   rp   s                    r    _perform_join_asofr|     s   B lUBJJ$7889$|:L9MNOOmeRZZ%8999$}:M9NOPPgt}--)h..: %++111j8++ 	1   \00667#m:LL!!'(:!;
 	
 ,

++&#%)+
 "2<@
 -,,'%)+ #2=A
 $(iI IL.ID ==[=9Le	**	*!!,//122Ys   HHc           	      H   Sn[        U [        5      (       a  [        R                  " U /5      n Sn[        R
                  " [	        S[        U 5      S9[	        S[        U5      S9/5      nUR                  SS9nU(       a!  UR                  5       R                  5       S   nU$ )aM  Filter rows of a table based on the provided expression.

The result will be an output table with only the rows matching
the provided expression.

Parameters
----------
table : Table or RecordBatch
    Table that should be filtered.
expression : Expression
    The expression on which rows should be filtered.

Returns
-------
Table
FTr=   )rC   r-   r<   r   )rG   r   r   from_batchesr   r0   r	   r
   rS   combine_chunks
to_batches)table
expressionis_batchr4   results        r    _filter_tabler   ^  s    " H%%%""E7+$$N,B5,IJH&7
&CD& D ]]t],F&&(335a8Mr   c                 z   [        U [        R                  5      (       a  [        U SS9nO[	        S[        U 5      5      n[	        S[        U40 UD65      n[        R                  " XE/5      nUR                  SS9nU[        :X  a  U$ U[        R                  :X  a  [        R                  " U5      $ [        S5      e)NTr<   r=   order_byrF   )rG   rH   r!   r8   r   r	   r   r0   rS   r   r&   rI   )table_or_dataset	sort_keysr\   kwargsdata_sourcer   r4   rp   s           r    _sort_sourcer   ~  s    "BJJ//&'7TJ!23CD
 :'9)'Nv'NOH$$k%<=D==T=2Le	**	*!!,//122r   c                     [         R                  " [        S[        U 5      5      [        S[        XS95      /5      nUR	                  US9$ )Nr=   	aggregate)keysr<   )r   r0   r	   r   rS   )r   
aggregatesr   r*   r4   s        r    	_group_byr     sJ    $$N$:5$ABK!5j!LM& D ==[=11r   )TF)T)pyarrow.libr   r   pyarrow.computer   r   pyarrow._aceror   r   r	   r
   r   r   r   r   r   ImportErrorexcstrpyarrow.datasetr3   rH   pyarrow._datasetr   r   r8   rq   r|   r   r   r   r   r   r    <module>r      s   2 + -
 
 
"
 02 #"%#	n3f /3#(X3v@ ;@ 3,2Y  

J3s8*TUV    
Bs(   A A; A8 A33A8;BB