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.
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:
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.
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. ►NOTE◄ Optionally, 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.
|
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 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.
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:
|
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 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:
|
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.
|
|
►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:
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).
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. |
|
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:
This configuration returns all Country values of all 'Companies' for each user in a tuple search.
|
|
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.
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.
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. |
|