
    mBNj=                        d dl Z d dlmZ d dl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ZdZdZdZdZdZdZdZdZdZ dZ!dZ"eeeeeeeeee!e e"gZ# G d de      Z$d Z%d1dZ&de'fdZ(de)fdZ*de+fd Z,de-fd!Z.de
fd"Z/de
fd#Z0defd$Z1defd%Z2defd&Z3defd'Z4d( Z5defd)Z6defd*Z7defd+Z8defd,Z9d- Z:d. Z;e%e&e(e*e,e.e/e7e6e8e9e:e0e1e2e3e4gZ< G d/ d0      Z=y)2    N)OrderedDict)datedatetimetimetimezone)Enum)List)relativedelta)ResponseError   )Edge)SchemaVersionMismatchException)Node)PathzLabels addedzLabels removedzNodes createdzNodes deletedzProperties setzIndices createdzIndices deletedzCached executionzProperties removedzRelationships deletedzRelationships createdzinternal execution timec                   T    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZy)ResultSetScalarTypesa"  
    Enumeration representing different scalar types in the query result set.

    Attributes:
        VALUE_UNKNOWN   (int): Unknown scalar type  (0)
        VALUE_NULL      (int): Null scalar type     (1)
        VALUE_STRING    (int): String scalar type   (2)
        VALUE_INTEGER   (int): Integer scalar type  (3)
        VALUE_BOOLEAN   (int): Boolean scalar type  (4)
        VALUE_DOUBLE    (int): Double scalar type   (5)
        VALUE_ARRAY     (int): Array scalar type    (6)
        VALUE_EDGE      (int): Edge scalar type     (7)
        VALUE_NODE      (int): Node scalar type     (8)
        VALUE_PATH      (int): Path scalar type     (9)
        VALUE_MAP       (int): Map scalar type      (10)
        VALUE_POINT     (int): Point scalar type    (11)
        VALUE_VECTORF32 (int): Vector scalar type   (12)
        VALUE_DATETIME  (int): DateTime scalar type (13)
        VALUE_DATE      (int): Date scalar type     (14)
        VALUE_TIME      (int): Time scalar type     (15)
        VALUE_DURATION  (int): Duration scalar type (16)
    r   r                        	   
                     N)__name__
__module____qualname____doc__VALUE_UNKNOWN
VALUE_NULLVALUE_STRINGVALUE_INTEGERVALUE_BOOLEANVALUE_DOUBLEVALUE_ARRAY
VALUE_EDGE
VALUE_NODE
VALUE_PATH	VALUE_MAPVALUE_POINTVALUE_VECTORF32VALUE_DATETIME
VALUE_DATE
VALUE_TIMEVALUE_DURATION     f/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/falkordb/query_result.pyr   r   -   s^    . MJLMMLKJJJIKONJJNr8   r   c                 B    t         j                  j                  d       y)z
    Parse a value of unknown type.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        None
    zUnknown type
N)sysstderrwritevaluegraphs     r9   __parse_unknownrA   X   s     JJ%&r8   returnc                      y)z
    Parse a null value.

    Args:
        value: The null value.
        graph: The graph instance.

    Returns:
        None: Always returns None.
    Nr7   r>   s     r9   __parse_nullrD   f   s     r8   c                 |    t        | t              r| j                         S t        | t              st        |       S | S )z
    Parse the value as a string.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        str: The parsed string value.
    )
