Contact Us 1-800-596-4880

leftJoin

DataWeave 2.2 is compatible and bundled with Mule 4.2. This version of Mule reached its End of Life on May 2, 2023, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

leftJoin(Array<L>, Array<R>, (leftValue: L) -> String, (rightValue: R) -> String): Array<{ l: L, r?: R }>

Joins two arrays of objects by a given ID criteria.

leftJoin returns an array all the left items, merged by ID with any right items that meet the joining criteria.

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters

Name Description

left

The left-side array of objects.

right

The right-side array of objects.

leftCriteria

The criteria used to extract the ID for the left collection.

rightCriteria

The criteria used to extract the ID for the right collection.

Example

This example shows how join behaves. Notice that it returns all objects from the left-side array (left) but only joins items from the right-side array (right) if the values of the left-side user.id and right-side product.ownerId match.

Source

 %dw 2.0
 import * from dw::core::Arrays
 var users = [{id: "1", name:"Mariano"},{id: "2", name:"Leandro"},{id: "3", name:"Julian"},{id: "5", name:"Julian"}]
 var products = [{ownerId: "1", name:"DataWeave"},{ownerId: "1", name:"BAT"}, {ownerId: "3", name:"DataSense"}, {ownerId: "4", name:"SmartConnectors"}]
 output application/json
 ---
 leftJoin(users, products, (user) -> user.id, (product) -> product.ownerId)

Output

[
  {
    "l": {
      "id": "1",
      "name": "Mariano"
    },
    "r": {
      "ownerId": "1",
      "name": "DataWeave"
    }
  },
  {
    "l": {
      "id": "1",
      "name": "Mariano"
    },
    "r": {
      "ownerId": "1",
      "name": "BAT"
    }
  },
  {
    "l": {
      "id": "2",
      "name": "Leandro"
    }
  },
  {
    "l": {
      "id": "3",
      "name": "Julian"
    },
    "r": {
      "ownerId": "3",
      "name": "DataSense"
    }
  },
  {
    "l": {
      "id": "5",
      "name": "Julian"
    }
  }
]