﻿ Set Joining | Enterprise Architect User Guide
 Prev Next

# Set Joining

## Intersect

intersect(left: set, right: set)

An 'intersect' join will return a set containing all nodes that exist in both the left and right set. This join is comparable to a bitwise AND operation.  In set theory, this type of join is called an 'intersection'.

{1, 2, 3} intersected with {2, 3, 4} results in {2, 3}

This example returns a set that contains all nodes that have a single attribute with the name of "TYPE" and the value of "int".

intersect(

getByValue("int"),

getByName("TYPE")

)

## Union

union(left: set, right: set [, right: set])

'Union' joins return a set that includes all nodes found in either the left or the right set. This join is used to combine the results of two or more sub-queries into a single set. A 'union' join is similar to a logical OR operation. In set theory, the 'union' join is known as a union.

The 'union' join is able to operate on more than two sets. The result is a set that contains all nodes from all supplied sets. The 'union' join is the only join able to operate on more than two sets.

The result of a 'union' join is always a discrete set, unless one of the source sets contained duplicates. This means that duplicates in source sets will be preserved, but the 'union' join itself will not generate duplicates.

{1, 2, 3} unioned with {2, 3, 4} results in {1, 2, 3, 4}

This sample creates a set containing all nodes with an attribute named “TYPE” or a single attribute with the value of “int”.

union(

getByValue("int"),

getByName("TYPE")

)

## Except

except(left: set, right: set)

'except' joins return sets that contain any nodes from either set that do not appear in both sets. This join is similar to a bitwise XOR operation. In set theory, this type of join is referred to as a 'symmetric difference' join.

{1, 2, 3} excepted with {2, 3, 4} results in {1, 4}

For more information on the 'symmetric difference' join in set theory, see http://en.wikipedia.org/wiki/Symmetric_difference.

This sample returns a set of all nodes with an attribute named "TYPE" but no single attribute with the value of "int", plus all nodes with an attribute with the value of "int" that are not named "TYPE".

except(

getByValue("int"),

getByName("TYPE")

)

## Exclude

exclude(left: set, right: set)

'Exclude' joins return a set that contains all nodes from the left set that do not appear in the right set.  In set theory, this type of join is referred to as a relative complement join.

{1, 2, 3} complemented with {2, 3, 4} results in {1}

This sample returns a set of all nodes with a value of “int” that are not “TYPE” nodes:

Exclude(

getByValue(“int”),

getByName(“TYPE”)

)

## OffsetIntersect

offsetIntersect(count: number, left: set, right: set)

offsetIntersect(value: string, left: set, right: set)

offsetIntersect(count: number, value: string, left: set, right: set)

The offsetIntersect function performs both a non-destructive tree traversal and an intersect join in one operation. Each node in the left set is traversed according to parameters provided, then the result of the traversal is intersected with the right set.  If the intersect passes, the original node is added to the result set.  If the intersect fails, the node is excluded from the result set.

The traversal parameters for offsetIntersect are the same as for 'move' and 'filter'.  For more information about the traversal parameters, see the 'move' function described in the Set Traversal Help topic.

This sample takes all “NAME” nodes, traverses them up one parent, and intersects them with a set of all “CLASS” nodes.  If a “NAME” node passes both the traversal and intersect join, it is added to the result set. The result is a set of all “NAME” nodes whose immediate parent is a “CLASS” node.

offsetIntesect(1,

getByNode(“NAME”),

getByNode(“CLASS”)

)