§
    ø¦¹bV  ã                   ó\   — d dl Z  G d„ d¦  «        Z G d„ d¦  «        Z G d„ d¦  «        ZdS )é    Nc                   ó   — e Zd ZdZd„ ZdS )ÚProfileStatszB
    ProfileStats, runtime execution statistics of operation.
    c                 ó"   — || _         || _        d S ©N)Úrecords_producedÚexecution_time)Úselfr   r   s      úE/usr/lib/python3/dist-packages/redis/commands/graph/execution_plan.pyÚ__init__zProfileStats.__init__	   s   € Ø 0ˆÔØ,ˆÔÐÐó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r
   r   r      s-   € € € € € ðð ð-ð -ð -ð -ð -r   r   c                   óB   — e Zd ZdZd
d„Zd„ Zd„ Zdedefd„Z	de
fd	„ZdS )Ú	Operationz<
    Operation, single operation within execution plan.
    Nc                 ó>   — || _         || _        || _        g | _        dS )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)r	   r   r   r   s       r
   r   zOperation.__init__   s%   € ð ˆŒ	ØˆŒ	Ø*ˆÔØˆŒˆˆr   c                 óŠ   — t          |t          ¦  «        r| |u rt          d¦  «        ‚| j                             |¦  «         | S )Nzchild must be Operation)Ú
isinstancer   Ú	Exceptionr   Úappend)r	   Úchilds     r
   Úappend_childzOperation.append_child!   sF   € Ý˜%¥Ñ+Ô+ð 	7¨t°u¨}¨}ÝÐ5Ñ6Ô6Ð6àŒ×Ò˜UÑ#Ô#Ð#Øˆr   c                 ó*   — t          | j        ¦  «        S r   ©Úlenr   )r	   s    r
   Úchild_countzOperation.child_count(   s   € Ý�4”=Ñ!Ô!Ð!r   ÚoÚreturnc                 óp   — t          |t          ¦  «        sdS | j        |j        k    o| j        |j        k    S )NF)r   r   r   r   )r	   r#   s     r
   Ú__eq__zOperation.__eq__+   s6   € Ý˜!�YÑ'Ô'ð 	Ø�5àŒy˜AœFÒ"Ð: t¤y°A´FÒ':Ð:r   c                 ó>   — | j         €dn	d| j         z   }| j        › |› �S )NÚ z | )r   r   )r	   Úargs_strs     r
   Ú__str__zOperation.__str__1   s,   € ØœÐ*�2�2°¸¼	Ñ0AˆØ”)Ð'˜XÐ'Ð'Ð'r   )NN)r   r   r   r   r   r   r"   ÚobjectÚboolr&   Ústrr*   r   r   r
   r   r      s�   € € € € € ðð ðð ð ð ðð ð ð"ð "ð "ð;˜ð ; 4ð ;ð ;ð ;ð ;ð(˜ð (ð (ð (ð (ð (ð (r   r   c                   óF   — e Zd ZdZd„ Zd„ Zdefd„Zdede	fd„Z
d„ Zd	„ Zd
S )ÚExecutionPlanz2
    ExecutionPlan, collection of operations.
    c                 óÜ   — t          |t          ¦  «        st          d¦  «        ‚t          |d         t          ¦  «        rd„ |D ¦   «         }|| _        |                      ¦   «         | _        dS )zº
        Create a new execution plan.

        Args:
            plan: array of strings that represents the collection operations
                  the output from GRAPH.EXPLAIN
        zplan must be an arrayr   c                 ó6   — g | ]}|                      ¦   «         ‘ŒS r   )Údecode)Ú.0Úbs     r
   ú
