o
    Zh-                  
   @   s   d dl mZ d dlmZmZ zd dlmZmZmZm	Z	m
Z
mZmZmZ W n ey; Z zedee dddZ[ww zd dlmZ d dlmZ W n ey\   G dd	 d	ZeZY nw dddZddd
defddZdd ZefddZd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                   @   s(   e Zd ZG dd dZG dd dZdS )DatasetModuleStubc                   @      e Zd ZdS )zDatasetModuleStub.DatasetN__name__
__module____qualname__ r   r   D/var/www/html/lang_env/lib/python3.10/site-packages/pyarrow/acero.pyDataset2       r   c                   @   r   )z!DatasetModuleStub.InMemoryDatasetNr   r   r   r   r   InMemoryDataset5   r   r   N)r   r   r   r   r   r   r   r   r   r   1   s    r   Tc                 C   sl   t dt| |d}dd | jjD }t |t dt|g}| jd}|d ur4t |t dt|g}|S )Nscanuse_threadsc                 S   s   g | ]}t |qS r   )r   ).0fr   r   r   
<listcomp>?   s    z$_dataset_to_decl.<locals>.<listcomp>projectfilter)	r   r   schemanamesfrom_sequencer	   Z_scan_optionsgetr   )datasetr   declprojectionsZfilter_exprr   r   r   _dataset_to_decl:   s   r)   Fc
                    s~  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 ]\}
}|
 |< q2i t |ttfsG|g}t|D ]\}
}|
|< qK|j	j
}|j	j
}| dksd| dkrgg }n*| dkso| dkrrg }n| dksz| dkrfdd	|D }n| d
kr fdd	|D }i }t|D ]\}
}||v r|
||< qi }t|D ]\}
}||v r|
||< qt |tjrt||d}ntdt|}t |tjrt||d}ntdt|}|rt| |||||pd|pdd}nt| |||pd|pdd}td|||gd}|r| dkrt|}t|}t|}g }g }t|| D ]n\}
}|
t|k rW||v rW|| || |   }|tdt|
t|| g q%|
|krc||v rcq%|rt|
|k rt||v rt||7 }|r|
|kr||v r||7 }|| |t|
 q%tdt||}t||g}|j|d}|	tkr|S |	tjkrt|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r|qS r   r   r   col)right_keys_orderr   r   r          z!_perform_join.<locals>.<listcomp>zright outerc                    r+   r   r   r,   )left_keys_orderr   r   r      r/   r   table_source )Zoutput_suffix_for_leftZoutput_suffix_for_rightZhashjoin)optionsZinputsz
full outerZcoalescer    Unsupported output type)
isinstancer   dsr   	TypeErrortypetuplelist	enumerater"   r#   r)   r   r   r   setlenappendr   Z_callZ_fieldr	   r$   to_tabler   )Z	join_typeZleft_operandZ	left_keysZright_operandZ
right_keysZleft_suffixZright_suffixr   Zcoalesce_keysoutput_typeidxkeyZleft_columnsZright_columnsZleft_column_keys_indicesZcolnameZright_column_keys_indicesZleft_sourceZright_sourceZ	join_optsr'   Zleft_columns_setZright_columns_setZright_operand_indexZprojected_col_namesr(   r-   Zright_key_indexZ
projectionresult_tabler   )r0   r.   r   _perform_joinO   s   (















rD   c                 C   s2   t t dt| dt dt|dg}|jd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
    r1   )r3   r!   Tr   )r   r$   r   r   r?   )table
expressionr'   r   r   r   _filter_table   s
   rG   c                 K   s   t | tjrt| dd}ntdt| }tdt|fi |}t||g}|jdd}|t	kr2|S |tj
kr<t
|S td)NTr   r1   order_byr4   )r5   r6   r   r)   r   r   r   r$   r?   r   r   r7   )Ztable_or_dataset	sort_keysr@   kwargsZdata_sourcerH   r'   rC   r   r   r   _sort_source  s   

rK   c              	   C   s2   t t dt| t dt||dg}|j|dS )Nr1   Z	aggregate)keysr   )r   r$   r   r
   r?   )rE   Z
aggregatesrL   r   r'   r   r   r   	_group_by.  s
   rM   )T)Zpyarrow.libr   Zpyarrow.computer   r   Zpyarrow._aceror   r   r   r   r	   r
   r   r   ImportErrorexcstrZpyarrow.datasetr&   r6   Zpyarrow._datasetr   r   r)   rD   rG   rK   rM   r   r   r   r   <module>   s8   ,



 2