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:
TableRepresents 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:
- add_field(id, data_type, order_index=None, description=None)[source]
Adds a new field to the UnionTable.
- 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