MarkLogic 9 Product Documentation
op:uda

op:uda(
   $outCol as item(),
   $inCol as item(),
   $module-path as xs:string,
   $func-name as xs:string,
   [$options as map:map?]
) as map:map

Summary

This function processes the values of column for each row in the group or row set with the specified user-defined aggregate as implemented by an aggregate user-defined function (UDF) plugin. The UDF plugin must be installed on each host. The result is used for building the parameters used by the op:group-by function.

For more information on UDF functions, see Aggregate User-Defined Functions in the Application Developer's Guide.

Parameters
$outCol The name to be used for the aggregated column.
$inCol The column with the values to aggregate.
$module-path The path to the installed plugin module.
$func-name The name of the UDF function.
$options The options can take a values key with a distinct value to average the distinct values of the column and an arg key specifying an argument for the user-defined aggregate. The value can be a string or placeholder parameter.

Example


xquery version '1.0-ml';

import module namespace op = 'http://marklogic.com/optic'
      at 'MarkLogic/optic.xqy';
      
      let $plan1 :=
        op:from-view('main', 'employees')
          => op:order-by(op:schema-col('main', 'employees', 'EmployeeID'))
      let $plan2 :=
        op:from-view('main', 'expenses')
          => op:order-by(op:schema-col('main', 'expenses' , 'EmployeeID'))
      return
        op:join-inner($plan1, $plan2)
        => op:where(
             op:eq(
               op:schema-col('main', 'employees' , 'EmployeeID'),
               op:schema-col('main', 'expenses', 'EmployeeID')
             )
           )
        => op:group-by(op:schema-col('main', 'employees', 'EmployeeID'), 
                       op:uda('DetailSum', op:schema-col('main', 'expenses', 'Amount'), 
                      'sampleplugin/sampleplugin', 'sum'))
        => op:order-by(op:desc(op:col('DetailSum')))
        => op:result()
 
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy