Loading TOC...

MarkLogic Server 11.0 Product Documentation
op.uda

op.uda(
   aggColName as String,
   columndef as String,
   module as String,
   function as String,
   [options as String]
) as aggregatedef

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 prototype.groupBy function.

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

Parameters
aggColName The name to be used for the aggregated column.
columndef The column with the values to aggregate.
module The path to the installed plugin module.
function 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

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

      const plan1 =
        op.fromView('main', 'employees')
          .orderBy(op.schemaCol('main', 'employees', 'EmployeeID'));
      const plan2 =
        op.fromView('main', 'expenses')
          .orderBy(op.schemaCol('main', 'expenses' , 'EmployeeID'));
      const output =
        plan1.joinInner(plan2)
        .where(
          op.eq(
            op.schemaCol('main', 'employees' , 'EmployeeID'),
            op.schemaCol('main', 'expenses', 'EmployeeID')
          )
        )
        .groupBy(op.schemaCol('main', 'employees', 'EmployeeID'),
                 op.uda('DetailSum', op.schemaCol('main', 'expenses', 'Amount'),
                        'sampleplugin/sampleplugin', 'sum'))
        .orderBy(op.desc(op.col('DetailSum')))
        .result();
      output;

  

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