You are viewing the documentation for Blueriq 17. Documentation for other versions is available in our documentation directory.
SIZE collection
This function determines the size of a collection.
Syntax
SIZE ( collection )
- collection - A collection of attribute or entity instances. This can be an expression or a relation attribute for instance.
Return type
- integer
Example
Suppose you have a Parent
and a Child
entity, where Parent
has a multivalued relation with Child
via the relation Parent.has_Children
. With this model the following instances are created:
Parent instance | Child instance | Child.name | Child.hobbies |
---|---|---|---|
Parent_1 | Child_1 | “Kim” | “Reading”, “Dancing” |
Parent_1 | Child_2 | “Rick” | “Tennis”, “Dancing” |
Parent_1 | Child_3 | “Bob” | “Painting”, “Basketball”, “Reading” |
Parent_2 | Child_4 | “Mary” | “Football” |
Then:
- if
Parent_1
is active,SIZE ( Parent.has_Children )
= 3 - if
Parent_2
is active,SIZE ( Parent.has_Children )
= 1 - without an active
Parent
instance,SIZE ( Parent.has_Children )
results in an error - if
Child_1
is active,SIZE ( Child.hobbies )
= 2 - if
Child_3
is active,SIZE ( Child.hobbies )
= 3 - if
Child_4
is active,SIZE ( Child.hobbies )
= 1 SIZE ( ? )
= 0
COUNT
and SIZE
are similar except for UNKNOWN
: COUNT ( ? ) = UNKNOWN
UNIQUE collection
The UNIQUE
function filters duplicate items from a collection. An expression resulting in a collection, never contains duplicate values. A subexpression however, can contain duplicates.
Syntax
UNIQUE ( collection )
- collection - A collection of attribute or entity instances.
Examples
Suppose the following model.
Person instance | Person.name |
---|---|
Person_1 | “Kim” |
Person_2 | “Rick” |
Person_3 | “Bob” |
Person_4 | “Rick” |
COLLECT Person.name FROM ALL Person
= "Kim”, “Rick”, “Bob” (a result never contains duplicate values)SIZE ( COLLECT Person.name FROM ALL Person )
= 4 (a subexpression can contain duplicate values)SIZE ( UNIQUE ( COLLECT Person.name FROM ALL Person ) )
= 3 (the collection holds three unique values)
SUBSET OF
This function returns TRUE
if the items in a collection are all present in another collection.
Syntax
collection1 SUBSET OF collection2
- collection1 - The collection that is tested to be a subset of the second collection.
- collection2 - The collection that is tested to hold all the items in the first collection.
Return type
- boolean
Examples
('a', 'b', 'c') SUBSET OF ('a', 'b', 'c', 'd')
= TRUE('a', 'b', 'c', 'd') SUBSET OF ('a', 'b', 'c')
= FALSE(Person.hobbies) SUBSET OF ([“Tennis”, “Soccer”, “Music”])
= TRUE ifPerson.hobbies = “Tennis”, “Soccer”
(Person.hobbies) SUBSET OF ([“Tennis”, “Soccer”, “Music”])
= UNKNOWNif Person.hobbies = ?
(Person.hobbies) SUBSET OF ([“Tennis”, “Soccer”, ?])
= FALSE ifPerson.hobbies = “Tennis”, “Soccer”
('a', 'b', 'c') SUBSET OF (['a', 'b', 'c'])
will result in an error.
UNION
Adds two collections of the same base type to a new collection.
Syntax
UNION ( collection1 , collection2 )
- collection1 - First collection to be added to the new collection.
- collection2 - Second collection to be added to the new collection.
Return type
- collection
Examples
Suppose you have a Parent
and a Child
entity, where Parent
has a multivalued relation with Child
via the relation Parent.has_Children
. With this model the following instances are created:
Parent instance | Child instance | Child.name | Child.hobbies |
---|---|---|---|
Parent_1 | Child_1 | “Kim” | “Reading”, “Dancing” |
Parent_1 | Child_2 | “Rick” | “Tennis”, “Dancing” |
Parent_1 | Child_3 | “Bob” | “Painting”, “Basketball”, “Reading” |
Parent_2 | Child_4 | “Mary” | “Football” |
UNION ( Parent[Parent_1].has_Children , Parent[Parent_2].Has_Children )
results in a collection of allChild
instancesUNION ( Parent[Parent_1].has_Children.name , Parent[Parent_2].Has_Children.name )
= “Kim”, “Rick”, “Bob”, “Mary”- if
Child_2
is active,UNION ( Child.hobbies , “Reading” )
= “Tennis”, “Dancing”, “Reading” UNION ( Child[Child_1].hobbies , Child[Child_2].hobbies )
= “Reading”, “Dancing”, “Tennis”
INTERSECTION
This function determines the intersection of two collections. It returns a collection containing the items that are present in both specified collections.
Syntax
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 of child instances Child_1 and Child_3
- INTERSECTION(Teacher[Teacher_1].teaches_Children.name, Teacher[Teacher_2].teaches_Children.name) results in a “Kim”, “Bob”
- INTERSECTION(Child[Child_1].hobbies, Child[Child_3].hobbies) results in “Reading”
- INTERSECTION(Child[Child_2].hobbies, Child[Child_3].hobbies) 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.
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.