Chained projection

Projection – Abstract

Purpose: Enables the chaining of Projections and Joins to provide a specific return value.

images/download/attachments/162409422/image-2023-12-12_17-48-17-version-1-modificationdate-1702399697657-api-v2.png

The Chained projection enables the chaining of Projections and Joins in order to provide a specific return value.

Similar to the chaining of value resolvers (see Chained resolver), the chained elements pass on the respective return value to the subsequent level as a reference object (e.g. for Projections defined there).

NOTE◄ If multiple Chained projection instances are used within the same search that contain similar Joins, these are not created redundantly in the database query. Instead, a shared join is accessed multiple times even if each Chained projection uses a different name for the 'Join alias'. However, redundant joins are used if a Chained projection contains a join whose configuration is identical to an explicit configuration in the 'Joins' enumeration of the search.

Configuration

Parameter

Type

Description

Name

String

The optional Name parameter can be used to assign an (alias) name to the projection.

  • If no Name is specified, the name applicable to the last element of the chain (for Joins: the 'Join alias') is used as the column name (if relevant).

Chain

Elements
(Projections
and/or Joins)

The chain is always initially empty (see screenshot above), which causes an error (NullPointerException) at runtime.

Clicking on the large images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/add.svg icon opens a context menu that offers all Joins and the applicable Projections for selection.

For elements of an existing chain, a small images/s/-95e2zf/9012/8yg2g7/_/images/icons/emoticons/add.svg icon appears at the bottom and top edge when the mouse cursor is moved closer (see screenshot on the left). This can be used to open the same context menu in order to attach an additional element at the respective position or insert it into the chain.

To remove elements from an existing chain, the 'Remove value' functions in the context menu can be used.

The context menu also offers the usual 'operators' for the clipboard ('Cut', 'Copy' and after copying or cutting also 'Paste') of Lobster Data Platform / Orchestration, which can be applied to individual elements of the chain.

Regardless of the number of elements in the chain, the last element of the chain defines the return value.

images/download/attachments/162409422/image-2023-12-12_17-49-19-version-1-modificationdate-1702399759528-api-v2.png

Examples

Simple example: Adding the 'owner' account of an entity

In a tuple search for any entity type, the complete company account for its 'owner' is output as the complex value of a column.

Configuration:

The screenshot on the right shows a Chained projection that contains a Entity join as the only element with the following parameterization:

  • As an Entity, the entity type 'Company account' (CompanyAccount) is selected.

  • The Join alias owner is also used here as the name for the output column, as the higher-level Chained projection does not provide a Name.

  • The On condition is a Field restriction that requires a match (==) between the ID of the added company account (owner.ID) and the value of the 'Owner' (ownerId) property for the entity in the context of the search.

NOTE◄ As the type hint at the bottom indicates, the Entity join returns a 'Company account' (if available), which also applies to the Chained projection as a whole due to the lack of a successor element.

images/download/attachments/162409422/image-2023-12-13_7-49-53-version-1-modificationdate-1702450194658-api-v2.png


Variant:

Based on the previous use case, the tuple column should now only identify the 'owner' as a chained string with selected address characteristics instead of the entire account.

Specifically, the fields 'Name' (name1) and 'Account number' (accNumber) should appear separated by an underscore (_).

Configuration:

Starting from the Entity join (owner) configured as above, which provides the complete company account for the 'owner' of the entity, the chain is extended by two Projections (as successors) as shown on the right:

The Chained projection now provides text in total.

images/download/attachments/162409422/image-2023-12-12_17-52-22-version-1-modificationdate-1702399942807-api-v2.png

More complex use case: Identifying the 'owner of the owner'

Based on the previous example, a further tuple column is to be added, which identifies the owner of the owner company of the entity in the context of the search via its address characteristics according to the 'variant' scheme.

Configuration:

The Chained projection shown in the screenshot on the right can be created from a copy of the projection described above as 'variant' with the following changes:

  • A second Entity join is inserted between the Entity join owner and the Property projection for the address field as a copy of the first.

  • In addition, the Name for the Chained projection (at the top) should be adapted so that the columns can be distinguished. We name the column ONE_OVER_ONE here.

NOTE◄ The copy of the existing Entity join instance can be used here without changes because the following conditions are met:

  1. In a chain, the Join alias only applies within the relevant join instance. Therefore, both instances can use the same value (owner).

  2. The Property projection for the compare value (on the right in the Field restriction within the On condition refers with the same path (ownerId) to the return value of the predecessor instance, where it refers to the entity in the context.

images/download/attachments/162409422/image-2023-12-12_17-53-42-version-1-modificationdate-1702400022437-api-v2.png

Expansion:

The search should now contain a Where condition that ensures that at least one of the address characteristics linked in the ONE_OVER_ONE projection is filled.

Configuration:

images/download/attachments/162409422/image-2023-12-13_9-20-10-version-1-modificationdate-1702455611502-api-v2.png

NOTE

  • In the data query, a separate join is not generated for each Entity join instance. This would be 'company account' joins only for the ONE_OVER_ONE column and the associated Where condition.

  • Specifically, a LEFT OUTER JOIN used several times is implemented for each 'company account' level and another one is used to access the associated address.

  • By copying, pasting and adapting, the required variants can be 'produced' quite easily once a Chained projection with the two joins has been set up.

  • Of course, you could also create the two 'company account' joins 'centrally' and address each use via two general 'Join alias' names (e.g. owner, ownersOwner). In terms of runtime performance, however, this offers no significant advantage unless both methods are used simultaneously. If only one central definition is created for each 'company account' join, the risk of individual adjustments being made to originally identical join configurations is avoided. This could increase the number of joins generated in the database query.