op.hasGroupKey( outputColumn as String, column as columnIdentifier ) as aggregatedef
This aggregate function adds a flag to a grouped row specifying whether a column acted as a grouping key for the row.
The flag column has a value of 0 in result rows belonging to a group that has the group key and a value of 1 in other result rows. The aggregate is useful for the prototype.groupByUnion function in cases where the grouping key is nullable and, thus, null values in the grouping key column are insufficient to distinguish rows grouped on a null value from rows that don't belong to a group with the grouping key.
Parameters | |
---|---|
outputColumn | The name to be used for the aggregated flag column. |
column | The column to flag as a grouping key. The column can be named with a string or a column parameter function such as op.col or constructed from an expression with op.as. |
const op = require('/MarkLogic/optic'); op.fromView('main', 'expenses') .groupByUnion( [op.group(), op.group(['Category', 'Location'])], [op.hasGroupKey('Category'), op.hasGroupKey('Location'), op.sum("TotalAmount", "Amount")] ) .orderBy(['Category', 'Location']) .result();