<listcomp>z*ExecutionPlan.__init__.<locals>.<listcomp>G   s    € Ð-Ð-Ð- 1�A—H’H‘J”JÐ-Ð-Ð-r   N)r   Úlistr   ÚbytesÚplanÚ_operation_treeÚstructured_plan)r	   r8   s     r
   r   zExecutionPlan.__init__;   so   € õ ˜$¥Ñ%Ô%ð 	5ÝÐ3Ñ4Ô4Ð4å�d˜1”g�uÑ%Ô%ð 	.Ø-Ð-¨Ð-Ñ-Ô-ˆDàˆŒ	Ø#×3Ò3Ñ5Ô5ˆÔÐÐr   c                 ó  — ||k    rdS |                      ¦   «         |                      ¦   «         k    rdS t          |                      ¦   «         ¦  «        D ]1}|                      |j        |         |j        |         ¦  «        s dS Œ2dS )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Úis       r
   r=   z!ExecutionPlan._compare_operationsL   s�   € ð �VÒÐØ�5ð ×ÒÑÔ 6×#5Ò#5Ñ#7Ô#7Ò7Ð7Ø�5õ �v×)Ò)Ñ+Ô+Ñ,Ô,ð 	ð 	ˆAØ×+Ò+¨F¬O¸AÔ,>ÀÄÐPQÔ@RÑSÔSð Ø�u�uðð ˆtr   r$   c                 óR   — d„ }d„ }|                       | j        t          ||¦  «        S )Nc                 ó@   — d                      d„ | D ¦   «         ¦  «        S )Nú
c                 óF   — g | ]}|                      ¦   «         D ]}d |z   ‘ŒŒS )ú    )Ú
splitlines)r3   Ú	str_childÚlines      r
   r5   z?ExecutionPlan.__str__.<locals>.aggraget_str.<locals>.<listcomp>e   sO   € ð ð ð à!Ø )× 4Ò 4Ñ 6Ô 6ðð ð ð ˜T‘Mðð ð ð r   )Újoin)Ústr_childrens    r
   Úaggraget_strz+ExecutionPlan.__str__.<locals>.aggraget_strc   s4   € Ø—9’9ðð à%1ðñ ô ñô ð r   c                 ó   — | › d|› �S )NrC   r   )ÚxÚys     r
   Úcombine_strz*ExecutionPlan.__str__.<locals>.combine_strl   s   € Ø�;�;˜1�;�;Ðr   )Ú_operation_traverser:   r-   )r	   rK   rO   s      r
   r*   zExecutionPlan.__str__b   sF   € ð	ð 	ð 	ð	ð 	ð 	ð ×'Ò'ØÔ ¥# |°[ñ
ô 
ð 	
r   r#   c                 óx   — t          |t          ¦  «        sdS | j        }|j        }|                      ||¦  «        S )zfCompares two execution plans

        Return: True if the two plans are equal False otherwise
        F)r   r/   r:   r=   )r	   r#   r>   r?   s       r
   r&   zExecutionPlan.__eq__s   sE   € õ ˜!�]Ñ+Ô+ð 	Ø�5ð Ô%ˆØÔ"ˆð ×'Ò'¨°Ñ7Ô7Ð7r   c                 óª   ‡ ‡‡‡—  ‰|¦  «        }t          |j        ¦  «        dk    r|S ˆˆˆˆ fd„|j        D ¦   «         } ‰| ‰|¦  «        ¦  «        S )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
        r   c                 ó@   •— g | ]}‰                      |‰‰‰¦  «        ‘ŒS r   )rP   )r3   r   Úaggregate_fÚ	combine_fÚop_fr	   s     €€€€r
   r5   z5ExecutionPlan._operation_traverse.<locals>.<listcomp>“   s=   ø€ ð ð ð àð ×(Ò(¨°°kÀ9ÑMÔMðð ð r   r    )r	   ÚoprV   rT   rU   Úop_resr   s   ` ```  r
   rP   z!ExecutionPlan._operation_traverseƒ   s†   øøøø€ ð ��b‘”ˆÝˆrŒ{ÑÔ˜qÒ Ð ØˆMðð ð ð ð ð ð àœ[ðñ ô ˆHð
 �9˜V [ [°Ñ%:Ô%:Ñ;Ô;Ð;r   c                 óÌ  — d}d}g }d}d„ }|t          | j        ¦  «        k     �r9| j        |         }|                     d¦  «        }||k    rQ ||                     d¦  «        ¦  «        }|r)|                     ¦   «         }|                     |¦  «         |}|dz  }n§||dz   k    rU ||                     d¦  «        ¦  «        }|                     |¦  «         |                     |¦  «         |}|dz  }|dz  }nI||k     r4||z
  dz   }	t          |	¦  «        D ]}
