UnionedEntityClass

UnionedEntityClass[class1,]

represents an entity class containing all the distinct entities in all the classi.

Details and Options

  • UnionedEntityClass[class1,class2,] is effectively equivalent to the unsorted union of the entities in each classi as they appear when applying EntityList.
  • When the classes appearing in UnionedEntityClass effectively have the same type after the simplification in EntityList, the resulting entities will have that type. When performing the union of incompatible types, the resulting entities will have a new type.
  • UnionedEntityClass[class1,class2,,SameTestProperties {props1,props2,}] uses properties propsi from classi to test for entity equality.
  • UnionedEntityClass[class,SameTestProperties{prop1,prop2,}] can be used to remove entities that have identical sets of values for all properties propi.
  • UnionedEntityClass[class1,class2,,SameTestPropertiesFull] treats all entities as different and can be used to concatenate multiple classes into a single one.
  • EntityProperties[UnionedEntityClass[class1,class2,]] returns all the properties of each classi, along with EntityProperty[UnionedEntityClass[],"propj"], where "propj" are any of the properties that appear in at least two of the classi when those classes have different entity types.

Examples

open allclose all

Basic Examples  (3)

Compute the union of two classes of the same type:

Mix different types of entities:

When used with relational-database-backed entities, UnionedEntityClass can be used to yield different SQL statements:

Generally, it corresponds to a UNION statement:

When used with SameTestPropertiesFalse, it corresponds to a UNION ALL statement:

When used with a single argument and an explicit list for SameTestProperties, it corresponds to PostgreSQL DISTINCT ON:

Scope  (4)

Use UnionedEntityClass to group together entities of the same type:

Group together entities of different types:

When grouping together entities of different types, all entities are treated as different:

Use the option SameTestProperties to delete duplicates:

UnionedEntityClass can be used with a single argument and SameTestProperties to represent a class of entities where duplicates according to some criterion have been removed:

Options  (2)

SameTestProperties  (2)

Use selected properties to define equality between entities:

Setting SameTestProperties to False effectively joins the classes:

Note that helium appears twice in this list:

Properties & Relations  (3)

UnionedEntityClass is usually equivalent to Union:

UnionedEntityClass with SameTestPropertiesFalse is roughly equivalent to Join:

UnionedEntityClass with a single argument and an explicit setting for SameTestProperties is roughly equivalent to DeleteDuplicatesBy:

When grouping together implicit EntityClass or FilteredEntityClass expressions, it is often more efficient to use disjunction in the condition:

The two classes are equivalent apart from the order:

Possible Issues  (1)

Entities backed by a relational database have some additional limitations:

Some relational database backends do not guarantee that the order of rows resulting from this operation is preserved, for example, in this case "employees" appear before "offices":

Introduced in 2020
 (12.1)