Versions Compared

Key

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

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 )


Inputs
  • collection1, collection2 - Collections to be compared. These collections must be of the same base type.


Return type

  • collection


Venn diagram



Examples

ExpressionResultType
SYMMETRIC_DIFFERENCE ( [ "a" , "b" , "c" ] , [ "c" , "d" , "e" ] )[ "a", "b", "d", "e" ]String (multivalued)
SYMMETRIC_DIFFERENCE ( [ "nv" , "bv" ] , [ "NV" ] )[ "bv" ]String (multivalued)
SYMMETRIC_DIFFERENCE ( 1 , 1 )[ ]Integer (multivalued)



Back to top

Panel
bgColorwhite

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 this when using the SIZE or UNPACK function, or when using TSL.

This is best illustrated with the following examples.

Person instancePerson.NamePerson.AgePerson_1Kim24Person_2Rick25Person_3Bob25ExpressionResultTypeNoteCOLLECT Person.Age FROM ALL Person[ 24 , 25 ]String (multivalued)SIZE ( COLLECT Person.Age FROM ALL Person )3IntegerThe intermediary collection is [ 24, 25, 25 ]

 TSL:

The ages present are: [[[ COLLECT Person.Age FROM ALL Person ]]].

The ages present are: 24, 25, 25.StringThe intermediary collection is [ 24, 25, 25 ]SIZE ( UNIQUE ( COLLECT Person.Age FROM ALL Person ) )2IntegerThe 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.AgePerson_2Rick25Person_3Bob25ExpressionResultTypeNoteCOLLECT Person.Age FROM ALL Person[ 25 ]Integer (multivalued)UNPACK ( COLLECT Person.Age FROM ALL Person )ErrorThe collection contains 2 elements [ 25 , 25 ]UNPACK ( UNIQUE ( COLLECT Person.Age FROM ALL Person ) )25
UI Text Box
typenote

 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.

Back to top