
    Pi=                     6   d dl mZ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dfdZd
efdZd ZefdZddZdS )    )TableRecordBatcharray)
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__     a/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/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_declr7   ;   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.
    filter_expression : pyarrow.compute.Expression
        Residual filter which is applied to matching row.

    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filter_expressionhashjoinoptionsinputsz
full outercoalescer,   Unsupported output type)
isinstancer   dsr   	TypeErrortypetuplelist	enumerater.   r/   r7   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_typerE   idxkeyleft_columnsright_columns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_namesr5   r<   right_key_index
projectionresult_tabler?   r=   s!                                  @@r   _perform_joinrs   R   s   T 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	                 R   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|
 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
    r9   c                 $    g | ]}|gz   v
|S r   r   )r)   r<   right_byright_ons     r   r+   z&_perform_join_asof.<locals>.<listcomp>3  s5       xj8+++ 	+++r   zColumns zE present in both tables. AsofJoin does not support column collisions.Tr%   rA   asofjoinrG   r@   rK   )rL   r   rM   r   rN   rO   rP   rQ   r.   r/   rS   
ValueErrorr7   r   r
   r   rX   r"   )rZ   left_onleft_byr\   rw   rv   	tolerancer&   ra   re   columns_collisionsri   rj   rk   r4   rr   s       ``          r   _perform_join_asofr~     ss   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          }|rd|j	        dk    r-|
                                                                d         }n,d |j        D             }t          j        ||j        	          }|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 or RecordBatch
    FTrA   )rH   r-   r@   r   c                 :    g | ]}t          g |j                   S ))rO   )r   rO   )r)   r   s     r   r+   z!_filter_table.<locals>.<listcomp>  s'    LLLUeBUZ000LLLr   )r.   )rL   r   r   from_batchesr   r0   r
   r   rX   num_rowscombine_chunks
to_batchesr.   from_arrays)table
expressionis_batchr4   resultarrayss         r   _filter_tabler   b  s    " H%%% "E7++$N,B5,I,IJJJH&7
&C&CDDD&  D ]]t],,F K?Q**,,7799!<FFLLfmLLLF ,VFMJJJF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@   rA   order_byrK   )rL   rM   r   r7   r   r
   r   r0   rX   r   r"   rN   )table_or_dataset	sort_keysra   kwargsdata_sourcer   r4   rr   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 )NrA   	aggregate)keysr@   )r   r0   r
   r   rX   )r   
aggregatesr   r&   r4   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   r   pyarrow.computer   r   pyarrow._aceror   r	   r
   r   r   r   r   r   r   ImportErrorexcstrpyarrow.datasetr3   rM   pyarrow._datasetr   r   r7   rs   r~   r   r   r   r   r   r   <module>r      s$  2 2 1 1 1 1 1 1 1 1 1 - - - - - - - -
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    
+V33s88VVV 
      0000000           
BBB   2 #"%#t	r3 r3 r3 r3n /3#(X3 X3 X3 X3v! ! !H ;@ 3 3 3 3,2 2 2 2 2 2s&   + AA		AA A65A6