
    y-Ph;                     0   d dl mZmZ d dlmZmZ 	 d dlmZmZm	Z	m
Z
mZmZmZmZmZ n&# e$ rZ ed ee           d          ddZ[ww xY w	 d dlmZ d dlmZ n# e$ r  G d d	          ZeZY nw xY wddZddd
defdZd
efdZd ZefdZddZdS )    )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                   B    e Zd Z G d d          Z G d d          ZdS )DatasetModuleStubc                       e Zd ZdS )DatasetModuleStub.DatasetN__name__
__module____qualname__     M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyarrow/acero.pyDatasetr   3           Dr   r   c                       e Zd ZdS )!DatasetModuleStub.InMemoryDatasetNr   r   r   r   InMemoryDatasetr    6   r   r   r!   N)r   r   r   r   r!   r   r   r   r   r   2   sd        	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	r   r   TFc           	      n   t          dt          | ||                    }d | j        j        D             }t          j        |t          dt          |                    g          }| j                            d          }|1t          j        |t          dt          |                    g          }|S )Nscanuse_threadsimplicit_orderingc                 ,    g | ]}t          |          S r   )r   ).0fs     r   
<listcomp>z$_dataset_to_decl.<locals>.<listcomp>B   s    :::588:::r   projectfilter)	r   r   schemanamesfrom_sequencer   _scan_optionsgetr
   )datasetr%   r&   declprojectionsfilter_exprs         r   _dataset_to_declr6   ;   s    v[+ -  -  - . .D ;:W^%9:::K$	{9&8&E&EFFG D '++H55K (;x):;)G)GHHI
 
 Kr   c
                    t          |t          t          j        f          st	          dt          |                     t          |t          t          j        f          st	          dt          |                     i t          |t          t          f          s|g}t          |          D ]
\  }
}|
|<   i t          |t          t          f          s|g}t          |          D ]
\  }
}|
|<   |j	        j
        }|j	        j
        }| dk    s| dk    rg }n>| dk    s| dk    rg }n/| dk    s| dk    rfd|D             }n| d	k    rfd
|D             }i }t          |          D ]\  }
}||v r|
||<   i }t          |          D ]\  }
}||v r|
||<   t          |t          j                  rt          ||          }nt          dt          |                    }t          |t          j                  rt          ||          }nt          dt          |                    }|rt          | |||||pd|pd          }nt          | |||pd|pd          }t          d|||g          }|r| dk    rzt          |          }t          |          }t!          |          }g }g }t          ||z             D ]\  }
}|
t!          |          k     r||v r{|                    |           |||                           }|                    t%          j        dt%          j        |
          t%          j        ||z             g                     |
|k    r||v r|r|
|k     r	||v r||z  }|r|
|k    r	||v r||z  }|                    |           |                    t%          j        |
                     t          dt+          ||                    }t          j        ||g          }|                    |          }|	t          k    r|S |	t          j        k    rt          j        |          S t	          d          )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 outerc                     g | ]}|v|	S r   r   )r(   colright_keys_orders     r   r*   z!_perform_join.<locals>.<listcomp>   s+     
 
 
C7G,G,GC,G,G,Gr   zright outerc                     g | ]}|v|	S r   r   )r(   r;   left_keys_orders     r   r*   z!_perform_join.<locals>.<listcomp>   s*     
 
 
3o+E+EC+E+E+Er   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.   r6   r   r	   r   setlenappendr   _call_fieldr   r/   to_tabler!   ) 	join_typeleft_operand	left_keysright_operand
right_keysleft_suffixright_suffixr%   coalesce_keysoutput_typeidxkeyleft_columnsright_columnsleft_column_keys_indicescolnameright_column_keys_indicesleft_sourceright_source	join_optsr3   left_columns_setright_columns_setright_operand_indexprojected_col_namesr4   r;   right_key_index
projectionresult_tabler>   r<   s                                  @@r   _perform_joinrq   R   s   P lUBJ$788 PN$|:L:LNNOOOmeRZ%899 QO$}:M:MOOPPP Oi%//  K	i(( # #S"j4-00 " \
j)) $ $S #  &,L!(.M K9#;#;	l	"	"i<&?&?	g		l!:!:
 
 
 
(
 
 
 
m	#	#
 
 
 
'
 
 
  "!,// 4 4Wi03$W- "!-00 5 5Wj  14%g. ,
++ X&|MMM!.2H2V2VWW-,, 
';OOO"2=AA
 
  
'y*lM#.#4"$0$6B
 
 
		 (y*#.#4"$0$6B
 
 
	
 I{L.I  D  2=l22 |,,..!,// !,">?? $	 $	HCS&&&&32J+J+J#**3///
 #<s34#6""$Z")#..
0A/?1A 1A2      +++7P0P0P  '$'*=$=$=000;&C (%(,?%?%?///<'C#**3///""%c**    !)+7JKK
 

 ($
);<<==[=99Le	*	*	*!,///1222r   c	                 p   t          | t          t          j        f          st	          dt          |                      t          |t          t          j        f          st	          dt          |                     t          |t          t          f          s|g}t          t          t          f          sgfd|j        j	        D             }	t          | j        j	                  t          |	          z  }
|
r"t          d                    |
                    t          | t          j                  rt          | |d          }nt          dt          |                     }t          |t          j                  rt          ||d          }nt          dt          |                    }t!          |||          }t          d|||g          }|                    |	          }|t          k    r|S |t          j        k    rt          j        |          S t	          d
          )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
    r8   c                 $    g | ]}|gz   v
|S r   r   )r(   r;   right_byright_ons     r   r*   z&_perform_join_asof.<locals>.<listcomp>/  s5       xj8+++ 	+++r   zOColumns {} present in both tables. AsofJoin does not support column collisions.Tr$   r@   asofjoinrE   r?   rI   )rJ   r   rK   r   rL   rM   rN   rO   r-   r.   rQ   
ValueErrorformatr6   r   r	   r   rV   r!   )rX   left_onleft_byrZ   ru   rt   	tolerancer%   r_   rc   columns_collisionsrg   rh   ri   r3   rp   s       ``          r   _perform_join_asofr}     so   B lUBJ$788 PN$|:L:LNNOOOmeRZ%899 QO$}:M:MOOPPPgt}-- )h.. :    $+1  M \0677#m:L:LL 
!!'(:!;!;
 
 	
 ,
++ 
&#"$ $ $
 "2<@@
 
 -,, 
'{"$ $ $ #2=AA
 
 $(Hi I I{L.I  D ==[=99Le	*	*	*!,///1222r   c           	         d}t          | t                    rt          j        | g          } d}t	          j        t	          dt          |                     t	          dt          |                    g          }|                    d          }|r,|	                                
                                d         }|S )a}  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@   )rF   r,   r?   r   )rJ   r   r   from_batchesr   r/   r	   r
   rV   combine_chunks
to_batches)table
expressionis_batchr3   results        r   _filter_tabler   ^  s    " H%%% "E7++$N,B5,I,IJJJH&7
&C&CDDD&  D ]]t],,F 9&&((3355a8Mr   c                    t          | t          j                  rt          | d          }nt	          dt          |                     }t	          dt          |fi |          }t	          j        ||g          }|                    d          }|t          k    r|S |t          j
        k    rt          j
        |          S t          d          )NTr?   r@   order_byrI   )rJ   rK   r   r6   r   r	   r   r/   rV   r   r!   rL   )table_or_dataset	sort_keysr_   kwargsdata_sourcer   r3   rp   s           r   _sort_sourcer   ~  s    "BJ// 
&'7TJJJ!23CDD
 
 :'9)'N'Nv'N'NOOH$k8%<==D==T=22Le	*	*	*!,///1222r   c           
          t          j        t          dt          |                     t          dt          ||                    g          }|                    |          S )Nr@   	aggregate)keysr?   )r   r/   r	   r   rV   )r   
aggregatesr   r%   r3   s        r   	_group_byr     s`    $N$:5$A$ABBK!5jt!L!L!LMM&  D ==[=111r   )TF)T)pyarrow.libr   r   pyarrow.computer   r   pyarrow._aceror   r   r	   r
   r   r   r   r   r   ImportErrorexcstrpyarrow.datasetr2   rK   pyarrow._datasetr   r   r6   rq   r}   r   r   r   r   r   r   <module>r      s  2 + * * * * * * * - - - - - - - -
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    
+V33s88VVV 
      0000000           
BBB   2 #"%#	n3 n3 n3 n3f /3#(X3 X3 X3 X3v  @ ;@ 3 3 3 3,2 2 2 2 2 2s&   ) AAAA A43A4