Loading TOC...

MarkLogic 12 Product Documentation
op:array-aggregate

op:array-aggregate(
   $outCol as item(),
   $inCol as item(),
   [$options as map:map?]
) as map:map

Summary

This function constructs an array whose items are the result of evaluating the column for each row in the group or row set. The result is used for building the parameters used by the op:group-by function.

Parameters
$outCol The name to be used for the aggregated column.
$inCol The columns to be aggregated. The column can be named with a string or a column function such as op:col, op:view-col, or op:schema-col, or constructed from an expression with the op:as function.
$options The options can take a values key with a 'distinct' value to aggregate the distinct values of the column.

Example

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $expenses := op:from-view("main", "expenses")

return $expenses
    => op:group-by("Category", op:array-aggregate("Expense Array", "Amount"))
    => op:order-by("Category")
    => op:result()
  

Example

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
     at "/MarkLogic/optic.xqy";

let $expenses := op:from-view("main", "expenses")

return $expenses
    => op:group-by("Category", op:array-aggregate("Expense Array", "Amount",map:entry("values","distinct")))
    => op:order-by("Category")
    => op:result()
  

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.