test_merge

The merge algebra: what combines from two partial answers, and what does not.

Each merge is checked against the same query run over the WHOLE table, which is the only assertion that means anything here – a merge that agrees with itself proves nothing. The refusals are tested as carefully as the successes, because an aggregate that combines wrongly answers confidently rather than failing.

Attributes

ROWS

Classes

Group

Stats

Functions

_totals(rows)

_groups(rows)

Per-key records from an ordered engine: a group CLOSES when the key

_stats(rows)

_runs(rows)

_fold_groups(earlier, later) → Group

_fold_stats(earlier, later) → Stats

_halves(rows)

test_sums_and_counts_add() → None

test_a_derived_output_is_recomputed_from_the_merged_totals() → None

An output that is an EXPRESSION over the aggregates is not an aggregate:

test_a_mean_survives_only_as_a_sum_and_a_count() → None

The remedy the refusal names, tested: a mean asked for as an expression

test_ordered_groups_fold_the_group_that_straddles_the_boundary() → None

The hazard an ordered engine makes concrete: the group the boundary

test_boundary_stats_come_from_the_ranges_that_own_them() → None

first and last are defined by position, which is why the arms'

test_unsorted_rows_refuse_the_ordered_merge() → None

The conditional merge, checked rather than assumed. An ordered engine

test_arms_that_arrive_out_of_order_refuse_the_ordered_merge() → None

Each arm ascends, but the later arm reopens a key the earlier one

test_keyed_groups_merge_over_the_whole_key_set() → None

The contrast with the ordered merge: an engine holding one accumulator

test_a_top_k_merges_two_k_lists() → None

Every row of the whole query's top k is in the top k of the range it

test_a_merged_top_k_keeps_the_earliest_arrival_tie_break() → None

The fixture's keys repeat, so the answer is decided by ties rather than

test_a_negative_limit_is_refused() → None

test_sorted_runs_merge_stably() → None

Equal keys take the earlier range first, which is what keeps a stable

test_an_empty_merge_answers() → None

_reductions([mergeable]) → dau_scheduler.MergeRule

test_check_split_refuses_a_mean_by_name() → None

The aggregate that looks additive and is not.

test_check_split_refuses_a_distinct_count_by_name() → None

test_the_order_statistics_and_moments_are_refused_by_name(kind) → None

test_the_refusal_reasons_are_read_only() → None

The table is shared by every caller in the process; one that edits

test_an_unknown_aggregate_is_refused_rather_than_summed() → None

Default-deny: an aggregate nobody has heard of is not added on the

test_a_declared_mean_passes_when_the_partials_carry_it() → None

Whether a mean survives is a property of what the ENGINES emit, not

test_boundary_stats_are_declarable_too() → None

test_a_shape_that_cannot_split_refuses_before_any_aggregate() → None

A windowed result whose window spans the boundary reads rows from both

test_a_rule_with_no_combine_says_so() → None

The default is not a silent identity. A rule declared without a combine

test_one_partial_is_the_answer() → None

A degenerate share ran the whole query on one engine, so no merge is

test_a_failed_arm_is_not_merged_into_a_short_answer() → None

An engine that invalidated its own work returns a partial that says so.

Module Contents

test_merge.ROWS
class test_merge.Group
key: int
total: int
count: int
class test_merge.Stats
key: int
first: int
last: int
minimum: int
maximum: int
count: int
test_merge._totals(rows)
test_merge._groups(rows)

Per-key records from an ordered engine: a group CLOSES when the key changes, which is what makes the boundary pair the only shared group.

test_merge._stats(rows)
test_merge._runs(rows)
test_merge._fold_groups(earlier: Group, later: Group) → Group
test_merge._fold_stats(earlier: Stats, later: Stats) → Stats
test_merge._halves(rows)
test_merge.test_sums_and_counts_add() → None
test_merge.test_a_derived_output_is_recomputed_from_the_merged_totals() → None

