columnsOffunctionfunction columnsOf(result: FanOut): readonly MergedColumn[]The columns of the answers and the type each has: the one every non-null value has, decimal where numbers are whole and not, and text where they disagree.
Merging (commons data 0059-sql-federate): the rows of a fan-out are loaded, tagged with the target they came from, into tables of an engine the caller gives (DuckDB is the one meant for it), where the merge is SQL: a fleet_rows table with a column for each column of the answers (the type they all agree on, or text where they do not), the target, when it was collected and a key that is the same for the same row; and a fleet_targets table with what each target answered. Counting by a column and finding the targets that differ are given as queries over those tables.
columnsOffunctionfunction columnsOf(result: FanOut): readonly MergedColumn[]The columns of the answers and the type each has: the one every non-null value has, decimal where numbers are whole and not, and text where they disagree.
ColumnTypetypeno test imports ittype ColumnType = "text" | "integer" | "decimal" | "boolean";The type a column of the merged rows has.
countByfunctionfunction countBy(m: Merged, column: string): Promise<readonly { readonly value: unknown; readonly rows: number; readonly targets: number; }[]>How many of the rows have each value of a column, and in how many targets: the value, the rows and the targets.
Differenceinterfaceno test imports itinterface DifferenceWhat differs between a target and the baseline: a row the baseline has and the target lacks, or the target has and the baseline lacks.
| Member | Type | What it is |
|---|---|---|
target | string | |
kind | "extra" | "missing" | |
row | Readonly<Record<string, unknown>> |
differencesfunctionfunction differences(m: Merged, baseline?: "majority" | { readonly target: string; }): Promise<readonly Difference[]>The targets that differ from a baseline, row by row. The baseline is the rows that at least half of the targets that answered have (majority, the default), or the rows of one target.
| Parameter | What it is |
|---|---|
m | the merge |
baseline | majority, or the id of a target |
Mergedinterfaceno test imports itinterface MergedThe tables of a merge.
| Member | Type | What it is |
|---|---|---|
columns | readonly MergedColumn[] | |
rows | Table<Record<string, unknown>, Record<string, unknown>, "fleet_rows"> | fleet_rows: the rows of every target that answered. |
targets | Table<TargetRow, TargetRow, "fleet_targets"> | fleet_targets: what each target answered. |
on | Runner | Runs SQL on the engine the merge is in. |
MergedColumninterfaceno test imports itinterface MergedColumnA column of the merged rows.
| Member | Type | What it is |
|---|---|---|
name | string | |
type | ColumnType | |
mixed | boolean | Whether the targets gave it in more than one type, and it is text for that. |
mergeIntofunctionfunction mergeInto(result: FanOut, on: Runner): Promise<Merged>Loads a fan-out into fleet_rows and fleet_targets of an engine; tables of those names that are there are replaced.
| Parameter | What it is |
|---|---|
result | the fan-out |
on | the engine and its dialect (DuckDB, where the merge is analytical) |
tablesOfconstno test imports itconst tablesOf: (m: Merged) => { readonly rows: Table<Record<string, unknown>, Record<string, unknown>, "fleet_rows">; readonly targets: Table<TargetRow, TargetRow, "fleet_targets">; }A merge's tables as typed tables for a query of the caller's own (0053): from(tablesOf(m).rows)....
TargetRowinterfaceno test imports itinterface TargetRowA row of fleet_targets.
| Member | Type | What it is |
|---|---|---|
target | string | |
status | string | |
error | string | null | |
rows | number | |
durationMs | number | |
collectedAt | string |