
    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%d0d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. d/      Z=y)1    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                           	   
                     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     n/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/falkordb/asyncio/query_result.pyr   r   -   s^    . MJLMMLKJJJIKONJJNr8   r   c                 J   K   t         j                  j                  d       yw)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%&s   !#returnc                    K   yw)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      s   c                    K   t        | t              r| j                         S t        | t              st        |       S | S w)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   s7      %||~eS!5zLs   >A c                     K   t        |       S w)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:   c                 X   K   t        | t              r| j                         n| } | dk(  S w)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_booleanrQ      s(      )6ELLNEEF?s   (*c                     K   t        |       S w)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_doublerU      s      <rN   c                    K   t        t        |             D cg c]  }t        | |   |       d{    }}|S 7 
c c}w 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.
    N)rangelenparse_scalar)r?   r@   iscalars       r9   __parse_arrayr\      sF      <AU;LM;LaLq5111;LFMM 2Ms   A=;
=A=Ac                 F   K   | D cg c]  }t        |       c}S c c}w w)z
    Parse a vector32f.

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

    Returns:
        list: The parsed vector.
    rS   )r?   r@   vs      r9   __parse_vectorf32r_      s$      $$eE!He$$$s   !!c                 T   K   t        j                  | t        j                        S wNtz)r   fromtimestampr   utcr>   s     r9   __parse_datetimerf      s     !!%HLL99s   &(c                 p   K   t        j                  | t        j                        j	                         S wra   )r   rd   r   re   r   r>   s     r9   __parse_daterh      &     !!%HLL9>>@@   46c                 p   K   t        j                  | t        j                        j	                         S wra   )r   rd   r   re   r   r>   s     r9   __parse_timerl      ri   rj   c                    K   t        j                  | t        j                        }t        dddt        j                        }t	        ||      S w)Nrb   i  r   )tzinfo)r   rd   r   re   r
   )r?   r@   	timestampepochs       r9   __parse_durationrq      s=     &&u>IT1a5EE**s   AAc                    K   i }| D ]D  }|j                   j                  |d          d{   }t        |dd |       d{   }|||<   F |S 7 $7 w)z
    Parse node/edge properties.

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

    Returns:
        dict: Dictionary containing parsed properties.
    r   Nr   )schemaget_propertyrY   )propsr@   
propertiesprop	prop_name
prop_values         r9   __parse_entity_propertiesrz      sb      J,,33DG<<	'QR%88
 *
9 
 	 =8s!   )AAAAAAc                   K   t        | d         }d}t        | d         dkD  r3| d   D cg c]%  }|j                  j                  |       d{   ' }}t	        | d   |       d{   }t        |d||      S 7 .c c}w 7 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labelsrv   )rL   rX   rs   	get_labelrz   r   )r?   r@   r}   r   inner_labelrv   s         r9   __parse_noder      s      %(mGF
58}qOTUVxXx..{;;;xX0q5AAJr&ZPP <XAs4   )B#A?A=
A?B)B*B=A??Bc                    K   t        | d         }|j                  j                  | d          d{   }t        | d         }t        | d         }t        | d   |       d{   }t	        |||||      S 7 G7 w)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   Nr   r   r   )edge_idrv   )rL   rs   get_relationrz   r   )r?   r@   r   relationsrc_node_iddest_node_idrv   s          r9   __parse_edger   
  s      %(mG\\..uQx88HeAh-KuQx=L0q5AAJX|W 	 9 Bs!   0A>A:2A>%A<&A><A>c                    K   t        | d   |       d{   }t        | d   |       d{   }t        ||      S 7 '7 w)z
    Parse the value to a path.

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

    Returns:
        Path: The parsed Path instance.
    r   Nr   )rY   r   )r?   r@   nodesedgess       r9   __parse_pathr     sD      uQx//EuQx//Eu 0/s   A=A?AAc                    K   t               }t        |       }t        d|d      D ]6  }t        | |   |       d{   }t	        | |dz      |       d{   ||<   8 |S 7 %7 w)z
    Parse the value as a map.

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

    Returns:
        OrderedDict: The parsed OrderedDict.
    r   r   Nr   )r   rX   rW   rJ   rY   )r?   r@   m	n_entriesrZ   keys         r9   __parse_mapr   /  si      	AE
I1i#"58U33#E!a%L%88# $ H 48s!   8A$A A$A"A$"A$c                 H   K   t        | d         t        | d         d}|S w)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	longituderS   )r?   r@   ps      r9   __parse_pointr   D  s'      58_5q?CAHs    "c                 f   K   t        | d         }| d   } t        |   | |       d{   }|S 7 w)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   N)rL   PARSE_SCALAR_TYPES)r?   r@   scalar_typer[   s       r9   rY   rY   S  s=      eAh-K!HE%k25%@@FM As   &1/1c                   B   e Zd 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y)QueryResultz@
    Represents the result of a query operation on a graph.
    c                 <    || _         g | _        g | _        g | _        y)z
        Initializes a QueryResult instance.

        Args:
            graph: The graph on which the query was executed.
        N)r@   header
result_set
_raw_stats)selfr@   s     r9   __init__zQueryResult.__init__  s      
r8   c                    K   | j                  |       t        |      dk(  r|d   | _        y|d   | _        | j                  |       d{    y7 w)zx
        Parse the response from the server.

        Args:
            response: The response from the server.
        r   r   N)_QueryResult__check_for_errorsrX   r   _QueryResult__parse_results)r   responses     r9   parsezQueryResult.parse  sN      	)x=A&qkDO 'rlDO&&x000s   A	AAA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                    K   | j                  |      | _        t        | j                        dk(  ry| j                  |       d{   | _        y7 
w)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   rX   _QueryResult__parse_recordsr   )r   raw_result_sets     r9   __parse_resultszQueryResult.__parse_results  sH      )).9 t{{q  $ 4 4^ DDDs   AAAA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   rT   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   r   s      r9   __parse_headerzQueryResult.__parse_header  s      "r8   c                    K   g }|d   D ]I  }g }|D ]/  }|j                  t        || j                         d{          1 |j                  |       K |S 7 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   N)appendrY   r@   )r   r   recordsrowrecordcells         r9   __parse_recordszQueryResult.__parse_records  s^      !!$CFLtzz$BBC NN6"	 %  Cs   6AA ArB   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_ADDEDr   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_removed(  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_created2       $$%:;;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_deleted<  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_createdF       $$_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_deletedP  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_executionZ  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_msd  s     $$%<==r8   N)r"   r#   r$   r%   r   r   r   r   r   r   r   propertyrL   r   r   r   r   r   r   r   r   r   r   boolr   rT   r   r7   r8   r9   r   r   z  so   1$,E"& 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   falkordb.edger   falkordb.exceptionsr   falkordb.noder   falkordb.pathr   r   r   r   r   r   r   r   r   r   r   r   r   STATSr   rA   rD   rI   rJ   rL   rM   r   rQ   rT   rU   r\   r_   rf   rh   rl   rq   rz   r   r   r   r   r   rY   r   r   r7   r8   r9   <module>r      s   
 # 3 3   0   >   !!##% ) / / 3  	 (4 (V'# (3 4 %  %T %:H :A AA A+M +(Q Q& *  { *& # *r> r>r8   