isinstancebytesdecodestrr>   s     r9   __parse_stringrJ   t   s3     %||~eS!5zLr8   c                     t        |       S )z
    Parse the integer value from the value.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        int: The parsed integer value.
    )intr>   s     r9   __parse_integerrM      s     u:r8   c                 P    t        | t              r| j                         n| } | dk(  S )z
    Parse the value as a boolean.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        bool: The parsed boolean value.
    true)rF   rG   rH   r>   s     r9   __parse_booleanrP      s$     )6ELLNEEF?r8   c                     t        |       S )z
    Parse the value as a double.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        float: The parsed double value.
    floatr>   s     r9   __parse_doublerT      s     <r8   c                 l    t        t        |             D cg c]  }t        | |   |       }}|S c c}w )z
    Parse an array of values.

    Args:
        value: The array value to parse.
        graph: The graph instance.

    Returns:
        list: The parsed list of values.
    )rangelenparse_scalar)r?   r@   iscalars       r9   __parse_arrayr[      s9     6;3u:5FG5Fl58U+5FFGM Hs   1c                 >    | D cg c]  }t        |       c}S c c}w )z
    Parse a vector32f.

    Args:
        value: The vector to parse.
        graph: The graph instance.

    Returns:
        list: The parsed vector.
    rR   )r?   r@   vs      r9   __parse_vectorf32r^      s      $$eE!He$$$s   c                 L    t        j                  | t        j                        S Ntz)r   fromtimestampr   utcr>   s     r9   __parse_datetimere      s    !!%HLL99r8   c                 h    t        j                  | t        j                        j	                         S r`   )r   rc   r   rd   r   r>   s     r9   __parse_daterg      "    !!%HLL9>>@@r8   c                 h    t        j                  | t        j                        j	                         S r`   )r   rc   r   rd   r   r>   s     r9   __parse_timerj      rh   r8   c                     t        j                  | t        j                        }t        dddt        j                        }t	        ||      S )Nra   i  r   )tzinfo)r   rc   r   rd   r
   )r?   r@   	timestampepochs       r9   __parse_durationro      s9    &&u>IT1a5EE**r8   c                 |    i }| D ]4  }|j                   j                  |d         }t        |dd |      }|||<   6 |S )z
    Parse node/edge properties.

    Args:
        props (List): List of properties.
        graph: The graph instance.

    Returns:
        dict: Dictionary containing parsed properties.
    r   r   N)schemaget_propertyrX   )propsr@   
propertiesprop	prop_name
prop_values         r9   __parse_entity_propertiesrx      sO     JLL--d1g6	!$qr(E2
 *
9 
 r8   c                     t        | d         }d}t        | d         dkD  r+| d   D cg c]  }|j                  j                  |       }}t	        | d   |      }t        |d||      S c c}w )z
    Parse the value to a node.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        Node: The parsed Node instance.
    r   Nr   r    )node_idaliaslabelsrt   )rL   rW   rq   	get_labelrx   r   )r?   r@   r{   r}   inner_labelrt   s         r9   __parse_noder      st     %(mGF
58}qINqR+%,,((5R*58U;Jr&ZPP Ss   "A+c                     t        | d         }|j                  j                  | d         }t        | d         }t        | d         }t        | d   |      }t	        |||||      S )z
    Parse the value to an edge.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        Edge: The parsed Edge instance.
    r   r   r   r   r   )edge_idrt   )rL   rq   get_relationrx   r   )r?   r@   r   relationsrc_node_iddest_node_idrt   s          r9   __parse_edger   
  sk     %(mG||((q2HeAh-KuQx=L*58U;JX|W r8   c                 V    t        | d   |      }t        | d   |      }t        ||      S )z
    Parse the value to a path.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        Path: The parsed Path instance.
    r   r   )rX   r   )r?   r@   nodesedgess       r9   __parse_pathr     s1     q5)Eq5)Eur8   c                     t               }t        |       }t        d|d      D ]&  }t        | |   |      }t	        | |dz      |      ||<   ( |S )z
    Parse the value as a map.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        OrderedDict: The parsed OrderedDict.
    r   r   r   )r   rW   rV   rJ   rX   )r?   r@   m	n_entriesrY   keys         r9   __parse_mapr   /  sV     	AE
