
op.groupConcat( aggColName as String, columndef as ColumnIdentifier, [options as String] ) as aggregatedef
This function concatenates the non-null values of the column for the rows in the group or row set. The result is used for building the parameters used by the prototype.groupBy function.
| Parameters | |
|---|---|
| aggColName | The name to be used for column with the concatenated values. |
| columndef | The name of the column with the values to be concatenated for the group. The column can be named with a string or a column function such as op.col, op.viewCol, or op.schemaCol, or constructed from an expression with the op.as function. |
| options |
The options can take a values key with a 'distinct' value to concat
the distinct values of the column.
In addition to the values key, the options can take
a separator key specifying a separator character. The value
can be a string or placeholder parameter.
|
const op = require('/MarkLogic/optic');
op.fromView('main', 'expenses')
.groupBy('Category', op.groupConcat("Spent", "Amount", {"separator":"-", "values":"distinct" }))
.orderBy('Category')
.result();
const op = require('/MarkLogic/optic');
const plan1 =
op.fromLiterals([
{rowId: 1, colorId: 1, desc: 'ball'},
{rowId: 1, colorId: 3, desc: 'foo'},
{rowId: 2, colorId: 2, desc: 'square'},
{rowId: 2, colorId: 1, desc: 'box'},
{rowId: 3, colorId: 1, desc: 'hoop'},
{rowId: 3, colorId: 4, desc: 'circle'}
], 'myItem');
const plan2 =
op.fromLiterals([
{colorId: 1, colorDesc: 'red'},
{colorId: 2, colorDesc: 'blue'},
{colorId: 3, colorDesc: 'black'},
{colorId: 4, colorDesc: 'yellow'}
], 'myColor');
const descCol = plan1.col('desc');
const itemColorIdCol = plan1.col('colorId');
const colorIdCol = plan2.col('colorId');
plan1.joinInner(plan2, op.on(itemColorIdCol, colorIdCol))
.groupBy('rowId', op.groupConcat('shapes', descCol, {separator: ', '}))
.orderBy(['rowId'])
.result();
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.