Subsearch projection

Projection – Abstract

Purpose: Provides a simple way to include a single simple value (or, in special cases, multiple simple values) of any entity type in the context of the parent search.

images/download/attachments/157876346/image-2023-11-14_7-14-16-version-1-modificationdate-1699942463581-api-v2.png

A Subsearch projection offers a simple way of integrating a single simple value (or in special cases multiple simple values) from the data of entities of any entity type into the context of the parent search (_parentQuery).

The term subselect refers to the methodology for integrating data from an 'external' entity as a 'subquery', which can provide specific values for different functional sections (e.g. output columns or Restrictions) of the higher-level search.

The area of application of Subsearch projection overlaps with that of Joins. However, there are constellations when integrating or looking up data that can only be realized in one way or the other.

  • On the one hand, a Subsearch projection is often 'more expensive' in terms of the performance of a search because the data of the integrated entity type is retrieved 'line by line' and therefore often repeatedly (and possibly redundantly).

  • On the other hand, the Subsearch projection offers a degrees of freedom for constraints and the preparation of the integrated data (e.g. Group by and Aggregate projection), which are not available in the context of Joins.

The following restrictions must be observed when using the Subsearch projection:

  1. Only Projections that provide values that are 'simply' represented in the database (by exactly one column) can be used as a Projection for column subselect.

    • Example: Enumeration values

      • An enumeration value is stored at database level either as a Long value ('Ordinal') or, in exceptional cases, as a String ('Name'). In any case, the database uses a simple value, even if it appears complex in the XML.

      • Values from dynamic or static enumerations are therefore easily suitable as Projection for column of subselect.

    • Example: Date values

      • Timestamp field – e.g. the 'Created' (created) for any entity – is easily suitable as a Projection for column of subselect.

      • A DateTime field – e.g. the 'password expiry date' (passwordExpiryDate) for Users – is not suitable as a Projection for column of subselect, because a date/time field at database level requires two 'columns' (for UTC milliseconds and time zone).

      • The UTC milliseconds of a DateTime field – e.g. the 'PasswordExpiryDate.dateValue' (passwordExpiryDate.dateValue) property for Users – can easily be used as a Projection for column of subselect.

    • Example: List fields

      • In principle, 'list fields' – e.g. 'parentCompanies' (parentCompanies) for Company accounts – can be used as a Projection for column of subselect.

      • However, the Projection for column of subselect may only provide several values where these can also be processed:

        • If the Subsearch projection defines an output column (in a tuple or CSV search), then only a single value is permitted as a return value. With a 'list field' as a Projection for column of subselect, the search is aborted at runtime with an error as soon as the list field returns multiple values for the same result row.

        • Where 'multi-value' content is permitted – e.g. on the right-hand side of a Field restriction with the in compare type – a 'list field' can easily be used as a Projection for column of subselect.

      • IMPORTANT◄ The use of a Collection projection as a Projection for column of subselect within a Subsearch projection to project a list into an output column is not possible for technical reasons.

        • However, the reverse approach is more effective: A Subsearch projection with a 'list value' as a Projection for column of subselect can be used in a Collection projection to provide values for a collection.

  2. The Subsearch projection may only return exactly one result, unless the context is explicitly aimed at a list.

    • The uniqueness of the result can only be enforced in the parent search by setting the 'Maximum results' parameter to 1. The Subsearch projection, on the other hand, has no 'limit' for the number of 'result rows', so you cannot simply define the 'first result' as the return value.

    • If necessary, an Aggregate can be used in the Projection for column of subselect, e.g. to select the minimum or maximum value from several values.

    • Within Collection projection.


IMPORTANT◄ In contrast to the parent search, no access restrictions apply to the subselect. If the Entity parameter refers to the same entity type as the parent search, the subselect always takes into account all existing instances of this type, while the parent search only returns a real or fake subset, namely the entities for which there is read access in the execution context.


Configuration

Parameter

Type

Description

Name

String

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

Entity

Entity type

The selection for the Entity parameter determines the primary data source for the subselect. Only the entity types offered in the dropdown can be selected.

Entity types that are not directly available as 'Entity' in the higher-level search (e.g. attributes) can also be selected for the subselect.

NOTEOptionally, additional data sources can be integrated into the subselect via Joins.

Projection for column of subselect

Projection

The Projection for column of subselect defines the return value(s) of the Sub search. Any Projections can be used here as long as they return values that are 'simple' on the database side – i.e. represented by exactly one column.

  • If no Projection for column of subselect is defined, the Subsearch projection returns the Long value 1 as the return value. There is therefore no error message if a projection is accidentally forgotten, unless the Long data type cannot be processed in the context.

