
    &`iC$                        d dl 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lmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z'm(Z(m)Z)m*Z* d dl+m,Z,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z>m?Z?m@Z@mAZA d dlBmCZC d dlDmEZE  ede          ZFeeFee	         eEge	f         ZGde#dee	         d eEd!e	fd"ZHd#e!dee	         d eEd!e	fd$ZId% ZJd& ZKd' ZLd( ZMde%dee	         d eEd!e	fd)ZNde4dee	         d eEfd*ZO G d+ d,          ZPded-eee         eGf         d!eeG         fd.ZQd/S )0    )CallableDictListOptionalTupleTypeTypeVar)PhysicalOperator)AggregateNumRows)InputDataBuffer)JoinOperator)LimitOperator)OutputSplitter)UnionOperator)ZipOperator)LogicalOperatorLogicalPlanPhysicalPlan)AbstractAllToAll)Count)AbstractFrom)	InputData)Join)AbstractUDFMapFilterProjectStreamingRepartition)UnionZip)DownloadLimit)Read)StreamingSplit)Write)plan_all_to_all_op)plan_download_op)plan_read_op)plan_filter_opplan_project_opplan_streaming_repartition_opplan_udf_map_op)plan_write_op)DataContextLogicalOperatorType)bound
logical_opphysical_childrendata_contextreturnc                 X    t          |          dk    sJ t          || j                  S )z>Get the corresponding DAG of physical operators for InputData.r   )
input_datalenr   r5   r0   r1   r2   s      v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/data/_internal/planner/planner.pyplan_input_data_opr:   8   s>      !!Q&&&&(       opc                 V    t          |          dk    sJ t          || j                  S )Nr   r6   )r<   r1   r2   s      r9   plan_from_opr>   F   s0    
  !!Q&&&&<777r;   c                 F    t          |          dk    sJ t          |g|R  S N   )r7   r   _r1   r2   s      r9   plan_zip_oprD   O   s3     !!Q&&&&|8&78888r;   c                 F    t          |          dk    sJ t          |g|R  S r@   )r7   r   rB   s      r9   plan_union_oprF   T   s3     !!Q&&&&:(9::::r;   c                 d    t          |          dk    sJ t          | j        |d         |          S )N   r   )r7   r   _limitr8   s      r9   plan_limit_oprJ   Y   s7     !!Q&&&&*,=a,@,OOOr;   c                 r    t          |          dk    sJ t          |d         g|t          j                  S )NrH   r   )column_name)r7   r   r   COLUMN_NAMEr8   s      r9   plan_count_oprN   ^   sE     !!Q&&&&	1	%:K   r;   c                     t          |          dk    sJ t          ||d         |d         | j        | j        | j        | j        | j        | j        | j        | j	                  S )NrA   r   rH   )r2   left_input_opright_input_op	join_typeleft_key_columnsright_key_columnsleft_columns_suffixright_columns_suffixnum_partitionspartition_size_hint#aggregator_ray_remote_args_override)
r7   r   
_join_type_left_key_columns_right_key_columns_left_columns_suffix_right_columns_suffix_num_outputs_partition_size_hint_aggregator_ray_remote_argsr8   s      r9   plan_join_oprb   e   sx    
  !!Q&&&&!'*(+'#5$7&;'=!.&;,6,R   r;   c                 ~    t          |          dk    sJ t          |d         | j        | j        || j                  S )NrH   r   )nequalr2   locality_hints)r7   r   _num_splits_equal_locality_hintsr8   s      r9   plan_streaming_split_oprj   z   sR    
  !!Q&&&&!

 !!1   r;   c            
           e Zd ZdZi eeeeee	e
eeeeeeeeeeeeeeeeeeeeee e!e"e#Z$de%de&fdZ'de(de)fdZ*de(de+de,e-e.e(e-f         f         fdZ/d	S )
PlannerzThe planner to convert optimized logical to physical operators.

    Note that planner is only doing operators conversion. Physical optimization work is
    done by physical optimizer.
    logical_planr3   c                 x    |                      |j        |j                  \  }}t          |||j                  }|S )z@Convert logical to physical operators recursively in post-order.)_plan_recursivelydagcontextr   )selfrm   physical_dagop_mapphysical_plans        r9   planzPlanner.plan   sC    #55l2 
  
f %\6<;OPPr;   r0   c                 X    t          || j                  }||S t          d|           )Nz0Found unknown logical operator during planning: )find_plan_fn_DEFAULT_PLAN_FNS
ValueError)rr   r0   plan_fns      r9   get_plan_fnzPlanner.get_plan_fn   s<    z4+ABBNKzKK
 
 	
r;   r2   c                    i }g }|j         D ]E}|                     ||          \  }}|                    |           |                    |           F|                     |          } ||||          }	|	g}
|
rR|
                                }|j        rn6|                    |           |||<   |
                    |j                    |
R|||	<   |	|fS )a]  Plan a logical operator and its input dependencies recursively.

        Args:
            logical_op: The logical operator to plan.
            data_context: The data context.

        Returns:
            A tuple of the physical operator corresponding to the logical operator, and
            a mapping from physical to logical operators.
        )	input_dependenciesro   appendupdater|   pop_logical_operatorsset_logical_operatorsextend)rr   r0   r2   rt   r1   childphysical_childchild_op_mapr{   physical_opqueuecurr_physical_ops               r9   ro   zPlanner._plan_recursively   s    ;= 2 	( 	(E+/+A+A%+V+V(NL$$^444MM,''''"":.. gj*;\JJ
  		>$yy{{2 22:>>>'1F#$LL)<===  		> ){F""r;   N)0__name__
__module____qualname____doc__r"   r'   r   r:   r$   r,   r   r>   r   r(   r   r+   r   r%   r   rF   r   rD   r!   rJ   r   rN   r   r)   r   r*   r   rb   r#   rj   r    r&   ry   r   r   rv   r   PlanLogicalOpFnr|   r-   r   r
   r   ro    r;   r9   rl   rl      sm        l% 	} 	l	
 	 	 	, 	} 	[ 	} 	} 	 	; 	l 	/  	"!&     
o 
/ 
 
 
 
,#),#9D,#	o7G&G!HH	I,# ,# ,# ,# ,# ,#r;   rl   plan_fnsc                 b    |                                 D ]\  }}t          | |          r|c S dS )a  Find the plan function for a logical operator.

    This function goes through the plan functions in order and returns the first one
    that is an instance of the logical operator type.

    Args:
        logical_op: The logical operator to find the plan function for.
        plan_fns: The dictionary of plan functions.

    Returns:
        The plan function for the logical operator, or None if no plan function is
        found.
    N)items
isinstance)r0   r   op_typer{   s       r9   rx   rx      sG    $ %NN,,  j'** 	NNN	4r;   N)Rtypingr   r   r   r   r   r   r	   'ray.data._internal.execution.interfacesr
   9ray.data._internal.execution.operators.aggregate_num_rowsr   8ray.data._internal.execution.operators.input_data_bufferr   +ray.data._internal.execution.operators.joinr   5ray.data._internal.execution.operators.limit_operatorr   6ray.data._internal.execution.operators.output_splitterr   5ray.data._internal.execution.operators.union_operatorr   3ray.data._internal.execution.operators.zip_operatorr   %ray.data._internal.logical.interfacesr   r   r   8ray.data._internal.logical.operators.all_to_all_operatorr   3ray.data._internal.logical.operators.count_operatorr   3ray.data._internal.logical.operators.from_operatorsr   8ray.data._internal.logical.operators.input_data_operatorr   2ray.data._internal.logical.operators.join_operatorr   1ray.data._internal.logical.operators.map_operatorr   r   r   r   3ray.data._internal.logical.operators.n_ary_operatorr   r   8ray.data._internal.logical.operators.one_to_one_operatorr    r!   2ray.data._internal.logical.operators.read_operatorr"   =ray.data._internal.logical.operators.streaming_split_operatorr#   3ray.data._internal.logical.operators.write_operatorr$   -ray.data._internal.planner.plan_all_to_all_opr%   +ray.data._internal.planner.plan_download_opr&   'ray.data._internal.planner.plan_read_opr'   *ray.data._internal.planner.plan_udf_map_opr(   r)   r*   r+   (ray.data._internal.planner.plan_write_opr,   ray.data.contextr-   r.   r   r:   r>   rD   rF   rJ   rN   rb   rj   rl   rx   r   r;   r9   <module>r      s   G G G G G G G G G G G G G G G G G G D D D D D D           E D D D D D O O O O O O Q Q Q Q Q Q O O O O O O K K K K K K         
      F E E E E E L L L L L L N N N N N N C C C C C C            K J J J J J J J T T T T T T T T C C C C C C X X X X X X E E E E E E L L L L L L H H H H H H @ @ @ @ @ @            C B B B B B ( ( ( ( ( (g3?KKK $/0+>@PP
,-  	   88,-8 8 	8 8 8 89 9 9
; ; ;
P P P
  ,-  	   *,-    W# W# W# W# W# W# W# W#t+/_0E0V+Wo     r;   