Loading TOC...

ModifyPlan.prototype.generateView

ModifyPlan.prototype.generateView(
   schemaName as String,
   viewName as String,
   [columnDeclarations as object[]]
) as ElementNode

Summary

This method generates a view that encapsulates a query. Insert the generated XML into the schemas database and then use the op.fromView op:from-view accessor to use the generated view.

Parameters
schemaName The schema name that can be passed to op.fromView() when accessing the generated view.
viewName The view name that must be passed to op.fromView() when accessing the generated view.
columnDeclarations Optional type and nullability declarations for some or all of the columns of the view.
  • name

    The name of the column in the QBV (required)

  • type

    The type to define the column as. Any TDE column type is valid for this field. (required)

  • nullable

    True or false. If you expect null results in this column, set this field to true. (optional - default is true)

  • collation

    This is specifically for string types. Provide the collation you expect the result to be (optional - default is no collation)

  • invalidValues

    Provide skip or reject to this field. If skip is provided, the engine skips rows that contain values whose type, nullability, or collation don't match your specification. If reject is provided, an error is thrown if a value that does not match the column criteria is found (optional - default is skip)

Usage Notes

Each column must have an atomic data type that is indexable by TDE. The unqualified name of each column must be unique in the row. The optional column declarations takes the following keys to specify the treatment of rows with invalid values:

generateView is a method of the following classes:

Example

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

op.fromView('main', 'employees')
   .where(cts.collectionQuery('/division/manufacturing'))
   .select(['EmployeeID', 'FirstName', 'LastName'])
   .orderBy('EmployeeID')
   .generateView('main', 'manufacturingEmployees');
  

Example

const op = require('/MarkLogic/optic');
const plan1 =
  op.fromLiterals([
    {rowId: 1, colorIdShape: 1, desc: 'ball'},
    {rowId: 2, colorIdShape: 2, desc: 'square'},
    {rowId: 3, colorIdShape: 1, desc: 'box'},
    {rowId: 4, colorIdShape: 1, desc: 'oval'},
    {rowId: 5, colorIdShape: 5, desc: 'circle'}
  ]);
const plan2 =
  op.fromLiterals([
    {colorId: 1, colorDesc: 'red'},
    {colorId: 2, colorDesc: 'blue'},
    {colorId: 3, colorDesc: 'black'},
    {colorId: 4, colorDesc: 'yellow'}
  ]);
const output =
  plan1.joinInner(
    plan2, op.on(op.col('colorIdShape'), op.col('colorId'))
  )
  .select(['rowId', op.as('description', op.col('desc')), 'colorId', 'colorDesc'])
  .orderBy(op.col('rowId'));
output.generateView('ThreeParams', 'ThreeColsSelected',
        [{name:'rowId', type:'integer',nullable:true, invalidValues: 'reject'},
         {name:'description', type:'string', invalidValues: 'reject'},
         {name:'colorId', type:'integer',nullable:false, invalidValues: 'skip'}]);
  

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