|                     ¦   «         }Œ||	z  }nt          d¦  «        ‚|t          | j        ¦  «        k     �°9|d         S )z7Build the operation tree from the string representationr   Nc                 óP  — d }| d                               ¦   «         }|                      d¦  «         t          | ¦  «        dk    r¥d| d         v r›t          t	          j        d| d         ¦  «                             d¦  «        ¦  «        }t          t	          j        d| d         ¦  «                             d¦  «        ¦  «        }t          ||¦  «        }|                      d¦  «         t          |t          | ¦  «        dk    rd n| d                               ¦   «         |¦  «        S )Nr   zRecords producedéÿÿÿÿzRecords produced: (\d+)é   zExecution time: (\d+.\d+) ms)
ÚstripÚpopr!   ÚintÚreÚsearchÚgroupÚfloatr   r   )r   r   r   r   r   s        r
   Ú_create_operationz8ExecutionPlan._operation_tree.<locals>._create_operation£   s  € Ø ˆMØ˜”7—=’=‘?”?ˆDØ�HŠH�Q‰KŒKˆKÝ�4‰yŒy˜1Š}ˆ}Ð!3°t¸B´xÐ!?Ð!?Ý#&Ý”IÐ8¸$¸r¼(ÑCÔC×IÒIÈ!ÑLÔLñ$ô $Ð õ "'Ý”IÐ>ÀÀRÄÑIÔI×OÒOÐPQÑRÔRñ"ô "�õ !-Ð-=¸~Ñ NÔ N�Ø—’˜‘”�ÝØ�c $™iœi¨1šn˜n�d�d°$°q´'·-²-±/´/À=ñô ð r   rE   ú|r\   zcorrupted plan)	r!   r8   ÚcountÚsplitr^   r   r   r<   r   )r	   r@   ÚlevelÚstackÚcurrentrd   Ú
current_opÚop_levelr   Úlevels_backÚ_s              r
   r9   zExecutionPlan._operation_treeš   s©  € ð ˆØˆØˆØˆð	ð 	ð 	ð$ •#�d”i‘.”.Ò Ñ Øœ 1œˆJØ!×'Ò'¨Ñ/Ô/ˆHØ˜5Ò Ð ð *Ð)¨*×*:Ò*:¸3Ñ*?Ô*?Ñ@Ô@�Øð 0Ø#Ÿiši™kœk�GØ×(Ò(¨Ñ/Ô/Ð/Ø�Ø�Q‘��Ø˜U Q™YÒ&Ð&ð *Ð)¨*×*:Ò*:¸3Ñ*?Ô*?Ñ@Ô@�Ø×$Ò$ UÑ+Ô+Ð+Ø—’˜WÑ%Ô%Ð%Ø�Ø˜‘
�Ø�Q‘��Ø˜EÒ!Ð!ð $ hÑ.°Ñ2�Ý˜{Ñ+Ô+ð *ð *�AØ#Ÿiši™kœk�G�GØ˜Ñ$��åÐ 0Ñ1Ô1Ð1ð; •#�d”i‘.”.Ò Ñ ð< �QŒxˆr   N)r   r   r   r   r   r=   r-   r*   r+   r,   r&   rP   r9   r   r   r
   r/   r/   6   s—   € € € € € ðð ð6ð 6ð 6ð"ð ð ð,
˜ð 
ð 
ð 
ð 
ð"8˜ð 8 4ð 8ð 8ð 8ð 8ð <ð <ð <ð.9ð 9ð 9ð 9ð 9r   r/   )r`   r   r   r/   r   r   r
   ú<module>ro      s›   ðØ 	€	€	€	ð-ð -ð -ð -ð -ñ -ô -ð -ð%(ð %(ð %(ð %(ð %(ñ %(ô %(ð %(ðP]ð ]ð ]ð ]ð ]ñ ]ô ]ð ]ð ]ð ]r   