
    /_i=                        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 	 d dlmZ d dlmZ 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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 Tw xY w)    )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                   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__     L/var/www/html/land_sniper/venv/lib/python3.12/site-packages/pyarrow/acero.pyDatasetr   3       r   r   c                       e Zd Zy)!DatasetModuleStub.InMemoryDatasetNr   r   r   r   InMemoryDatasetr!   6   r   r   r"   N)r   r   r   r   r"   r   r   r   r   r   2   s    	 		 	r   r   TFc           	      z   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implicit_orderingprojectfilter)
r   r   schemanamesr   from_sequencer   _scan_optionsgetr   )datasetr&   r'   declfprojectionsfilter_exprs          r   _dataset_to_declr4   ;   s    v[+ - .D &-^^%9%9:58:K:$$	{9&8&EFGD ''++H5K ((;x):;)GHI
 K ;s   B8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 }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.
    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 outerzright outer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+   r4   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_typer=   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_optsr0   left_columns_setright_columns_setright_operand_indexprojected_col_namesr2   right_key_index
projectionresult_tables!                                    r   _perform_joinrn   R   s   T 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2Y

s   )	O13O1	O6O6c	                    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}|j                  j                  D 	cg c]  }	|	|g|z   vr|	 }
}	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      }|j!                  |	      }|t        k(  r|S |t        j"                  k(  rt        j"                  |      S t	        d
      c c}	w )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
    r6   zColumns zE present in both tables. AsofJoin does not support column collisions.Tr%   r9   asofjoinr?   r8   rC   )rD   r   rE   r   rF   rG   rH   rI   r*   r+   rK   
ValueErrorr4   r   r
   r   rP   r"   )rR   left_onleft_byrT   right_onright_by	tolerancer&   rY   r`   r_   columns_collisionsrd   re   rf   r0   rm   s                    r   _perform_join_asofrx     s   B lUBJJ$789$|:L9MNOOmeRZZ%899$}:M9NOPPgt}-)h.: %++11xj8++ 	M  \00667#m:LL)* +; ;
 	
 ,

+&#"$
 "2<@
 -,'{"$ #2=A
 $(HiI I{L.ID ==[=9Le	**	*!!,//122Ys   9G3c           	         d}t        | t              rt        j                  | g      } d}t	        j
                  t	        dt        |             t	        dt        |            g      }|j                  d      }|r|j                  dkD  r#|j                         j                         d   }|S |j                  D cg c]  }t        g |j                         }}t        j                  ||j                  	      }|S c c}w )
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
    FTr9   )r@   r)   r8   r   )rG   )r*   )rD   r   r   from_batchesr   r,   r
   r   rP   num_rowscombine_chunks
to_batchesr*   r   rG   from_arrays)table
expressionis_batchr0   resultr   arrayss          r   _filter_tabler   b  s    " H%%""E7+$$N,B5,IJH&7
&CD& D ]]t],F??Q**,779!<F M ?EmmLUeBUZZ0LFL ,,VFMMJFM Ms   >D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      )NTr8   r9   order_byrC   )rD   rE   r   r4   r   r
   r   r,   rP   r   r"   rF   )table_or_dataset	sort_keysrY   kwargsdata_sourcer   r0   rm   s           r   _sort_sourcer     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 )Nr9   	aggregate)keysr8   )r   r,   r
   r   rP   )r   
aggregatesr   r&   r0   s        r   	_group_byr     sL    $$N$:5$ABK!5jt!LM& D ==[=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.datasetr/   rE   pyarrow._datasetr   r   r4   rn   rx   r   r   r   r   r   r   <module>r      s   2 2 1 -
 
 
"
 02 #"%#t	r3n /3#(X3v!H ;@ 3,2i  

J3s8*TUV    
Bs(   A A8 A5A00A58BB