Contact Us 1-800-596-4880

MQL Reference Guide

Overview

MQL expressions follow the following structure:

from object as o  join ...  where ...   select new {     property = object_expression  }

If you wish to only transform objects, you can use the shortcut notation which omits the from, join and where statements:

select new {  property = object_expression}

Where clause

The where clause allows you to filter out objects. For example:

from people where age > 21 and (firstName = 'Joe' or firstName = 'Jane')
  • The following comparators are supported: =, <, >, !=, like.

  • Like performs a case insensitive search of the right hand word in the left hand object.

  • Clause precedence is determine by parentheses.

  • The left and right hand sides of individual where clauses can be any Object Expressions.

  • You can refer to properties on the selected object with and without the "as" identifier. For example, both of these expressions are equivalent:

from people as p where age > 21from people as p where p.age > 21

Join clause

The join clause allows you to join data from another data source and select it. It follows the form:

join object_expression as variable on condition async(threads)|sync
Clause Description

expression

Any Object Expressions.

variable

The name of the variable which to put the result of the join in

condition

The condition on whether or not to join the data. An MVEL expression which returns a boolean. The on clause is optional

async/sync

Whether or not to do the join asynchronously. If asynchronous, an executor will be created to join the data. The executor can optionally be specified using the Query.setExecutor method. The number of threads can also be specified as part of the async statement, e.g. async(5). "sync" specifies that the join should happen synchronously. By default it is async(10).

Example:

from users as u join twitter.getTweetCount(u.twitterId) as tweetCount on u.twitterId  select new {     name = u.name,     tweetCount = tweetCount  }

Selecting new objects

The select statement creates a new object for each object that is queried. If no select statement is present, the original query object is returned. The left hand side of the equals statement is the name of the property that is created. The right hand side is any Object Expressions.

Selecting Maps

You can create new Map objects with different properties by using select new.

from users as u select new {   name = u.firstName + ' ' + u.lastName }

Selecting POJOs

You can instantiate instances of POJOs and set properties on them using the select new(className) syntax:

from users as u select new(com.mulesoft.examples.UserSummary) {   name = u.firstName + ' ' + u.lastName }

Selecting Child objects

You can also create child relationships, for example:

from users as u select new {   name = u.name,   address = new {     address1 = u.address1,     address2 = u.address2,     state = u.state,     city = u.city   } }

This will yield a sub object for the address field which is made up of the address1, address2, state and city properties.

Object Expressions

Object expressions are a subset of the MVEL syntax. Pieces of the MVEL syntax which are supported include:

  • Value tests

  • Arrays, List and Maps

  • Property Navigation

  • Functions

  • Strings and Numbers

Examples include:

object.propertyobject.function()object[index]object 'foo'123nullx + yx