o
    $i                     @   sH  d dl mZmZ ddlmZ d dl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 d dlmZ eeeeeegZeeeeegZ edefddZ!edefddZ"G dd deZ#G dd deZ$deee	ge	f  fddZ%dedefddZ&dS )    )CallableList   )Ruleset)LogicalPlan	OptimizerPhysicalPlanPlanRule)CombineRepartitions)%ConfigureMapTaskMemoryUsingOutputSize)InheritBatchFormatRule)InheritTargetMaxBlockSizeRule)LimitPushdownRule)FuseOperators)PredicatePushdown)ProjectionPushdown)SetReadParallelismRule)DeveloperAPIreturnc                   C      t S N)_LOGICAL_RULESET r   r   b/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/data/_internal/logical/optimizers.pyget_logical_ruleset/      r   c                   C   r   r   )_PHYSICAL_RULESETr   r   r   r   get_physical_ruleset4   r   r   c                   @   &   e Zd ZdZedee fddZdS )LogicalOptimizerz$The optimizer for logical operators.r   c                 C      dd t  D S )Nc                 S      g | ]}| qS r   r   .0rule_clsr   r   r   
<listcomp>>       z*LogicalOptimizer.rules.<locals>.<listcomp>)r   selfr   r   r   rules<      zLogicalOptimizer.rulesN__name__
__module____qualname____doc__propertyr   r
   r*   r   r   r   r   r    9       r    c                   @   r   )PhysicalOptimizerz%The optimizer for physical operators.r   c                 C   r!   )Nc                 S   r"   r   r   r#   r   r   r   r&   F   r'   z+PhysicalOptimizer.rules.<locals>.<listcomp>)r   r(   r   r   r   r*   D   r+   zPhysicalOptimizer.rulesNr,   r   r   r   r   r3   A   r2   r3   c                  C   s"   ddl m}  t j|  jt jgS )ad  Get the list of transformation functions to convert a logical plan
    to an optimized physical plan.

    This returns the 3 transformation steps:
    1. Logical optimization
    2. Planning (logical -> physical operators)
    3. Physical optimization

    Returns:
        A list of transformation functions, each taking a Plan and returning a Plan.
    r   create_planner)ray.data._internal.plannerr5   r    optimizeplanr3   r4   r   r   r   get_plan_conversion_fnsI   s
   r9   logical_planc                 C   s,   t  \}}}|| }|j| _||}||S )a  Get the physical execution plan for the provided logical plan.

    This process has 3 steps:
    (1) logical optimization: optimize logical operators.
    (2) planning: convert logical to physical operators.
    (3) physical optimization: optimize physical operators.
    )r9   dag_dag)r:   optimize_logicalr8   optimize_physicaloptimized_logical_planphysical_planr   r   r   get_execution_plan^   s
   
rA   N)'typingr   r   rulesetr   %ray.data._internal.logical.interfacesr   r   r   r	   r
   5ray.data._internal.logical.rules.combine_repartitionsr   :ray.data._internal.logical.rules.configure_map_task_memoryr   5ray.data._internal.logical.rules.inherit_batch_formatr   >ray.data._internal.logical.rules.inherit_target_max_block_sizer   /ray.data._internal.logical.rules.limit_pushdownr   0ray.data._internal.logical.rules.operator_fusionr   3ray.data._internal.logical.rules.predicate_pushdownr   4ray.data._internal.logical.rules.projection_pushdownr   5ray.data._internal.logical.rules.set_read_parallelismr   ray.util.annotationsr   r   r   r   r   r    r3   r9   rA   r   r   r   r   <module>   sH    
