b&eZGddZGddZGddZGddeZGdd eZGd d ZGd d ZGddZ y)ceZdZddZdZy)Limitc ||_||_yN)offsetcount)selfrrs C/usr/lib/python3/dist-packages/redis/commands/search/aggregation.py__init__zLimit.__init__s  ct|jr+dt|jt|jgSgS)NLIMIT)rstrrrs r build_argszLimit.build_args s, ::S-s4::? ?Ir N)r__name__ __module__ __qualname__r rr r rrs r rc0eZdZdZdZdZdZedZy)Reducerzr Base reducer object for all reducers. See the `redisearch.reducers` module for the actual reducers. Nc.||_d|_d|_yr)_args_field_aliasrargss r r zReducer.__init__s   r cp|tur&|js td|jdd}||_|S)a Set the alias for this reducer. ### Parameters - **alias**: The value of the alias for this reducer. If this is the special value `aggregation.FIELDNAME` then this reducer will be aliased using the same name as the field upon which it operates. Note that using `FIELDNAME` is only possible on reducers which operate on a single field value. This method returns the `Reducer` object making it suitable for chaining. z(Cannot use FIELDNAME alias with no fieldN) FIELDNAMEr ValueErrorr)raliass r r#z Reducer.aliass: I ;; !KLLKKOE  r c|jSr)rrs r rz Reducer.args5s zzr ) rrr__doc__NAMEr r#propertyrrr r rrs, D .r rceZdZdZdZdZy) SortDirectionz@ This special class is used to indicate sort direction. Nc||_yr)field)rr+s r r zSortDirection.__init__As  r )rrrr% DIRSTRINGr rr r r)r):sIr r)ceZdZdZdZy)AsczK Indicate that the given field should be sorted in ascending order ASCNrrrr%r,rr r r.r.EsIr r.ceZdZdZdZy)DesczL Indicate that the given field should be sorted in descending order DESCNr0rr r r2r2MsIr r2cVeZdZdZddZdZdZdZdZdZ dZ d Z d Z dd Z d Zy )AggregateRequestzH Aggregation request which can be passed to `Client.aggregate`. c||_g|_g|_d|_t |_d|_d|_d|_g|_ y)a} Create an aggregation request. This request may then be passed to `client.aggregate()`. In order for the request to be usable, it must contain at least one group. - **query** Query string for filtering records. All member methods (except `build_args()`) return the object itself, making them useful for chaining. FrN) _query_aggregateplan _loadfields_loadallr_limit_max _with_schema _verbatim_cursor)rquerys r r zAggregateRequest.__init__ZsH   g  ! r cR|r|jj||Sd|_|S)aC Indicate the fields to be returned in the response. These fields are returned in addition to any others implicitly specified. ### Parameters - **fields**: If fields not specified, all the fields will be loaded. Otherwise, fields should be given in the format of `@field`. T)r9extendr:)rfieldss r loadzAggregateRequest.loadqs0     # #F + !DM r c t|tr|gn|}t|tr|gn|}dtt|g|}|D]i}|d|jtt|j gz }|j |j |jY|d|jgz }k|jj ||S)a| Specify by which fields to group the aggregation. ### Parameters - **fields**: Fields to group by. This can either be a single string, or a list of strings. both cases, the field should be specified as `@field`. - **reducers**: One or more reducers. Reducers may be found in the `aggregation` module. GROUPBYREDUCEAS) isinstancerrlenr&rrBrr8)rrCreducersretreducers r group_byzAggregateRequest.group_bys(4&&!+Hg!>H:H#c&k*4V4 .G HgllCGLL0A,BC CC JJw|| $~~)gnn--  . ""3' r c |jD]-\}}d|g}||d|gz }|jj|/|S)aQ Specify one or more projection expressions to add to each result ### Parameters - **kwexpr**: One or more key-value pairs for a projection. The key is the alias for the projection, and the value is the projection expression itself, for example `apply(square_root="sqrt(@foo)")` APPLYrH)itemsr8rB)rkwexprr#exprrLs r applyzAggregateRequest.applysU"<<> ,KE4D/C e}$    & &s +  ,  r c(t|||_|S)a Sets the limit for the most recent group or query. If no group has been defined yet (via `group_by()`) then this sets the limit for the initial pool of results from the query. Otherwise, this limits the number of items operated on from the previous group. Setting a limit on the initial search results may be useful when attempting to execute an aggregation on a sample of a large data set. ### Parameters - **offset**: Result offset from which to begin paging - **num**: Number of results to return Example of sorting the initial results: ``` AggregateRequest("@sale_amount:[10000, inf]") .limit(0, 10) .group_by("@state", r.count()) ``` Will only group by the states found in the first 10 results of the query `@sale_amount:[10000, inf]`. On the other hand, ``` AggregateRequest("@sale_amount:[10000, inf]") .limit(0, 1000) .group_by("@state", r.count() .limit(0, 10) ``` Will group all the results matching the query, but only return the first 10 groups. If you only wish to return a *top-N* style query, consider using `sort_by()` instead. )rr;)rrnums r limitzAggregateRequest.limitsTFC(  r ct|ttfr|g}g}|D]4}t|tr||j|jgz }/||gz }6dtt |g}|j ||jdd}|dkDr|dt|gz }|jj ||S)a, Indicate how the results should be sorted. This can also be used for *top-N* style queries ### Parameters - **fields**: The fields by which to sort. This can be either a single field or a list of fields. If you wish to specify order, you can use the `Asc` or `Desc` wrapper classes. - **max**: Maximum number of results to return. This can be used instead of `LIMIT` and is also faster. Example of sorting by `foo` ascending and `bar` descending: ``` sort_by(Asc("@foo"), Desc("@bar")) ``` Return the top 10 customers: ``` AggregateRequest() .group_by("@customer", r.sum("@paid").alias(FIELDNAME)) .sort_by(Desc("@paid"), max=10) ``` SORTBYmaxrMAX) rIrr)r+r,rJrBgetr8)rrCkwargs fields_argsfrLrZs r sort_byzAggregateRequest.sort_bys8 fsM2 3XF  #A!]+55 s"  # S-./ ;jj" 7 E3s8$ $C ""3' r ctt|tr|g}|D]}|jjd|g!|S)z Specify filter for post-query results using predicates relating to values in the result set. ### Parameters - **fields**: Fields to group by. This can either be a single string, or a list of strings. FILTER)rIrr8rB)r expressions expressions r filterzAggregateRequest.filtersD k3 '&-K% ?J    & &*'= > ? r cd|_|S)z| If set, the `schema` property will contain a list of `[field, type]` entries in the result object. T)r=rs r with_schemazAggregateRequest.with_schemas ! r cd|_|S)NT)r>rs r verbatimzAggregateRequest.verbatim"s r chdg}|r|dt|gz }|r|dt|dzgz }||_|S)N WITHCURSORCOUNTMAXIDLEi)rr?)rrmax_idlers r cursorzAggregateRequest.cursor&sF~  Wc%j) )D  YHtO 45 5D  r cb|jg}|jr|jd|jr|jd|jr||jz }|j r#|jd|jdne|j rY|jd|jtt|j |j|j |j|j||jjz }|S)N WITHSCHEMAVERBATIMLOAD*) r7r=appendr>r?r:r9rrJrBr8r;r)rrLs r rzAggregateRequest.build_args/s{{m    JJ| $ >> JJz " << 4<< C == JJv  JJsO    JJv  JJs3t//01 2 JJt'' ( 4&&' t{{%%'' r N)rt)rg)rrrr%r rDrNrTrWr`rergrirorrr r r5r5Us@. 2$+Z-^$r r5ceZdZdZdZy)Cursorc.||_d|_d|_y)Nr)cidrnrrrys r r zCursor.__init__Ls  r ct|jg}|jr|dt|jgz }|jr|dt|jgz }|S)Nrmrl)rryrnrrs r rzCursor.build_argsQsSDHH  == YDMM 23 3D :: Wc$**o. .D r Nrrr r rwrwKs  r rwceZdZdZdZy)AggregateResultc.||_||_||_yr)rowsroschema)rrrors r r zAggregateResult.__init__[s   r c |jr|jjnd}d|jjdt |ddt |j d|d S)N)rory __class__ridrJrrzs r __repr__zAggregateResult.__repr__`sZ!%dkkoo"''(r$xl; N#9SE 4 r N)rrrr rrr r r}r}Zs   r r}N) objectr!rrr)r.r2r5rwr}rr r rsd H   ''T-=ssl     r