An output that is an EXPRESSION over the aggregates is not an aggregate: combining the arms’ ratios would produce a number that is not a ratio of anything, and it would look exactly like a total.

test_merge.test_a_mean_survives_only_as_a_sum_and_a_count() → None

The remedy the refusal names, tested: a mean asked for as an expression over two additive outputs splits exactly, while the mean of the arms’ means does not.

test_merge.test_ordered_groups_fold_the_group_that_straddles_the_boundary() → None

The hazard an ordered engine makes concrete: the group the boundary lands inside closes in BOTH arms, and the merge has to fold those two partial records rather than emit the key twice.

test_merge.test_boundary_stats_come_from_the_ranges_that_own_them() → None

first and last are defined by position, which is why the arms’ order is part of the contract: the straddling group opens in the earlier range and closes in the later one.

test_merge.test_unsorted_rows_refuse_the_ordered_merge() → None

The conditional merge, checked rather than assumed. An ordered engine closes a group when the key changes, so on unsorted rows it emits several records per key – merging those by key would collapse them into an answer no run produced.

test_merge.test_arms_that_arrive_out_of_order_refuse_the_ordered_merge() → None

Each arm ascends, but the later arm reopens a key the earlier one closed – so the two do not meet on one boundary key and the fold is not the merge this is.

test_merge.test_keyed_groups_merge_over_the_whole_key_set() → None

The contrast with the ordered merge: an engine holding one accumulator per distinct key can meet a key anywhere, so a key appears in both arms and there is no boundary pair.

test_merge.test_a_top_k_merges_two_k_lists() → None

Every row of the whole query’s top k is in the top k of the range it arrived in, so the two k-lists are the complete candidate set.

test_merge.test_a_merged_top_k_keeps_the_earliest_arrival_tie_break() → None

The fixture’s keys repeat, so the answer is decided by ties rather than by keys alone: a stable re-rank with the leading range first keeps earliest-arrival ties true of the whole table.

test_merge.test_a_negative_limit_is_refused() → None
test_merge.test_sorted_runs_merge_stably() → None

Equal keys take the earlier range first, which is what keeps a stable sort’s arrival-order ties true of the whole table rather than of each half.

test_merge.test_an_empty_merge_answers() → None
test_merge._reductions(mergeable=ADDITIVE) → dau_scheduler.MergeRule
test_merge.test_check_split_refuses_a_mean_by_name() → None

The aggregate that looks additive and is not.

test_merge.test_check_split_refuses_a_distinct_count_by_name() → None
test_merge.test_the_order_statistics_and_moments_are_refused_by_name(kind: str) → None
test_merge.test_the_refusal_reasons_are_read_only() → None

The table is shared by every caller in the process; one that edits it would change the refusal every other split sees.

test_merge.test_an_unknown_aggregate_is_refused_rather_than_summed() → None

Default-deny: an aggregate nobody has heard of is not added on the assumption that every aggregate is additive.

test_merge.test_a_declared_mean_passes_when_the_partials_carry_it() → None

Whether a mean survives is a property of what the ENGINES emit, not something the merge step can recover – so a caller whose partials carry sum and count separately says so, and the check believes it.

test_merge.test_boundary_stats_are_declarable_too() → None
test_merge.test_a_shape_that_cannot_split_refuses_before_any_aggregate() → None

A windowed result whose window spans the boundary reads rows from both ranges, so no aggregate list makes it mergeable.

test_merge.test_a_rule_with_no_combine_says_so() → None

The default is not a silent identity. A rule declared without a combine step has nothing to reassemble partials with, and saying that beats returning one arm’s answer.

test_merge.test_one_partial_is_the_answer() → None

A degenerate share ran the whole query on one engine, so no merge is involved and none is attempted.

test_merge.test_a_failed_arm_is_not_merged_into_a_short_answer() → None

An engine that invalidated its own work returns a partial that says so. Merging that into the other arm’s would produce a plausible answer missing half the rows, so the failure is what reaches the caller.