
    'e-                        d dl 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 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 ZefdZddZdS )    )Table)
Expressionfield)DeclarationExecNodeOptionsTableSourceNodeOptionsFilterNodeOptionsProjectNodeOptionsAggregateNodeOptionsOrderByNodeOptionsHashJoinNodeOptionsz@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__     -  /croot/pyarrow_1707330824290/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/lib/python3.11/site-packages/pyarrow/acero.pyDatasetr   2           Dr   r   c                       e Zd ZdS )!DatasetModuleStub.InMemoryDatasetNr   r   r   r   InMemoryDatasetr   5   r   r   r   N)r   r   r   r   r   r   r   r   r   r   1   sd        	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	r   r   Tc           	      l   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_threadsc                 ,    g | ]}t          |          S r   )r   ).0fs     r   
<listcomp>z$_dataset_to_decl.<locals>.<listcomp>?   s    :::588:::r   projectfilter)	r   r   schemanamesfrom_sequencer
   _scan_optionsgetr	   )datasetr#   declprojectionsfilter_exprs        r   _dataset_to_declr3   :   s    vwKPPPQQD ;:W^%9:::K$	{9&8&E&EFFG D '++H55K (;x):;)G)GHHI
 
 Kr   Fc
                    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
    z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%   r7   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+   r3   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_optsr0   left_columns_setright_columns_setright_operand_indexprojected_col_namesr1   r7   right_key_index
projectionresult_tabler:   r8   s                                  @@r   _perform_joinrk   O   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           	          t          j        t          dt          |                     t          dt          |                    g          }|                    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 Dataset
        Table or Dataset that should be filtered.
    expression : Expression
        The expression on which rows should be filtered.

    Returns
    -------
    Table
    r;   )r@   r)   Tr"   )r   r,   r   r	   rP   )table
expressionr0   s      r   _filter_tablero      sc    " $N,B5,I,IJJJH&7
&C&CDDD&  D ==T=***r   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_byrC   )rD   rE   r   r3   r   r   r   r,   rP   r   r   rF   )table_or_dataset	sort_keysrY   kwargsdata_sourcerq   r0   rj   s           r   _sort_sourcerv     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   rP   )rm   
aggregatesry   r#   r0   s        r   	_group_byr{   .  s`    $N$:5$A$ABBK!5jt!L!L!LMM&  D ==[=111r   )T)pyarrow.libr   pyarrow.computer   r   pyarrow._aceror   r   r   r	   r
   r   r   r   ImportErrorexcstrpyarrow.datasetr/   rE   pyarrow._datasetr   r   r3   rk   ro   rv   r{   r   r   r   <module>r      s  2       - - - - - - - -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	    
+V33s88VVV 
      0000000           
BBB   . #"%#	n3 n3 n3 n3b+ + +0 ;@ 3 3 3 3,2 2 2 2 2 2s&   % AAAA A0/A0