I1i#U1Xu-eAElE2# $ Hr8   c                 @    t        | d         t        | d         d}|S )z
    Parse the value to point.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        dict: The parsed dictionary representing a point.
    r   r   )latitude	longituderR   )r?   r@   ps      r9   __parse_pointr   D  s#     58_5q?CAHr8   c                 J    t        | d         }| d   } t        |   | |      }|S )z
    Parse a scalar value from a value in the result set.

    Args:
        value: The value to parse.
        graph: The graph instance.

    Returns:
        Any: The parsed scalar value.
    r   r   )rL   PARSE_SCALAR_TYPES)r?   r@   scalar_typerZ   s       r9   rX   rX   S  s0     eAh-K!HE,UE:FMr8   c                   h   e Zd ZdZd Zd Zd Zd Zd Zd Z	e
defd	       Ze
defd
       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Ze
defd       Zy)QueryResultz@
    Represents the result of a query operation on a graph.
    c                     || _         g | _        g | _        g | _        | j	                  |       t        |      dk(  r|d   | _        y|d   | _        | j                  |       y)z
        Initializes a QueryResult instance.

        Args:
            graph: The graph on which the query was executed.
            response: The response from the server.
        r   r   N)_graph_header_result_set
_raw_stats_QueryResult__check_for_errorsrW   _QueryResult__parse_results)selfr@   responses      r9   __init__zQueryResult.__init__  sc      	)x=A&qkDO 'rlDO  *r8   c                     t        |d   t              r%|d   }t        |      dk(  r|d   }t        |      }|t        |d   t              r|d   y)z
        Checks if the response contains an error.

        Args:
            response: The response from the server.

        Raises:
            ResponseError: If an error is encountered.
        r   zversion mismatchr   r   N)rF   r   rI   r   )r   r   errorversions       r9   __check_for_errorszQueryResult.__check_for_errors  s_     hqk=1QKE5z//"1+6w?K hrlM22, 3r8   c                     | j                  |      | _        t        | j                        dk(  ry| j                  |      | _        y)z
        Parse the query execution result returned from the server.

        Args:
            raw_result_set: The raw result set from the server.
        r   N)_QueryResult__parse_headerr   rW   _QueryResult__parse_recordsr   )r   raw_result_sets     r9   __parse_resultszQueryResult.__parse_results  s?     **>: t||!//?r8   c                     | j                   D ]7  }||v st        |j                  d      d   j                  d      d         c S  y)a  
        Get the value of a specific statistical metric.

        Args:
            s (str): The statistical metric to retrieve.

        Returns:
            float: The value of the specified statistical metric.
                Returns 0 if the metric is not found.
        z: r    r   )r   rS   split)r   sstats      r9   __get_statisticszQueryResult.__get_statistics  sG     OODDyTZZ-a066s;A>?? $ r8   c                     |d   }|S )z
        Parse the header of the result.

        Args:
            raw_result_set: The raw result set from the server.

        Returns:
            list: An array of column name/column type pairs.
        r   r7   )r   r   headers      r9   __parse_headerzQueryResult.__parse_header  s      "r8   c                     |d   D cg c]&  }|D cg c]  }t        || j                         c}( }}}|S c c}w c c}}w )z
        Parses the result set and returns a list of records.

        Args:
            raw_result_set: The raw result set from the server.

        Returns:
            list: A list of records.
        r   )rX   r   )r   r   rowcellrecordss        r9   __parse_recordszQueryResult.__parse_records  sT     &a(
( :==\$,=( 	 

 	 >
s   	>9>>rB   c                     | j                   S )z~
        Get the header of the result.

        Returns:
            list: An array of column name/column type pairs.
        )r   r   s    r9   r   zQueryResult.header  s     ||r8   c                     | j                   S )z
        Get a list of the results from a query.

        Returns:
            list: A list of each row returned from a query.
        )r   r   s    r9   
