MarkLogic 10 Product Documentation
op.bucketGroup

op.bucketGroup(
   name as String,
   column as columnIdentifier,
   boundaries as xs.anyAtomicType[],
   [collation as String?]
) as NamedColumnGroup

Summary

This function can be used as a named group in functions prototype.groupToArrays or prototype.facetBy . 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 JavaScript array 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

const op = require('/MarkLogic/optic');

op.fromLiterals([
            {'r':1, 'c1':'a', 'c2':'x', 'c3':'m'},
            {'r':2, 'c1':'b', 'c2':'x'          },
            {'r':3, 'c1':'a',           'c3':'n'},
            {'r':4,           'c2':'y', 'c3':'o'},
            {'r':5, 'c1':'b'                    },
            {'r':6,           'c2':'y'          },
            {'r':7,                     'c3':'p'},
            {'r':8, 'c1':'b', 'c2':'x', 'c3':'q'}
            ])
.groupToArrays(
    [op.bucketGroup('rBucket', op.col("r"), [2,4])],
    [op.count('numRows')]
    )
.result();
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy