
    '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 	 d dlmZ d dlmZ ddZddd
defdZd ZefdZddZy# e$ rZ ed ee       d      ddZ[ww xY w# e$ r  G d d	      ZeZY Mw xY w)    )Table)
Expressionfield)DeclarationExecNodeOptionsTableSourceNodeOptionsFilterNodeOptionsProjectNodeOptionsAggregateNodeOptionsOrderByNodeOptionsHashJoinNodeOptionsz@The pyarrow installation is not built with support for 'acero' ()N)ScanNodeOptionsc                   4    e Zd Z G d d      Z G d d      Zy)DatasetModuleStubc                       e Zd Zy)DatasetModuleStub.DatasetN__name__
__module____qualname__     -lib/python3.11/site-packages/pyarrow/acero.pyDatasetr   2       r   r   c                       e Zd Zy)!DatasetModuleStub.InMemoryDatasetNr   r   r   r   InMemoryDatasetr   5   r   r   r   N)r   r   r   r   r   r   r   r   r   r   1   s    	 		 	r   r   Tc           	      x   t        dt        | |            }| j                  j                  D cg c]  }t	        |       }}t        j
                  |t        dt        |            g      }| j                  j                  d      }|*t        j
                  |t        dt        |            g      }|S c c}w )Nscanuse_threadsprojectfilter)
r   r   schemanamesr   from_sequencer
   _scan_optionsgetr	   )datasetr#   declfprojectionsfilter_exprs         r   _dataset_to_declr0   :   s    vwKPQD &-^^%9%9:58:K:$$	{9&8&EFGD ''++H5K ((;x):;)GHI
 K ;s   B7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 }nE| dk(  s| dk(  rg }n8| dk(  s| dk(  r|D cg c]	  }||vs| }}n| dk(  r|D cg c]	  }||
vs| }}i }t        |      D ]  \  }}||v s|||<    i }t        |      D ]  \  }}||v s|||<    t        |t        j                        rt        ||	      }nt        d
t        |            }t        |t        j                        rt        ||	      }nt        d
t        |            }|rt        | |||||xs d|xs d      }nt        | |||xs d|xs d      }t        d|||g      }|rL| dk(  rFt        |      }t        |      }t!        |      }g }g }t        ||z         D ]  \  }}|t!        |      k  rq||v rm|j#                  |       |||
|         }|j#                  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  }|j#                  |       |j#                  t%        j(                  |              t        dt+        ||            }t        j,                  ||g      }|j/                  |	      }|	t        k(  r|S |	t        j0                  k(  rt        j0                  |      S t	        d      c c}w c c}w )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 outerzright outerr"   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'   r0   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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_optsr,   left_columns_setright_columns_setright_operand_indexprojected_col_namesr.   right_key_index
projectionresult_tables                                    r   _perform_joinrf   O   s   P lUBJJ$789$|:L9MNOOmeRZZ%899$}:M9NOPP Oi%/K	i( #S"# j4-0 \
j) $S #$  &&,,L!((..M K9#;	l	"i<&?	g	l!:(
C7G,GC
 
 
m	#'
3o+EC
 
  "!,/ 4Wi03$W-4 !#!-0 5Wj 14%g.5
 ,

+&|M!.2H2VW-,';O"2=A
 'y*lM#.#4"$0$6B
	 (y*#.#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   )	O/3O/	O4O4c           	          t        j                  t        dt        |             t        dt        |            g      }|j	                  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
    r3   )r8   r%   Tr"   )r   r(   r   r	   rH   )table
expressionr,   s      r   _filter_tablerj      sL    " $$N,B5,IJH&7
&CD& D ==T=**r   c                 v   t        | t        j                        rt        | d      }nt	        dt        |             }t	        dt        |fi |      }t	        j                  ||g      }|j                  d      }|t        k(  r|S |t        j                  k(  rt        j                  |      S t        d      )NTr"   r3   order_byr;   )r<   r=   r   r0   r   r   r   r(   rH   r   r   r>   )table_or_dataset	sort_keysrQ   kwargsdata_sourcerl   r,   re   s           r   _sort_sourcerq     s    "BJJ/&'7TJ!23CD
 :'9)'Nv'NOH$$k8%<=D==T=2Le	**	*!!,//122r   c           
          t        j                  t        dt        |             t        dt        ||            g      }|j	                  |      S )Nr3   	aggregate)keysr"   )r   r(   r   r   rH   )rh   
aggregatesrt   r#   r,   s        r   	_group_byrv   .  sL    $$N$:5$ABK!5jt!LM& D ==[=11r   )T)pyarrow.libr   pyarrow.computer   r   pyarrow._aceror   r   r   r	   r
   r   r   r   ImportErrorexcstrpyarrow.datasetr+   r=   pyarrow._datasetr   r   r0   rf   rj   rq   rv   r   r   r   <module>r      s   2  -	 	 	 
 0. #"%#	n3b+0 ;@ 3,2O  

J3s8*TUV    
Bs(   A A+ A(A##A(+A?>A?