HEX
Server: LiteSpeed
System: Linux ws4.angoweb.net 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 11 04:57:59 EST 2025 x86_64
User: tswangoe (2287)
PHP: 8.1.33
Disabled: show_source, system, shell_exec, passthru, exec, phpinfo, popen, proc_open
Upload Files
File: //lib/python3.9/site-packages/redis/commands/graph/__pycache__/execution_plan.cpython-39.opt-1.pyc
a

��bV�@s6ddlZGdd�d�ZGdd�d�ZGdd�d�ZdS)�Nc@seZdZdZdd�ZdS)�ProfileStatszB
    ProfileStats, runtime execution statistics of operation.
    cCs||_||_dS�N)�records_produced�execution_time)�selfrr�r�G/usr/lib/python3.9/site-packages/redis/commands/graph/execution_plan.py�__init__	szProfileStats.__init__N)�__name__�
__module__�__qualname__�__doc__r	rrrrrsrc@sHeZdZdZddd�Zdd�Zdd�Zeed	�d
d�Z	e
d�d
d�ZdS)�	Operationz<
    Operation, single operation within execution plan.
    NcCs||_||_||_g|_dS)z�
        Create a new operation.

        Args:
            name: string that represents the name of the operation
            args: operation arguments
            profile_stats: profile statistics
        N)�name�args�
profile_stats�children)rrrrrrrr	s	zOperation.__init__cCs*t|t�r||urtd��|j�|�|S)Nzchild must be Operation)�
isinstancer�	Exceptionr�append)r�childrrr�append_child!szOperation.append_childcCs
t|j�Sr��lenr)rrrr�child_count(szOperation.child_count��o�returncCs&t|t�sdS|j|jko$|j|jkS)NF)rrrr)rrrrr�__eq__+s
zOperation.__eq__�rcCs&|jdurdnd|j}|j�|��S)N�z | )rr)r�args_strrrr�__str__1szOperation.__str__)NN)r
rrr
r	rr�object�boolr�strr"rrrrrs
rc@sNeZdZdZdd�Zdd�Zed�dd�Zee	d	�d
d�Z
dd
�Zdd�ZdS)�
ExecutionPlanz2
    ExecutionPlan, collection of operations.
    cCsBt|t�std��t|dt�r.dd�|D�}||_|��|_dS)z�
        Create a new execution plan.

        Args:
            plan: array of strings that represents the collection operations
                  the output from GRAPH.EXPLAIN
        zplan must be an arrayrcSsg|]}|���qSr)�decode)�.0�brrr�
<listcomp>G�z*ExecutionPlan.__init__.<locals>.<listcomp>N)r�listr�bytes�plan�_operation_tree�structured_plan)rr.rrrr	;s
zExecutionPlan.__init__cCsT||krdS|��|��kr dSt|���D]"}|�|j||j|�s,dSq,dS)z{
        Compare execution plan operation tree

        Return: True if operation trees are equal, False otherwise
        FT)r�range�_compare_operationsr)r�root_a�root_b�irrrr2Lsz!ExecutionPlan._compare_operationsrcCs"dd�}dd�}|�|jt||�S)NcSsd�dd�|D��S)N�
cSs"g|]}|��D]}d|�qqS)�    )�
splitlines)r(Z	str_child�linerrrr*es�z?ExecutionPlan.__str__.<locals>.aggraget_str.<locals>.<listcomp>)�join)Zstr_childrenrrr�aggraget_strcs
��z+ExecutionPlan.__str__.<locals>.aggraget_strcSs|�d|��S)Nr6r)�x�yrrr�combine_strlsz*ExecutionPlan.__str__.<locals>.combine_str)�_operation_traverser0r%)rr;r>rrrr"bs
	
�zExecutionPlan.__str__rcCs&t|t�sdS|j}|j}|�||�S)zfCompares two execution plans

        Return: True if the two plans are equal False otherwise
        F)rr&r0r2)rrr3r4rrrrss

zExecutionPlan.__eq__csF�|�}t|j�dkr|S����fdd�|jD�}�|�|��SdS)aq
        Traverse operation tree recursively applying functions

        Args:
            op: operation to traverse
            op_f: function applied for each operation
            aggregate_f: aggregation function applied for all children of a single operation
            combine_f: combine function applied for the operation result and the children result
        rcsg|]}��|�����qSr)r?)r(r��aggregate_f�	combine_f�op_frrrr*�s�z5ExecutionPlan._operation_traverse.<locals>.<listcomp>Nr)r�oprCrArBZop_resrrr@rr?�s�z!ExecutionPlan._operation_traversecCs�d}d}g}d}dd�}|t|j�kr�|j|}|�d�}||krt||�d��}|rf|��}|�|�|}|d7}q||dkr�||�d��}|�|�|�|�|}|d7}|d7}q||kr�||d}	t|	�D]}
|��}q�||	8}qtd��q|dS)	z7Build the operation tree from the string representationrNcSs�d}|d��}|�d�t|�dkrzd|dvrztt�d|d��d��}tt�d|d��d��}t||�}|�d�t	|t|�dkr�dn
|d��|�S)NrzRecords produced���zRecords produced: (\d+)�zExecution time: (\d+.\d+) ms)
�strip�popr�int�re�search�group�floatrr)rrrrrrrr�_create_operation�s
��

�z8ExecutionPlan._operation_tree.<locals>._create_operationr7�|rFzcorrupted plan)	rr.�count�splitrHrrr1r)rr5�level�stack�currentrNZ
current_opZop_levelrZlevels_back�_rrrr/�s:









zExecutionPlan._operation_treeN)
r
rrr
r	r2r%r"r#r$rr?r/rrrrr&6sr&)rJrrr&rrrr�<module>s
(