Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 instanceChild instanceChild.nameChild.hobbies
Teacher_1Child_1“Kim”“Reading”, “Dancing”
Teacher_1Child_2“Rick”“Tennis”, “Dancing”
Teacher_1Child_3“Bob”“Painting”, “Basketball”, “Reading”
Teacher_2Child_1“Kim”“Reading”, “Dancing”
Teacher_2Child_3“Bob”“Painting”, “Basketball”, “Reading”
Teacher_2Child_4“Mary”“Football”

 

  • INTERSECTION ( Teacher[Teacher_1].teaches_Children , Teacher[Teacher_2].teaches_Children ) results in a collection of Child instances Child_1 and Child_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
_nav_BackToTop
_nav_BackToTop

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
_nav_BackToTop
_nav_BackToTop

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
_nav_BackToTop
_nav_BackToTop

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 instancePerson.NamePerson.Age
Person_1Kim24
Person_2Rick25
Person_3Bob25
  • 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 the UNIQUE function)

Now an example with the UNPACK function. We leave out the first instance from the previous example.

Person instancePerson.NamePerson.Age
Person_2Rick25
Person_3Bob25
  • 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
typewarningnote

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 COLLECT statement can contain duplicates. The functions UNIQUE, UNION, INTERSECTION, DIFFERENCE and SYMMETRIC_DIFFERENCE always return collections without duplicates.

Include Page
_nav_BackToTop
_nav_BackToTop