Loading TOC...

op functions

The table below lists all the op built-in functions (in this namespace: ).

The optic library module is a fluent API that builds up a plan definition for retrieving and processing rows. The result method executes the plan.

The plan operations fall into the following broad categories:

  • data access -- a plan can read a row set from a view, graph, lexicons, or literals.
  • row set modification -- a plan can filter rows with the where method, sort rows with orderBy, group rows with groupBy, project rows with select, or page over rows with limit.
  • row set composition -- a plan can combine multiple row sets with the joinInner(), joinLeftOuter, union, intersect, or except methods to yield a single row set.
  • row result processing -- a plan perform document joins and apply map or reduce functions to the final row set.

To use the optic.xqy module in your own XQuery modules, include the following line in your XQuery prolog:

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

The library uses the op: namespace, which is not predefined in the server.

86 functions
Function name Description
op:add This function returns the sum of the specified numeric expressions.
op:and This function returns true if the specified expressions all return true.
op:array-aggregate This function constructs an array whose items are the result of evaluating the column for each row in the group or row set.
op:as This function defines a column by assigning the value of an expression over the rows in the row set.
op:asc This function sorts the specified columndef in ascending order.
op:avg This function averages the non-null values of the column for the rows in the group or row set.
op:call This function calls value processing built-in functions that aren't listed in the list Value Processing Functions, the API also provides a general-purpose constructor for deferred calls.
op:case This function returns the specified valueExpression if the specified valueExpression is true.
op:col This method identifies a column, where the column name is unique.
op:count This function counts the rows where the specified input column has a value.
op:desc This function sorts the specified columndef in descending order.
op:divide This function divides the left numericExpression by the right numericExpression and returns the value.
op:eq This function returns true if the left and right expressions return the same value.
op:except This method restricts the left row set to rows where a row with the same columns and values doesn't exist in the right row set.
op:explain This method returns a representation of the builtin execution plan.
op:export This method generates a serialized representation of the Optic query to JSON so that it can be persisted as a file or used as a REST payload.
op:fragment-id-col Specifies a name for adding a fragment id column to the row set identifying the source documents for the rows from a view, lexicons or triples.
op:from-lexicons This function dynamically constructs a view from range indexes or the uri or collection lexicons.
op:from-literals Constructs a literal row set as in the SQL VALUES or SPARQL VALUES statements.
op:from-sparql This function dynamically constructs a row set based on a SPARQL SELECT query from triples.
op:from-sql This function dynamically constructs a row set based on a SQL SELECT query from views.
op:from-triples Reads rows by matching patterns in the triple index.
op:from-view This function reads a row set from a configured view over TDE-indexed rows or a predefined view over range indexes.
op:ge This function returns true if the value of the left expression is greater than or equal to the value of the right expression.
op:graph-col Identifies the graph for a triple providing one or more columns for a row.
op:group-by This method collapses a group of rows into a single row.
op:group-concat This function concatenates the non-null values of the column for the rows in the group or row set.
op:gt This function returns true if the value of the left expression is greater than the value of the right expression.
op:import This function instantiates a plan from the JSON representation of a plan that was exported by the op:export function.
op:intersect This method restricts the left row set to rows where a row with the same columns and values exists in the right row set.
op:is-defined This function tests whether the value of an expression is null in the row where the expression might be as simple as a column identified by op:col.
op:join-cross-product This method yields one output row set that concatenates every left row with every right row.
op:join-doc This function specifies a document column to add to the rows by reading the documents for an existing source column having a value of a document uri (which can be used to read other documents) or a fragment id (which can be used to read the source documents for rows).
op:join-doc-uri This method adds a uri column to rows based on an existing fragment id column to identify the source document for each row.
op:join-inner This method returns all rows from multiple tables where the join condition is met.
op:join-left-outer This method yields one output row set with the rows from an inner join as well as rows from the left row set.
op:json-array This function constructs a JSON array during row processing.
op:json-boolean This function constructs a JSON boolean node with the specified value.
op:json-document This function constructs a JSON document with the root content, which must be exactly one JSON object or array node.
op:json-null This function constructs a JSON null node.
op:json-number This function constructs a JSON number node with the specified value.
op:json-object This function constructs a JSON object with the specified properties.
op:json-string This function constructs a JSON text node with the specified value.
op:le This function returns true if the value of the left expression is less than or equal to the value of the right expression.
op:limit This method specifies the maximum number of rows to be returned by this Plan.
op:lt This function returns true if the value of the left expression is less than the value of the right expression.
op:map This method applies the specified function to each row returned by the plan to produce a different result row.
op:max This function gets the largest non-null value of the column for the rows in the group or row set.
op:min This function gets the smallest non-null value of the column for the rows in the group or row set.
op:modulo This function returns the remainder afer the division of the dividend and divisor expressions.
op:multiply This function multiplies the left numericExpression by the right numericExpression and returns the value.
op:ne This function returns true if the value of the left expression is not equal to the value of the right expression.
op:not This function returns true if neither of the specified boolean expressions return true.
op:offset This method returns a subset of the rows in the result set.
op:offset-limit This method returns a subset of the rows in the result set by skipping the number of rows specified by start and returning the remaining rows up to the length limit.
op:on Specifies an equijoin using one columndef each from the left and right rows.
op:or This function returns true if the specified expressions all return true.
op:order-by This method sorts the row set by the specified order definition.
op:param This function creates a placeholder for a literal value in an expression or as the offset or max for a limit.
op:pattern This function builds the parameters for the op:from-triples function.
op:prefixer This function factory returns a new function that takes a name parameter and returns a sem:iri, prepending the specified base URI onto the name.
op:prepare This method prepares the specified plan for execution as an optional final step before execution.
op:prop This function specifies the key expression and value content for a JSON property of a JSON object contructed by the op:json-object function.
op:reduce This method applies a function or the builtin reducer to each row returned by the plan to produce a single result as with the reduce() method of JavaScript Array.
op:result This method executes the plan (mapping or reducing, if specified) to generate the result, which is a sequence of map:map or json:array rows, unless mapped or reduced to different output.
op:sample This function randomly selects one non-null value of the column from the rows in the group or row set.
op:schema-col Unambiguously identifies a column with the schema name, view name, and column name.
op:select This call projects the specified columns from the current row set and / or applies a qualifier to the columns in the row set.
op:sequence-aggregate This call constructs a sequence whose items are the values of a column for each row in the group or row set.
op:sql-condition This function returns a filter definition as input for a WHERE operation.
op:subtract This function subtracts the right numericExpression from the left numericExpression and returns the value.
op:sum This function adds the non-null values of the column for the rows in the group or row set.
op:to-source This function generates an XQuery source code representation of a plan from the JSON or JavaScript literal object representation of a plan that was exported by the op:export function.
op:uda 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.
op:union This method yields all of the rows from the input row sets.
op:view-col Identifies a column where the combination of view and column name is unique.
op:when This function executes the specified expression if the specified condition is true for the row.
op:where This method restricts the row set to rows matched by the boolean expression.
op:where-distinct This method removes duplicate rows from the row set.
op:xml-attribute This function constructs an XML attribute with the name (which can be a string or QName) and atomic value.
op:xml-comment This function constructs an XML comment with the atomic value.
op:xml-document This function constructs an XML document with the root content, which must be exactly one node.
op:xml-element This function constructs an XML element with the name (which can be a string or QName), zero or more attributes, and child content.
op:xml-pi This function constructs an XML processing instruction with the atomic value.
op:xml-text This function constructs an XML text node with the specified value.
op:xpath This function extracts a sequence of child nodes from a column with node values -- especially, the document nodes from a document join.