result_setzQueryResult.result_set  s     r8   c                 ,    | j                  t              S )zy
        Get the number of labels added in the query.

        Returns:
        int: The number of labels added.
        )_QueryResult__get_statisticsLABELS_ADDEDr   s    r9   labels_addedzQueryResult.labels_added  s     $$\22r8   c                 ,    | j                  t              S )z
        Get the number of labels removed in the query.

        Returns:
            int: The number of labels removed.
        )r   LABELS_REMOVEDr   s    r9   labels_removedzQueryResult.labels_removed
       $$^44r8   c                 ,    | j                  t              S )z
        Get the number of nodes created in the query.

        Returns:
            int: The number of nodes created.
        )r   NODES_CREATEDr   s    r9   nodes_createdzQueryResult.nodes_created       $$]33r8   c                 ,    | j                  t              S )z
        Get the number of nodes deleted in the query.

        Returns:
            int: The number of nodes deleted.
        )r   NODES_DELETEDr   s    r9   nodes_deletedzQueryResult.nodes_deleted  r   r8   c                 ,    | j                  t              S )z
        Get the number of properties set in the query.

        Returns:
            int: The number of properties set.
        )r   PROPERTIES_SETr   s    r9   properties_setzQueryResult.properties_set(  r   r8   c                 ,    | j                  t              S )z
        Get the number of properties removed in the query.

        Returns:
            int: The number of properties removed.
        )r   PROPERTIES_REMOVEDr   s    r9   properties_removedzQueryResult.properties_removed2  s     $$%788r8   c                 ,    | j                  t              S )z
        Get the number of relationships created in the query.

        Returns:
            int: The number of relationships created.
        )r   RELATIONSHIPS_CREATEDr   s    r9   relationships_createdz!QueryResult.relationships_created<       $$%:;;r8   c                 ,    | j                  t              S )z
        Get the number of relationships deleted in the query.

        Returns:
            int: The number of relationships deleted.
        )r   RELATIONSHIPS_DELETEDr   s    r9   relationships_deletedz!QueryResult.relationships_deletedF  r   r8   c                 ,    | j                  t              S )z
        Get the number of indices created in the query.

        Returns:
            int: The number of indices created.
        )r   INDICES_CREATEDr   s    r9   indices_createdzQueryResult.indices_createdP       $$_55r8   c                 ,    | j                  t              S )z
        Get the number of indices deleted in the query.

        Returns:
            int: The number of indices deleted.
        )r   INDICES_DELETEDr   s    r9   indices_deletedzQueryResult.indices_deletedZ  r   r8   c                 2    | j                  t              dk(  S )z
        Check if the query execution plan was cached.

        Returns:
            bool: True if the query execution plan was cached, False otherwise.
        r   )r   CACHED_EXECUTIONr   s    r9   cached_executionzQueryResult.cached_executiond  s     $$%56!;;r8   c                 ,    | j                  t              S )z
        Get the server execution time of the query.

        Returns:
            float: The server execution time of the query in milliseconds.
        )r   INTERNAL_EXECUTION_TIMEr   s    r9   run_time_mszQueryResult.run_time_msn  s     $$%<==r8   N)r"   r#   r$   r%   r   r   r   r   r   r   propertylistr   r   rL   r   r   r   r   r   r   r   r   r   r   boolr   rS   r   r7   r8   r9   r   r   z  s   +.,@""     D     3c 3 3 5 5 5 4s 4 4 4s 4 4 5 5 5 9C 9 9 <s < < <s < < 6 6 6 6 6 6 <$ < < >U > >r8   r   )rB   N)>r;   collectionsr   r   r   r   r   enumr   typingr	   dateutil.relativedeltar
   redisr   edger   
exceptionsr   noder   pathr   r   r   r   r   r   r   r   r   r   r   r   r   STATSr   rA   rD   rI   rJ   rL   rM   r   rP   rS   rT   r[   r^   re   rg   rj   ro   rx   r   r   r   r   r   rX   r   r   r7   r8   r9   <module>r      s   
 # 3 3   0   6   !!##% ) / / 3  	 (4 (V'C (S T E 4 %t %:h :A$ AA$ A+m +(Q$ Q&$ *$   *& # *|> |>r8   