Joins

Join

Additional data sources can be added to the subselect via Joins, which are then available for Projections in other areas within the Subsearch projection.

Property to join and
Property of entity to join with

Property paths

The Property to join and Property of entity to join with parameters can optionally be used to define the relationship between the entity types in the subselect and the parent search via a match (==) between two properties.

  • The path selection for the Property to join refers to the entity type of the parent search (_parentQuery).

  • The path selection for the Property of entity to join with refers to the entity type in the subselect defined by the Entity parameter.

If matching two properties is the only sufficient condition for the assignment of data via subselect, the configuration of a Where condition can be dispensed with completely.

If a Where condition is also formulated, a 'match' defined via the Property to join and Property of entity to join with parameters is taken into account together with the Where condition as in an AND conjunction.

Example:

In a parent search for any entity type, a subselect should 'look up' information from the account of the Company value value, according to the parent search as the 'owner' (ownerId) of the respective entity. However, no information should be 'passed on' for company accounts that are assigned to the Company meta type 'Group' (GROUP) via the 'Metatype' (metaType) property:

images/download/attachments/157876346/image-2023-11-14_7-16-51-version-1-modificationdate-1699942618645-api-v2.png

  • The Property to join and Property of entity to join with parameters require a match between the 'owner' (ownerId) property of the parent entity and the 'ID' (id) property of the company account.

  • The Where condition with the Field restriction prevents the subselect from returning data from a 'group' that is referenced as the 'owner'.

Where

Restriction

The Where parameter enables the configuration of Restrictions for the assignment of instances of the Entity in the subselect to Entities in the parent search.

  • The prefix _parentQuery in property paths of the configuration refers – if necessary – to the entity from the parent search.

  • Property paths without this prefix refer to the context given in the subselect, i.e. either to properties of the Entity or paths to properties of other entities included in the subselect via Joins.

The following alternative configuration for the above example demonstrates how the above relationship can be formulated as a Where condition without using the Property to join and Property of entity to join with parameters:

images/download/attachments/157876346/image-2023-11-14_7-18-14-version-1-modificationdate-1699942701152-api-v2.png

  • In the check value (left), the prefix _parentQuery is used to reference the entity from the parent search.

  • In the compare value (right), the Property projection accesses the 'ID' (id) property of the subselect entity directly without a prefix.

Group by

Projection

The Subsearch projection can optionally be assigned projections for Group by results. The 'grouping' of results typically aims either to prevent the output of redundant results or to determine partial results per group via Aggregate.

IMPORTANT◄ If a Subsearch projection is to provide grouped results in the context of a Collection projection as an output column, a projection for the _parentQuery.id path must always be configured under Group by for technical reasons.

Examples

Typical example: Look up company names for the 'Owner' column in an overview

Each entity in Lobster Data Platform / Orchestration has an 'owner' (ownerId) property in which a Long value can be stored as a reference to the 'ID' (id) of a company (see Company accounts).

The practical use of such purely numerical 'pointer values' as a reference is limited. In order to recognize which company is hidden behind an internal ownerId value in overviews for entities (e.g. Users), the reference in the 'Owner' column is resolved by default using a Subsearch projection that outputs the 'Name' (address.name1) address property in addition to the 'ID' (id), without having to use the complete company account via join or embedding.

Configuration:

Via the ribbon path 'Settings > List: Edit', the associated data grid settings can be accessed with just a few clicks from a list with an 'Owner' column. The predefined configuration for the Subsearch projection, on which this column is always based, can also be found there.

  • The predefined Name of the Subsearch projection is always owner.

  • The Entity parameter always refers to the entity type 'Company account' (CompanyAccount), which is exclusively relevant to 'owners' of entities.

  • The predefined Projection for column of subselect uses a Concatenated projection to concatenate the Long value from the 'ID' (id) property to the address property 'Name' (address.name1) via a separator string defined as a Literal projection (empty/minus/empty) with a Property projection.

  • The predefined relationship between the entity type in the context uses the simplified notation for a direct match between two properties:

    • The Property to join is always the 'Owner' property (ownerId) of the entity in the parent search.

    • The Property of entity to join with is always the Long property 'ID' (id), which identifies the company account to be included via subselect.

images/download/attachments/157876346/image-2023-11-14_7-20-17-version-1-modificationdate-1699942824187-api-v2.png

NOTE◄ The generic columns for the information 'Created' (creatorId) and 'Last modified' (lastModifierId) each use a Subsearch projection according to the principle presented here to include the 'username' (username) property from the referenced user account.

More complex example: 'Associations' count per Aggregate

