bTddlmZddlmZddlmZddlmZddlm Z GddZ y ) ) DataError) ResponseError)VersionMismatchException) ExecutionPlan) QueryResultc`eZdZdZdZddZdZdZdZdZ d Z d Z dd Z d Z dd ZddZy) GraphCommandszRedisGraph Commandsc ~t|jdk(rt|jdk(ryd}|jjD]\}}|t |dzz }|dj |jDcgc] }t |c}z }|ddk(r|dd}|j |Scc}w)z& Create entire graph. rNzCREATE ,)lennodesedgesitemsstrjoinquery)selfr_nodeedges ?/usr/lib/python3/dist-packages/redis/commands/graph/commands.pycommitzGraphCommands.commit s tzz?a C Oq$8zz'') %GAt SY_ $E % <3t9<== 9 #2JEzz%  =sB: Nc|}||j||z}|rd}n|rdnd}||j|dg}|r"t|ts t d|d|gz } |j |} t || |S#t$rH} dt| vr td d t| vr|r|j|||d cYd} ~ S| d} ~ wt$r?} | j|_ |j|j||||cYd} ~ Sd} ~ wwxYw) a Executes a query against the graph. For more information see `GRAPH.QUERY `_. # noqa Args: q : str The query. params : dict Query parameters. timeout : int Maximum runtime for read queries in milliseconds. read_only : bool Executes a readonly query if set to True. profile : bool Return details on results produced by and time spent in each operation. Nz GRAPH.PROFILEzGRAPH.RO_QUERYz GRAPH.QUERYz --compactz+Timeout argument must be a positive integertimeoutzwrong number of argumentsz>Note: RedisGraph Python requires server version 2.2.8 or abovezunknown commandF) read_only)_build_params_headername isinstanceint Exceptionexecute_commandrrrprintrrversion_refresh_schema) rqparamsrrprofilercmdcommandresponsees rrzGraphCommands.querys&*  --f5=E !C&/"]C 5+6 gs+ MNN  7+ +G =+t++W5HtXw7 7 *c!f4T!CF*yzz!VWzFFG' =99DL  "::a)< <  =s6A55 D >;C9D ?C D  4DD D cDd}|t|z }|j|S)z Merge pattern. zMERGE )rr)rpatternrs rmergezGraphCommands.merge^s& Wzz%  cZ|j|jd|jS)z| Deletes graph. For more information see `DELETE `_. # noqa z GRAPH.DELETE) _clear_schemar#rrs rdeletezGraphCommands.deletegs' ##NDII>>r1c@|ji|_g|_y)zT Commit the graph and reset the edges and the nodes to zero length. N)rrrr4s rflushzGraphCommands.flushps   r1c td)zInternal only. Not supported.zVGRAPH.BULK is internal only. Use https://github.com/redisgraph/redisgraph-bulk-loader.)NotImplementedError)rkwargss rbulkzGraphCommands.bulkxs! H  r1c(|j|dS)ar Execute a query and produce an execution plan augmented with metrics for each operation's execution. Return a string representation of a query execution plan, with details on results produced by and time spent in each operation. For more information see `GRAPH.PROFILE `_. # noqa T)r))r)rrs rr)zGraphCommands.profileszz%z..r1c:|jd|jS)a Get a list containing up to 10 of the slowest queries issued against the given graph ID. For more information see `GRAPH.SLOWLOG `_. # noqa Each item in the list has the following structure: 1. A unix timestamp at which the log entry was processed. 2. The issued command. 3. The issued query. 4. The amount of time needed for its execution, in milliseconds. z GRAPH.SLOWLOG)r#rr4s rslowlogzGraphCommands.slowlogs##OTYY??r1cz|rdnd|g}||r|j|n td|jdg|S)a Retrieve or update a RedisGraph configuration. For more information see `https://redis.io/commands/graph.config-get/>`_. # noqa Args: name : str The name of the configuration value : The value we want to set (can be used only when `set` is on) set : bool Turn on to set a configuration. Default behavior is get. SETGETz3``value`` can be provided only when ``set`` is Truez GRAPH.CONFIG)appendrr#)rrvaluesetr(s rconfigzGraphCommands.configsQ%E40   e$I$t##N`_. # noqa z GRAPH.LIST)r#r4s r list_keyszGraphCommands.list_keyss ##L11r1c||j||z}|jd|j|}t|dtr|Dcgc]}|j }}dj |Scc}w)z Get the execution plan for given query, GRAPH.EXPLAIN returns an array of operations. Args: query: the query that will be executed params: query parameters GRAPH.EXPLAINr )rr#rr bytesdecoder)rrr(planbs rexecution_planzGraphCommands.execution_plansq  --f5=E##OTYYF d1gu %(,-1AHHJ-D-yy.s A5c~||j||z}|jd|j|}t|S)a8 Get the execution plan for given query, GRAPH.EXPLAIN returns ExecutionPlan object. For more information see `GRAPH.EXPLAIN `_. # noqa Args: query: the query that will be executed params: query parameters rI)rr#rr)rrr(rMs rexplainzGraphCommands.explainsB  --f5=E##OTYYFT""r1)NNFF)NF)N)__name__ __module__ __qualname____doc__rrr0r5r7r;r)r>rErGrOrQr1rr r sC!&==~!? / @=02"#r1r N) redisrredis.exceptionsr exceptionsrrOr query_resultrr rVr1rr[s *0)%L#L#r1