Page History
...
This function determines the intersection of two collections. It returns a collection containing the items that are present in both specified collections.
Syntax
Code Block |
---|
INTERSECTION ( collection1 , collection2 ) |
- collection1, collection2 - Collections to be intersected. These collections must be of the same base type.
Return type
- collection
Examples
Suppose the following model. Entity Teacher
has a multivalued relation with entity Child
via the relation Teacher.teaches_Children
.
Teacher instance | Child instance | Child.name | Child.hobbies |
---|---|---|---|
Teacher_1 | Child_1 | “Kim” | “Reading”, “Dancing” |
Teacher_1 | Child_2 | “Rick” | “Tennis”, “Dancing” |
Teacher_1 | Child_3 | “Bob” | “Painting”, “Basketball”, “Reading” |
Teacher_2 | Child_1 | “Kim” | “Reading”, “Dancing” |
Teacher_2 | Child_3 | “Bob” | “Painting”, “Basketball”, “Reading” |
Teacher_2 | Child_4 | “Mary” | “Football” |
INTERSECTION ( Teacher[Teacher_1].teaches_Children , Teacher[Teacher_2].teaches_Children )
results in a collection ofChild
instancesChild_1
andChild_3
INTERSECTION ( Teacher[Teacher_1].teaches_Children.name , Teacher[Teacher_2].teaches_Children.name )
= “Kim”, “Bob”INTERSECTION ( Child[Child_1].hobbies , Child[Child_3].hobbies )
= “Reading”INTERSECTION ( Child[Child_2].hobbies , Child[Child_3].hobbies )
results in an empty list
DIFFERENCE
This function returns a collection containing all the items from collection1 that are not present in collection 2.
Syntax
Code Block |
---|
DIFFERENCE ( collection1 , collection2 ) |
- collection1, collection2 - Collections to be intersected. These collections must be of the same base type.
Return type
- collection
Examples
DIFFERENCE (
Child
instances Child_1
and Child_3
DIFFERENCE ( Teacher[Teacher_1].teaches_Children.name , Teacher[Teacher_2].teaches_Children.name )
= “Kim”, “Bob”DIFFERENCE ( Child[Child_1].hobbies , Child[Child_3].hobbies )
= “Reading”[ "a", "b", "c"] , [ "c", "d", "e" ] )
= [ "a" , "b" ]DIFFERENCE ( [ "nv" , "bv" ] , [ "NV" ] )
= [ "bv" ]DIFFERENCE ( 1 , 1
)
results in an empty list
SYMMETRIC_DIFFERENCE
This function determines the symmetric difference between two collections. It returns a collection with the elements of the provided collections which are in either one of the collections, but not in both.
Syntax
Code Block |
---|
SYMMETRIC_DIFFERENCE ( collection1 , collection2 ) |
- collection1, collection2 - Collections to be intersected. These collections must be of the same base type.
Return type
- collection
Examples
SYMMETRIC_DIFFERENCE ( [ "a", "b", "c"] , [ "c", "d", "e" ] )
= [ "a", "b", "d", "e" ]SYMMETRIC_DIFFERENCE ( [ "nv" , "bv" ] , [ "NV" ] )
= [ "bv" ]SYMMETRIC_DIFFERENCE ( 1 , 1 )
results in an empty list
Collections vs. lists
UNIQUE, SUBSET, UNION and INTERSECTION return a collection of data, i.e. double entries are removed. However, COLLECT statements, + and - return a list of data. You have to be aware of this when using the SIZE or UNPACK function.
Example
Statuses = ["a","b","c","d","a","b","c","d"].
Result
The expression "SIZE ( COLLECT Status FROM {Statuses} )" will result in 8. Note that duplicates are not removed.
The expression "SIZE ( UNIQUE ( COLLECT Status FROM {Statuses} ) )" will result in 4, as the unique filters the duplicates.
UI Text Box | ||
---|---|---|
| ||
When the expression is completely evaluated, all duplicates are filtered as well. Using COLLECT Status FROM {Statuses} as a default expression on an attribute, will result in 4 elements. |