op:bucket-group

op:bucket-group(
   $name as xs:string,
   $column as columnIdentifier,
   $boundaries as xs:anyAtomicType+,
   [$collation as xs:string?]
) as map:map

Summary

This function can be used as a named group in functions op:group-to-arrays or op:facet-by. After grouping, the plan can also join a literal table with descriptive metadata based for each bucket number. Developers can handle special cases by taking the same approach as the convenience function and binding a new column on the return value of an sql:bucket expression on a numeric or datetime column to use as a grouping key.

Parameters
$name The name of both the group and the new grouping key column with numbered buckets.
$column The identifier for the existing column with the values (typically numeric or datetime) to put into buckets. The columns can be named with a string or a column parameter function such as op:col or constructed from an expression with op:as.
$boundaries An ordered XQuery sequence of values that specify the boundaries between buckets. The values must have the same type as the existing column.
$collation The collation to use when comparing strings as described in 'Collation URI Syntax' in the Application Developer's Guide

See Also

Example

xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";
op:from-literals((
              map:entry("r",1)=>map:with("c1","a")=>map:with("c2",1)=>map:with("c3","m"),
              map:entry("r",2)=>map:with("c1","b")=>map:with("c2",1)                    ,
              map:entry("r",3)=>map:with("c1","a")                    =>map:with("c3","n"),
              map:entry("r",4)                    =>map:with("c2",3)=>map:with("c3","o"),
              map:entry("r",5)=>map:with("c1","b")                                        ,
              map:entry("r",6)                    =>map:with("c2",5)                    ,
              map:entry("r",7)                                        =>map:with("c3","p"),
              map:entry("r",8)=>map:with("c1","b")=>map:with("c2",1)=>map:with("c3","q")
              ))
=> op:group-to-arrays(
    op:bucket-group("c2Bucket", op:col("r"), (2,4)),
    op:count("numRows")
    )
=> op:result()
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy