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
Include Page | ||||
---|---|---|---|---|
|
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 intersectedcompared. These collections must be of the same base type.
Return type
- collection
Examples
DIFFERENCE ( [ "a", "b", "c"] , [ "c", "d", "e" ] )
= [ "a" , "b" ]DIFFERENCE ( [ "nv" , "bv" ] , [ "NV" ] )
= [ "bv" ]DIFFERENCE ( 1 , 1 )
results in an empty list
Include Page | ||||
---|---|---|---|---|
|
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 intersectedcompared. 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
Include Page | ||||
---|---|---|---|---|
|
Collections vs. lists
A note on collections and duplicates
An expression resulting in a collection does not contain duplicates. Please be aware however, that intermediary results of a COLLECT
statement can contain duplicates. You have to be aware of 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.This is best illustrated with the following examples.
Person instance | Person.Name | Person.Age |
---|---|---|
Person_1 | Kim | 24 |
Person_2 | Rick | 25 |
Person_3 | Bob | 25 |
COLLECT Person.Age FROM ALL Person
= [ 24, 25 ]SIZE ( COLLECT Person.Age FROM ALL Person )
= 3 (the intermediary collection is [ 24, 25, 25 ]SIZE ( UNIQUE ( COLLECT Person.Age FROM ALL Person ) )
= 2 (the duplicates in the intermediary collection are filtered by theUNIQUE
function)
Now an example with the UNPACK function. We leave out the first instance from the previous example.
Person instance | Person.Name | Person.Age |
---|---|---|
Person_2 | Rick | 25 |
Person_3 | Bob | 25 |
COLLECT Person.Age FROM ALL Person
= [ 25 ]UNPACK ( COLLECT Person.Age FROM ALL Person )
will fail, because the collection contains 2 elements [25,25]UNPACK ( UNIQUE ( COLLECT Person.Age FROM ALL Person ) )
= 25
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 Only the intermediary results of a |
Include Page | ||||
---|---|---|---|---|
|