UnionTable

A UnionTable stacks rows from multiple source tables. Field mappings declare which source-table fields feed each union-table field, since source schemas may differ.

class UnionTable(id, source_tables)[source]

Bases: Table

Represents a table that is derived by performing a union operation on multiple source tables.

A union operation combines rows from multiple tables into a single table. Unlike joins,

a union does not merge columns based on key relationships but instead stacks rows from different tables on top of each other.

source_tables

The list of tables being combined into the UnionTable.

filter_field

An optional field ID that acts as a filter for selecting specific rows across the source tables.

set_filter_field(field)[source]

Sets the filter field for this union table. Returns self.

Return type:

UnionTable

add_field(id, data_type, order_index=None, description=None)[source]

Adds a new field to the UnionTable.

Parameters:
  • id (str) – A unique identifier for the field.

  • data_type (BaseDataType) – The data type of the field.

  • order_index (int | None) – (Optional) The order in which the field appears.

Returns:

The newly created DataField instance.

Return type:

DataField

add_field_mapping(source_table, field_name, source_field)[source]

Maps a field from a source table to a field in the UnionTable.

Field mappings allow fields with different names in different tables to be treated as equivalent in the UnionTable.

Parameters:
  • source_table (Table | UnionSource) – The source table containing the field, or a UnionSource describing the source table and the key to identify it if the same source is reused.

  • field_name (str) – The name of the field in the UnionTable.

  • source_field (Field) – The corresponding field in the source table.

Raises:

ValueError – If the source table is not part of the UnionTable.

direct_field_mapping(source_tables=None)[source]

Automatically maps fields from the source tables that have matching field IDs.

If source_tables is not provided, it defaults to all source tables in the UnionTable.

Parameters:

source_tables (list[Table | UnionSource] | None) – (Optional) A list of source tables to perform direct field mapping on.

Raises:

ValueError – If a provided source table is not part of the UnionTable.

class FieldMapping(union_source)[source]

Bases: Buildable

property source_table: Table

the source table for this field mapping.

Type:

Returns

property mapping_key: str

mapping_key for this field mapping.

Type:

Returns

add_map(field_name, source_field)[source]
build()[source]

Serialise this object to a JSON-compatible dict.

Converts public, non-None instance attributes to camelCase keys. Recursively builds nested Buildable objects, converts Enum values, and serialises date/time/datetime instances as lists of components.

Returns:

The serialised representation.

Return type:

dict[str, Any]

Raises:

TypeError – If an attribute value is of an unsupported type.

class UnionSource(source_table, mapping_key)[source]

Bases: Buildable

A source table in a union. Multiple UnionSource instances in a UnionTable may reference the same underlying table, distinguished by mapping_key.

property source_table: Table