Concatenate Tables
Stack tables into one
how decides what concat() does when the inputs do not line up.
Needs a transformer. Getting its guide.
Called tabsdata 2 times (ctrl+o to expand)
Generating — concat() appends rows, and the default how="vertical" is right here because both inputs carry the same three columns with the same types.
Called tabsdata 3 times (ctrl+o to expand)
The transformer, registered in subscriptions:
@transformer(
input_tables=["sales_east", "sales_west"],
output_tables=["sales_all"],
)
def combine_sales(east: TableFrameSpec, west: TableFrameSpec) -> TableFrameSpec:
return concat([east, west])
Execution committed, 0 failures.
subscriptions/sales_all is live — 2 rows from sales_east then 2 from sales_west, in that order, columns unchanged:
┌────────┬───────┬────────┐ │ region │ month │ amount │ ├────────┼───────┼────────┤ │ east │ jan │ 10 │ ├────────┼───────┼────────┤ │ east │ feb │ 20 │ ├────────┼───────┼────────┤ │ west │ jan │ 30 │ ├────────┼───────┼────────┤ │ west │ feb │ 40 │ └────────┴───────┴────────┘
Transformed tables
| region | month | amount |
|---|---|---|
| east | jan | 10 |
| east | feb | 20 |
| region | month | amount |
|---|---|---|
| west | jan | 30 |
| west | feb | 40 |
| region | month | amount |
|---|---|---|
| east | jan | 10 |
| east | feb | 20 |
| west | jan | 30 |
| west | feb | 40 |
Needs a transformer. Getting its guide.
Called tabsdata 2 times (ctrl+o to expand)
Generating — the columns match and the types do not, so how="vertical_relaxed" casts amount to a common supertype instead of refusing.
Called tabsdata 3 times (ctrl+o to expand)
The transformer, registered in subscriptions:
@transformer(
input_tables=["sales_east", "sales_west"],
output_tables=["sales_all"],
)
def combine_sales(east: TableFrameSpec, west: TableFrameSpec) -> TableFrameSpec:
return concat([east, west], how="vertical_relaxed")
Execution committed, 0 failures.
subscriptions/sales_all is live — amount came out Float64, so the Int64 value from sales_east was cast:
┌────────┬────────┐ │ region │ amount │ ├────────┼────────┤ │ east │ 10.0 │ ├────────┼────────┤ │ west │ 30.5 │ └────────┴────────┘
Transformed tables
| regionString | amountInt64 |
|---|---|
| east | 10 |
| regionString | amountFloat64 |
|---|---|
| west | 30.5 |
| regionString | amountFloat64 |
|---|---|
| east | 10.0 |
| west | 30.5 |
Needs a transformer. Getting its guide.
Called tabsdata 2 times (ctrl+o to expand)
Generating — the columns differ, which how="vertical" rejects. how="diagonal" takes the union of the columns and fills the gaps with null.
Called tabsdata 3 times (ctrl+o to expand)
The transformer, registered in subscriptions:
@transformer(
input_tables=["sales_east", "sales_west"],
output_tables=["sales_all"],
)
def combine_sales(east: TableFrameSpec, west: TableFrameSpec) -> TableFrameSpec:
return concat([east, west], how="diagonal")
Execution committed, 0 failures.
subscriptions/sales_all is live — 4 columns, the union of both inputs. The east row has no discount and the west row has no amount:
┌────────┬───────┬────────┬──────────┐ │ region │ month │ amount │ discount │ ├────────┼───────┼────────┼──────────┤ │ east │ jan │ 10 │ null │ ├────────┼───────┼────────┼──────────┤ │ west │ jan │ null │ 5 │ └────────┴───────┴────────┴──────────┘
Transformed tables
| region | month | amount |
|---|---|---|
| east | jan | 10 |
| region | month | discount |
|---|---|---|
| west | jan | 5 |
| region | month | amount | discount |
|---|---|---|---|
| east | jan | 10 | null |
| west | jan | null | 5 |
Needs a transformer. Getting its guide.
Called tabsdata 2 times (ctrl+o to expand)
Generating — the inputs differ in both their columns and their types, so this needs how="diagonal_relaxed", which unions the columns and casts to a supertype in one pass.
Called tabsdata 3 times (ctrl+o to expand)
The transformer, registered in subscriptions:
@transformer(
input_tables=["sales_east", "sales_west"],
output_tables=["sales_all"],
)
def combine_sales(east: TableFrameSpec, west: TableFrameSpec) -> TableFrameSpec:
return concat([east, west], how="diagonal_relaxed")
Execution committed, 0 failures.
subscriptions/sales_all is live — the union of both column sets, each column keeping the type it needs:
┌────────┬────────┬──────────┐ │ region │ amount │ discount │ ├────────┼────────┼──────────┤ │ east │ 10 │ null │ ├────────┼────────┼──────────┤ │ west │ null │ 5.5 │ └────────┴────────┴──────────┘
Transformed tables
| regionString | amountInt64 |
|---|---|
| east | 10 |
| regionString | discountFloat64 |
|---|---|
| west | 5.5 |
| regionString | amountInt64 | discountFloat64 |
|---|---|---|
| east | 10 | null |
| west | null | 5.5 |
None entries in the list are skipped. A list that is None, empty, or empty
once the None entries are dropped makes concat() return None, which leaves
the output table on its current version instead of committing a new one.