Many types of configuration elements in Lobster Data Platform / Orchestration depend directly or indirectly on the evaluation of the Association criteria assigned to them when it comes to selection decisions for a situation-dependent appearance, access control or the 'applicability' of certain elements.

Which Association criteria have or can have an influence on which configurations is regulated by more or less specific entity types for 'Associations'. Overviews for entities 'subject to association' usually contain a default column 'Associations', which displays the number of existing associations and enables the creation and removal of associations.

Runtime example:

images/download/attachments/157876346/image-2023-11-14_7-21-32-version-1-modificationdate-1699942898805-api-v2.png

  • In a list of Input forms for Users, the 'Associations' column indicates whether and, if so, how many Association criteria are linked to the respective input form.

  • The specific numerical value is not part of the data saved for the data input form, but is always determined anew by a Subsearch projection when the overview is displayed.

Configuration:

Via the ribbon path 'Settings > List: Edit', the associated data grid settings can be accessed with just a few clicks from a list with an 'Associations' column. The predefined configuration for the Subsearch projection, on which this column is always based, can also be found there.

Here we present an example of the definition for 'Associations' for the entity type 'Entity form' (EntityForm).

  • The predefined Name of the Subsearch projection is always numberOfAssociations.

  • The Entity parameter always contains the specific entity type relevant to the context, which goes back to the 'Association details' base class (BaseAssociation).
    Here: 'Input form > Association' (EntityFormAssociation).

  • The predefined Projection for column of subselect refers to an Aggregate with Type 'Count' for the 'ID' (id) property as a Projection.

  • The predefined relationship between the entity type in the context – here: 'Input form' (EntityForm) uses the simplified notation for a direct match between two properties:

    • The Property to join is always the 'ID' (id) of the entity in the parent search.

    • The Long property associatedObjectId, which the base class 'Association details' provides for the reference to the target of an association, always applies as the Property of entity to join with.

Effectively, the predefined projections for the 'Association' column only differ in the selection for the Entity, which must always be matched to the context.

NOTE◄ Some configurations that must be assigned (e.g. Custom overviews and 'Data grid settings') are only handled as types within the common 'Client settings' (ClientPreferences) class, so that these also share the 'Client settings > Association' (ClientPreferencesAssociation) class for the 'Association details'. The type does not have to be checked within the Subsearch projection, as the associatedObjectId is unique even without reference to the type and thus implies it.

images/download/attachments/157876346/image-2023-11-14_7-22-16-version-1-modificationdate-1699942942774-api-v2.png

More complex example: 'Collect' country codes of companies per user

A tuple search for the Users entity should name for each user in a 'list column' all countries that are the headquarters of companies in whose context the user can log in.

Configuration:

The configuration shown on the right shows the configuration of a Collection projection (ca_countries) in which a Subsearch projection is used as the Property of collection:

  • The subselect refers to the Entity 'Company account'.

  • As a Projection for column of subselect, a Property projection that accesses the address property 'Country' of the 'Company account' entity via the path address.countryCode.

  • The condition for the subselect requires a match between the Property to join 'Companies' (companies) of the parent entity 'User' and the 'ID' (id) property of the subselect entity 'Company'.

This configuration returns all Country values of all 'Companies' for each user in a tuple search.

  • If several companies of a user refer to the same country, this country will appear several times in the collection.

    Example: [DE, FR, DE, GB, US]

  • If no 'Country' is specified for a company, no reference to this will appear in the collection.

images/download/attachments/157876346/image-2023-11-14_7-24-6-version-1-modificationdate-1699943053171-api-v2.png

The following configuration adjustment is intended to prevent the same country value from being specified more than once within the collection:

The Property projection in the Projection for column of subselect was copied to the clipboard and pasted under Group by.

  • Grouping the results according to the single column projection should eliminate all redundant values so that only unique Country values appear as 'group names' as return values.

However, when executing the search with this variant of the Subsearch projection, an error such as the following occurs:


ERROR: column "t0.id" must appear in the GROUP BY clause or be used in an aggregate function


The column 't0.id' referenced in the error denotes the 'ID' property of the entity in the parent search, which for technical reasons must be present in the subselect Group by so that it can be used in the context of the parent Collection projection.

images/download/attachments/157876346/image-2023-11-14_7-25-52-version-1-modificationdate-1699943158852-api-v2.png

The search works with this addition – Property projection for the path _parentQuery.id as an additional projection within Group by.

►NOTE◄ The additional Property projection was inserted here as the top grouping criterion, which is not necessary, but makes more logical sense than in the subordinate second position.

images/download/attachments/157876346/image-2023-11-14_7-25-2-version-1-modificationdate-1699943108817-api-v2.png