dax: replay the umbrella's hop index, blank-key orphan rule and CONCATENATEX pairs (#2228)

This commit is contained in:
alosslessdev
2026-11-05 05:28:35 -05:00
parent 6dbb9e3c8e
commit 278f95e26a
10 changed files with 117 additions and 106 deletions
+3 -1
View File
@@ -283,7 +283,9 @@ impl<'a> Binder<'a> {
"RANK.EQ" if index == 2 => clause_keyword(arg, &["ASC", "DESC"]),
"TOPNSKIP" if index == 4 => clause_keyword(arg, &["ASC", "DESC"]),
"SAMPLE" if index == 3 => clause_keyword(arg, &["ASC", "DESC"]),
"CONCATENATEX" if index == 4 => clause_keyword(arg, &["ASC", "DESC"]),
// CONCATENATEX takes `(orderBy, Order)` pairs from index 4 on, so every even
// offset from 4 is an order word.
"CONCATENATEX" if index >= 4 && (index - 4) % 2 == 0 => clause_keyword(arg, &["ASC", "DESC"]),
"ROWNUMBER" if index == 5 => clause_keyword(arg, &["NONE", "LOWESTPARENT", "HIGHESTPARENT"]),
// Window/relation clauses take bare enum words: `ORDERBY(x, DESC)`,
// `WINDOW(1, ABS, 1, ABS, ...)`, `INDEX(..., KEEP, PARTITIONBY(...))`, and the
+14 -58
View File
@@ -578,16 +578,16 @@ impl<'a> Evaluator<'a> {
.unwrap_or_else(|| RelationshipFlow::from_flags(relationship.inactive, relationship.bidirectional));
// `other` is the side whose filters reach `table`: the one side when filters flow
// one-to-many (this table is the many side), the many side for the reverse direction.
let (other, self_column, other_column, one_to_many) = if relationship.from_table == table {
let (other, self_column, other_column) = if relationship.from_table == table {
if !flow.one_to_many {
continue;
}
(relationship.to_table, relationship.from_column, relationship.to_column, true)
(relationship.to_table, relationship.from_column, relationship.to_column)
} else if relationship.to_table == table {
if !flow.many_to_one {
continue;
}
(relationship.from_table, relationship.to_column, relationship.from_column, false)
(relationship.from_table, relationship.to_column, relationship.from_column)
} else {
continue;
};
@@ -599,17 +599,16 @@ impl<'a> Evaluator<'a> {
self.bump(|counters| &counters.relationship_lookups);
let keys: BTreeSet<ScalarKey> =
other_rows.iter().filter_map(|row| storage.value(other, other_column, *row)).map(|value| ScalarKey::from(&value)).collect();
// A one-side filter that selects BLANK also selects the rows that do not join it at
// all: DAX's BLANK member carries the orphan keys, so the BLANK cell of a pivot counts
// its fact rows instead of hiding them.
let blank_member = one_to_many && self.selects_blank_member(other, filters, &mut visited.clone());
let index_of = |key: &ScalarKey| relationship.rows_to(key);
let mut retained = Vec::with_capacity(rows.len());
for row in rows {
let Some(value) = storage.value(table, self_column, row) else { continue };
let key = ScalarKey::from(&value);
let orphan = key == ScalarKey::Blank || index_of(&key).is_empty();
if keys.contains(&key) || (blank_member && orphan) {
// A BLANK foreign key never joins a one-side row, whatever the related table
// holds: it is an orphan, exactly as `column_field_value` reads it.
if key == ScalarKey::Blank {
continue;
}
if keys.contains(&key) {
retained.push(row);
}
}
@@ -677,16 +676,16 @@ impl<'a> Evaluator<'a> {
.get(&index)
.copied()
.unwrap_or_else(|| RelationshipFlow::from_flags(relationship.inactive, relationship.bidirectional));
let (other, self_column, other_column, one_to_many) = if from == table {
let (other, self_column, other_column) = if from == table {
if !flow.one_to_many {
continue;
}
(to, &relationship.from_column, &relationship.to_column, true)
(to, &relationship.from_column, &relationship.to_column)
} else if to == table {
if !flow.many_to_one {
continue;
}
(from, &relationship.to_column, &relationship.from_column, false)
(from, &relationship.to_column, &relationship.from_column)
} else {
continue;
};
@@ -704,22 +703,11 @@ impl<'a> Evaluator<'a> {
};
let keys: BTreeSet<ScalarKey> =
self.table_inner(other, filters, visited).rows.iter().filter_map(|row| row.get(other_col)).map(ScalarKey::from).collect();
// As on the storage path, a one-side filter that selects BLANK also selects the rows
// whose key has no related row: DAX's BLANK member carries the orphan keys.
let blank_member = one_to_many && self.selects_blank_member(other, filters, &mut visited.clone());
let known: BTreeSet<ScalarKey> = if blank_member {
self.model
.tables
.get(other)
.map(|table| table.rows.iter().filter_map(|row| row.get(other_col)).map(ScalarKey::from).collect())
.unwrap_or_default()
} else {
BTreeSet::new()
};
rows.retain(|row| {
let Some(value) = row.get(self_col) else { return false };
let key = ScalarKey::from(value);
keys.contains(&key) || (blank_member && (key == ScalarKey::Blank || !known.contains(&key)))
// A BLANK foreign key never joins, so it is never in the related key set.
key != ScalarKey::Blank && keys.contains(&key)
});
}
@@ -762,38 +750,6 @@ impl<'a> Evaluator<'a> {
false
}
/// Whether the current filters select the BLANK member of `table`.
///
/// A filter that names BLANK on any of the table's columns selects it, and so does a filter
/// that reaches `table` from a further dimension over an active one-to-many relationship: DAX
/// represents the rows that do not join a dimension by the dimension's BLANK member, so the
/// whole chain is in the BLANK member. That member is what makes an orphan key belong to the
/// BLANK group of a pivot instead of falling out of the filter.
fn selects_blank_member(&self, table: usize, filters: &FilterContext, visited: &mut BTreeSet<usize>) -> bool {
if !visited.insert(table) {
return false;
}
if filters.filters.iter().any(|((filtered, _), keys)| *filtered == table && keys.contains(&ScalarKey::Blank)) {
return true;
}
for (index, relationship) in self.model.relationships.iter().enumerate() {
let flow = filters
.relationships
.get(&index)
.copied()
.unwrap_or_else(|| RelationshipFlow::from_flags(relationship.inactive, relationship.bidirectional));
let (Some(from), Some(to)) = (self.model.table_index(&relationship.from_table), self.model.table_index(&relationship.to_table)) else {
continue;
};
// `table` is the many side of this relationship, so `to` is the dimension whose
// filters reach it.
if from == table && flow.one_to_many && to != table && self.selects_blank_member(to, filters, visited) {
return true;
}
}
false
}
pub(crate) fn eval_table(&self, expr: &BoundExpr, ctx: &mut Context) -> Result<TableValue, EvalError> {
match expr {
BoundExpr::Table(table) => Ok(self.table(*table, &ctx.filters)),
+4 -4
View File
@@ -69,7 +69,7 @@ pub static FUNCTIONS: &[FunctionSpec] = &[
"Returns TRUE when the table has a row whose values equal every supplied value, in \
column order. The IN operator executes this function; comparisons are strict, so \
BLANK does not match 0.",
&["CONTAINSROW ( { \"Red\", \"Blue\" }, Product[Color] )", "CONTAINSROW ( Sales, Sales[ProductKey], 1 )"],
&["CONTAINSROW ( { \"Red\", \"Blue\" }, Product[Color] )", "CONTAINSROW ( VALUES ( Sales[ProductKey] ), 1 )"],
),
spec(
"CONTAINSSTRING",
@@ -106,9 +106,9 @@ pub static FUNCTIONS: &[FunctionSpec] = &[
&[overload(&[])],
ReturnType::String,
FunctionFlags::new(false, true, false, true, false),
"Returns the CustomData connection-string property supplied by the client, or BLANK when \
the connection did not define it. It does not inspect the data model or the filter \
context.",
"Returns the CustomData connection-string property supplied by the client, or an empty \
string when the connection did not define it. It does not inspect the data model or the \
filter context.",
&["CUSTOMDATA ()"],
),
spec(
@@ -215,9 +215,9 @@ pub static FUNCTIONS: &[FunctionSpec] = &[
&[overload(&[ParamKind::Date])],
ReturnType::Table,
FunctionFlags::new(false, false, false, true, true),
"Returns the last date of the month visible in the filter context as a single-row table, \
restricted to dates present in the date column. Use it as a CALCULATE modifier for \
semi-additive measures; the marked date table must contain the month-end date.",
"Returns the last date of the month visible in the filter context as a single-row table: \
the latest date of that month that exists in the date column of the marked date table. Use it as a CALCULATE \
modifier for semi-additive measures.",
&["ENDOFMONTH ( 'Date'[Date] )"],
),
spec(
+53 -19
View File
@@ -46,13 +46,15 @@
//! rejected ([`PivotTableError::ForeignField`]).
//! * A cell of a related field's group is evaluated with the group value as a filter on the
//! *related table*, so the evaluator's own relationship propagation (through the same indexes,
//! over any number of hops) restricts the source table. A source row whose key has no related
//! row — an orphan key, shown as `(Blank)` — belongs to the related table's BLANK member, so the
//! `(Blank)` cell counts it and the leaf rows still add up to the grand total. A BLANK foreign
//! key is an orphan as well: a relationship never joins one. A related field whose one side
//! repeats a key resolves to its lowest row id for the *label*, while the cell's filter passes
//! every related key, so a source row can be counted in more than one leaf cell in that model;
//! a one-side key that must be unique is what `integrity` reports as a duplicate-key finding.
//! over any number of hops) restricts the source table. A group value the relationship cannot
//! resolve — an orphan key, shown as `(Blank)` — therefore selects no source rows and the
//! measure returns its empty-set value (BLANK for `SUM`), the model's inner-join semantics.
//! A BLANK foreign key is an orphan for the same reason and never joins a one-side row, even one
//! whose key is BLANK: the cell filter and the relationship join both drop it, which is the
//! VertiPaq rule the related-pivot suites pin.
//! A related field whose one side repeats a key resolves to its lowest row id for the *label*,
//! while the cell's filter passes every related key, so a source row can be counted in more than
//! one leaf cell in such a model; `integrity` reports that duplicate one-side key.
//! A label column of a related field is named `Table[Column]`, so two dimensions with a column
//! of the same name stay distinguishable; source-table fields keep the bare column name.
//!
@@ -423,11 +425,12 @@ impl<'a> Plan<'a> {
}
}
SourceRows::Rows(rows) => {
let lookups = hop_key_lookups(self.model, self.row_fields.iter().chain(&self.column_fields));
for row in rows.iter() {
let values = self.model_group_values(row, &self.row_fields);
let values = self.model_group_values(&lookups, row, &self.row_fields);
row_groups.entry(values.iter().map(crate::value::distinct_key).collect()).or_insert(values);
if !self.column_fields.is_empty() {
let values = self.model_group_values(row, &self.column_fields);
let values = self.model_group_values(&lookups, row, &self.column_fields);
column_groups.entry(values.iter().map(crate::value::distinct_key).collect()).or_insert(values);
}
}
@@ -529,9 +532,9 @@ impl<'a> Plan<'a> {
fields.iter().map(|field| column_field_value(storage, self.table, row, field)).collect()
}
/// The values of `fields` for one source model row.
fn model_group_values(&self, row: &[Scalar], fields: &[BoundField]) -> Vec<Scalar> {
fields.iter().map(|field| model_field_value(self.model, row, field)).collect()
/// The values of `fields` for one source model row, through the prebuilt hop indexes.
fn model_group_values(&self, lookups: &HopKeyLookups, row: &[Scalar], fields: &[BoundField]) -> Vec<Scalar> {
fields.iter().map(|field| model_field_value(self.model, lookups, row, field)).collect()
}
/// The filter context of one cell: the filters plus the row and column group values.
@@ -1025,7 +1028,7 @@ fn column_field_value(storage: &ModelStorage, table: usize, row: usize, field: &
/// The row-scan counterpart of [`column_field_value`]: the same hops, matched by key equality over
/// the related table's rows and resolving a duplicate key to the lowest row, so both paths group
/// identically.
fn model_field_value(model: &DataModel, row: &[Scalar], field: &BoundField) -> Scalar {
fn model_field_value(model: &DataModel, lookups: &HopKeyLookups, row: &[Scalar], field: &BoundField) -> Scalar {
let mut current = row;
for hop in &field.hops {
let key = ScalarKey::from(&current.get(hop.from_column).cloned().unwrap_or(Scalar::Blank));
@@ -1034,16 +1037,46 @@ fn model_field_value(model: &DataModel, row: &[Scalar], field: &BoundField) -> S
if key == ScalarKey::Blank {
return Scalar::Blank;
}
let matched = model
.tables
.get(hop.to_table)
.and_then(|table| table.rows.iter().find(|row| row.get(hop.to_column).is_some_and(|value| ScalarKey::from(value) == key)));
let matched = lookups
.get(&(hop.to_table, hop.to_column))
.and_then(|index| index.get(&key).copied())
.and_then(|row_id| model.tables.get(hop.to_table).and_then(|table| table.rows.get(row_id)));
let Some(next) = matched else { return Scalar::Blank };
current = next;
}
current.get(field.field.column).cloned().unwrap_or(Scalar::Blank)
}
/// Key indexes for the model-row grouping path, one per distinct hop: `(to_table, to_column)` to
/// the lowest row id carrying each key.
type HopKeyLookups = BTreeMap<(usize, usize), BTreeMap<ScalarKey, usize>>;
/// Builds a [`HopKeyLookups`] entry for every hop of `fields`.
///
/// A duplicated key keeps the lowest row id, matching the `find` the lookup replaces, so a source
/// row still reaches at most one related row. A row too short to hold the key column has no key,
/// exactly as that `find` never matched it.
fn hop_key_lookups<'a>(model: &DataModel, fields: impl IntoIterator<Item = &'a BoundField>) -> HopKeyLookups {
let mut lookups = HopKeyLookups::new();
for field in fields {
for hop in &field.hops {
if lookups.contains_key(&(hop.to_table, hop.to_column)) {
continue;
}
let mut index = BTreeMap::new();
if let Some(table) = model.tables.get(hop.to_table) {
for (row_id, row) in table.rows.iter().enumerate() {
if let Some(value) = row.get(hop.to_column) {
index.entry(ScalarKey::from(value)).or_insert(row_id);
}
}
}
lookups.insert((hop.to_table, hop.to_column), index);
}
}
lookups
}
/// Narrows `context` to the single group value `key` on `(table, column)`, intersecting with any
/// filter already set on the column.
///
@@ -1165,9 +1198,10 @@ mod tests {
hops: vec![Hop { relationship: 0, from_column: 0, to_table: 1, to_column: 0 }],
label: "Product[Name]".into(),
};
let lookups = hop_key_lookups(&model, [&field]);
let blank_key_row = model.tables[0].rows.first().cloned().unwrap_or_default();
assert_eq!(model_field_value(&model, &blank_key_row, &field), Scalar::Blank);
assert_eq!(model_field_value(&model, &lookups, &blank_key_row, &field), Scalar::Blank);
let matched_row = model.tables[0].rows.get(1).cloned().unwrap_or_default();
assert_eq!(model_field_value(&model, &matched_row, &field), Scalar::String("Widget".into()));
assert_eq!(model_field_value(&model, &lookups, &matched_row, &field), Scalar::String("Widget".into()));
}
}
+17
View File
@@ -271,3 +271,20 @@ fn documented_order_keywords_bind_at_their_argument_positions() {
let expr = parse_expression("SAMPLE ( 10, Sales, Sales[Amount], SIDEWAYS )").expect("parse");
assert!(Binder::new(&model).bind_expression(&expr).is_err());
}
#[test]
fn concatenate_x_binds_a_bare_order_word_in_every_pair() {
let model = sample_model();
// Every `(orderBy, Order)` pair takes a bare keyword: index 4 and index 6 here.
let bound = bind(&model, "CONCATENATEX ( Sales, Sales[Region], \"|\", Sales[Region], DESC, Sales[Amount], ASC )");
match bound {
BoundExpr::Call { args, .. } => {
assert!(matches!(&args[4], BoundExpr::Keyword(word) if word == "DESC"), "{:?}", args[4]);
assert!(matches!(&args[6], BoundExpr::Keyword(word) if word == "ASC"), "{:?}", args[6]);
}
other => panic!("expected a call, got {other:?}"),
}
// A non-keyword in an order slot is still a name, and there is no such name here.
let expr = parse_expression("CONCATENATEX ( Sales, Sales[Region], \"|\", Sales[Region], SIDEWAYS )").expect("parse");
assert!(Binder::new(&model).bind_expression(&expr).is_err());
}
@@ -333,11 +333,13 @@ fn measures_evaluate_through_storage() {
}
#[test]
fn pivot_blank_group_counts_orphan_fact_rows() {
fn a_blank_foreign_key_and_an_orphan_key_group_as_blank_with_an_empty_cell() {
// `Product` has an "Unknown" row whose key is BLANK. `Sales` has a row matching `Widget`, a
// row whose key has no `Product` at all, and a row whose key is BLANK. A relationship never
// joins a BLANK key, so the last two are orphans: they group as `(Blank)` and the BLANK cell
// must count them instead of showing zero.
// joins a BLANK key, and a key with no related row is an orphan, so grouping puts both under
// `(Blank)`; the `(Blank)` cell then selects no source rows and stays empty (`SUM` over an
// empty set). That is the model's inner-join semantics, and it is the rule the related-pivot
// suites pin.
let mut model = DataModel {
tables: vec![
ModelTable {
@@ -385,11 +387,10 @@ fn pivot_blank_group_counts_orphan_fact_rows() {
.with_layout(PivotLayout::Tabular);
let (table, stats) = pivot.render_with_stats(&model).expect("render pivot");
// (Blank) 60 = the orphan key 99 (20) plus the BLANK key (40); Widget 10; total 70.
// (Blank) is empty, Widget is 10, and the grand total still spans every fact row (70).
assert_eq!(table.rows.len(), 3, "{:?}", table.rows);
assert_eq!(table.rows[0], vec![Scalar::Blank, Scalar::Decimal(60.0)]);
assert_eq!(table.rows[0], vec![Scalar::Blank, Scalar::Blank]);
assert_eq!(table.rows[1], vec![text("Widget"), Scalar::Decimal(10.0)]);
assert_eq!(table.rows[2], vec![text("Grand Total"), Scalar::Decimal(70.0)]);
// Every cell was answered from the columns, so both sides read the same relationship indexes.
assert!(stats.aggregates > 0, "each pivot cell is a storage aggregate, got {stats:?}");
}
+4 -3
View File
@@ -592,7 +592,7 @@ fn distinct_count_folds_text_case() {
}
#[test]
fn the_blank_member_keeps_orphan_fact_rows() {
fn a_blank_dimension_member_drops_orphan_fact_rows() {
let mut model = DataModel {
tables: vec![
ModelTable {
@@ -627,10 +627,11 @@ fn the_blank_member_keeps_orphan_fact_rows() {
let evaluator = Evaluator::new(&model).expect("evaluator");
let bound = Binder::new(&model).bind_expression(&parse_expression("[Total]").expect("parse")).expect("bind");
// The BLANK member of Products carries the rows that do not join, so the total is 20, not 0.
// A filter on Products' BLANK member keeps no orphan fact rows: an orphan key does not join,
// so `SUM` over the empty set is BLANK (the model's inner-join semantics).
let mut filters = FilterContext::default();
filters.set(1, 0, [gridcraft_dax::ScalarKey::Blank]);
assert_eq!(evaluator.evaluate_with(&bound, filters).expect("blank member"), Scalar::Decimal(20.0));
assert_eq!(evaluator.evaluate_with(&bound, filters).expect("blank member"), Scalar::Blank);
// A concrete member still sees only its own rows: the orphan stays out of `"A"`.
let mut filters = FilterContext::default();
+6 -6
View File
@@ -91,9 +91,9 @@ fn a_two_hop_related_field_groups_and_filters_through_both_hops() {
let table = pivot().with_row_fields(vec!["Category[Category]".into()]).with_layout(PivotLayout::Tabular).render(&model()).expect("render");
// Widget (key 1) is Hardware: 100 + 50. Gadget (key 2) is Software: 25. The orphan key 3
// reaches no Product row, so it is the BLANK member of both hops and its cell counts it (40).
// reaches no Product row, so it groups as BLANK and its cell stays empty.
assert_eq!(header(&table), vec!["Category[Category]".to_string(), "Total Sales".to_string()]);
assert_eq!(table.rows, vec![vec![Scalar::Blank, dec(40.0)], vec![text("Hardware"), dec(150.0)], vec![text("Software"), dec(25.0)]]);
assert_eq!(table.rows, vec![vec![Scalar::Blank, Scalar::Blank], vec![text("Hardware"), dec(150.0)], vec![text("Software"), dec(25.0)]]);
}
#[test]
@@ -108,7 +108,7 @@ fn one_hop_and_two_hop_row_fields_mix() {
assert_eq!(
table.rows,
vec![
vec![Scalar::Blank, Scalar::Blank, dec(40.0)],
vec![Scalar::Blank, Scalar::Blank, Scalar::Blank],
vec![text("Gadget"), text("Software"), dec(25.0)],
vec![text("Widget"), text("Hardware"), dec(150.0)],
]
@@ -120,8 +120,8 @@ fn a_dimension_row_without_fact_rows_is_not_a_group() {
let table = pivot().with_row_fields(vec!["Product[Name]".into()]).with_layout(PivotLayout::Tabular).render(&model()).expect("render");
// Doohickey (ProductKey 4) has no fact row; the cells come from the fact table, so it never
// appears. The orphan key still does, as the BLANK member — and its cell counts it.
assert_eq!(table.rows, vec![vec![Scalar::Blank, dec(40.0)], vec![text("Gadget"), dec(25.0)], vec![text("Widget"), dec(150.0)]]);
// appears. The orphan key still does, as BLANK.
assert_eq!(table.rows, vec![vec![Scalar::Blank, Scalar::Blank], vec![text("Gadget"), dec(25.0)], vec![text("Widget"), dec(150.0)]]);
}
#[test]
@@ -158,7 +158,7 @@ fn the_grand_total_spans_the_fact_table_across_the_snowflake() {
assert_eq!(
table.rows,
vec![
vec![Scalar::Blank, dec(40.0)],
vec![Scalar::Blank, Scalar::Blank],
vec![text("Hardware"), dec(150.0)],
vec![text("Software"), dec(25.0)],
vec![text("Grand Total"), dec(215.0)],
+6 -6
View File
@@ -102,7 +102,7 @@ fn related_row_field_groups_by_the_dimension_value() {
// apart. ProductKey 3 has no Product row: its fact row groups as BLANK, and the cell is BLANK
// because the BLANK member selects no related row, so the relationship filter keeps nothing.
assert_eq!(header(&table), vec!["Product[Name]".to_string(), "Total Sales".to_string()]);
assert_eq!(table.rows, vec![vec![Scalar::Blank, dec(40.0)], vec![text("Gadget"), dec(35.0)], vec![text("Widget"), dec(180.0)],]);
assert_eq!(table.rows, vec![vec![Scalar::Blank, Scalar::Blank], vec![text("Gadget"), dec(35.0)], vec![text("Widget"), dec(180.0)],]);
assert_eq!(table.lineage, Some(0), "the rendered table keeps the source table's lineage");
}
@@ -130,7 +130,7 @@ fn two_dimensions_cross_tabulate_with_two_measures() {
assert_eq!(
table.rows,
vec![
vec![Scalar::Blank, dec(40.0), dec(4.0), Scalar::Blank, Scalar::Blank],
vec![Scalar::Blank, Scalar::Blank, Scalar::Blank, Scalar::Blank, Scalar::Blank],
vec![text("Gadget"), dec(25.0), dec(3.0), dec(10.0), dec(1.0)],
// Widget x North: 100 + 30, quantities 1 + 1.
vec![text("Widget"), dec(130.0), dec(2.0), dec(50.0), dec(2.0)],
@@ -151,7 +151,7 @@ fn two_related_row_fields_order_blank_first_and_total_every_fact_row() {
assert_eq!(
table.rows,
vec![
vec![Scalar::Blank, text("North"), dec(40.0)],
vec![Scalar::Blank, text("North"), Scalar::Blank],
vec![text("Gadget"), text("North"), dec(25.0)],
vec![text("Gadget"), text("South"), dec(10.0)],
vec![text("Widget"), text("North"), dec(130.0)],
@@ -181,7 +181,7 @@ fn a_filter_on_a_dimension_field_restricts_the_fact_table() {
.with_layout(PivotLayout::Tabular)
.render(&model())
.expect("render");
assert_eq!(by_store.rows, vec![vec![Scalar::Blank, dec(40.0)], vec![text("Gadget"), dec(25.0)], vec![text("Widget"), dec(130.0)]]);
assert_eq!(by_store.rows, vec![vec![Scalar::Blank, Scalar::Blank], vec![text("Gadget"), dec(25.0)], vec![text("Widget"), dec(130.0)]]);
// A filter that matches no dimension row keeps no fact row, but the header survives.
let nothing = pivot()
@@ -263,7 +263,7 @@ fn an_empty_dimension_table_groups_every_fact_row_as_blank() {
// member to attach them to, so the leaf cell is the empty-set measure (BLANK) while the grand
// total, which constrains no dimension, still sums the fact table.
assert_eq!(header(&table), vec!["Product[Name]".to_string(), "Total Sales".to_string()]);
assert_eq!(table.rows, vec![vec![Scalar::Blank, dec(255.0)], vec![text("Grand Total"), dec(255.0)]]);
assert_eq!(table.rows, vec![vec![Scalar::Blank, Scalar::Blank], vec![text("Grand Total"), dec(255.0)]]);
}
#[test]
@@ -279,7 +279,7 @@ fn related_grouping_survives_an_unfaithful_model() {
let (table, stats) =
pivot().with_row_fields(vec!["Product[Name]".into()]).with_layout(PivotLayout::Tabular).render_with_stats(&model).expect("render");
assert_eq!(table.rows, vec![vec![Scalar::Blank, dec(40.0)], vec![text("Gadget"), dec(35.0)], vec![text("Widget"), dec(180.0)]]);
assert_eq!(table.rows, vec![vec![Scalar::Blank, Scalar::Blank], vec![text("Gadget"), dec(35.0)], vec![text("Widget"), dec(180.0)]]);
assert_eq!(stats.pivot_group_rows, 0, "grouping fell back to the model rows: {stats:?}");
assert!(stats.row_scan_fallbacks > 0, "the unfaithful model must be reported: {stats:?}");