From 0ade51f7aabb15fa6c4e63b0c3eb7419506ae0cf Mon Sep 17 00:00:00 2001 From: alosslessdev Date: Thu, 5 Nov 2026 14:54:44 -0500 Subject: [PATCH] dax: keep filter keys in their own variant and fold at comparison (#2228) --- crates/dax/src/eval.rs | 14 ++++++++++---- crates/dax/src/pivot_table.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/dax/src/eval.rs b/crates/dax/src/eval.rs index 5f3d14e3d..3c81aaa4b 100644 --- a/crates/dax/src/eval.rs +++ b/crates/dax/src/eval.rs @@ -180,8 +180,11 @@ impl FilterContext { self.filters.clear(); } + /// Sets a column filter. The keys keep their own variant so `column_value` can rebuild the + /// original scalar (`SELECTEDVALUE` must answer a date for a date filter); matching folds both + /// sides through [`folded_key`] instead. pub fn set(&mut self, table: usize, column: usize, values: impl IntoIterator) { - self.filters.insert((table, column), values.into_iter().map(|key| folded_key(&key)).collect()); + self.filters.insert((table, column), values.into_iter().collect()); } pub fn remove_table(&mut self, table: usize) { @@ -190,9 +193,12 @@ impl FilterContext { fn matches(&self, table: usize, column: usize, value: &Scalar) -> bool { match self.filters.get(&(table, column)) { - // Filter keys and values fold text the same way, so `VALUES`/`DISTINCTCOUNT` and the - // filters they feed agree on `"A"` and `"a"`. - Some(values) => values.contains(&distinct_key(value)), + // Both sides fold through the same rule, so text ignores case and a numeric key + // matches its other variants (a caller may insert keys into the public map directly). + Some(values) => { + let wanted = distinct_key(value); + values.iter().any(|allowed| folded_key(allowed) == wanted) + } None => true, } } diff --git a/crates/dax/src/pivot_table.rs b/crates/dax/src/pivot_table.rs index 07f535be6..8ed9b1719 100644 --- a/crates/dax/src/pivot_table.rs +++ b/crates/dax/src/pivot_table.rs @@ -393,7 +393,7 @@ impl<'a> Plan<'a> { let field = resolved.into_iter().next().ok_or_else(|| PivotTableError::UnknownField { pivot: name.clone(), field: filter.field.clone() })?; let bound = bind_field(model, table, &table_name, field)?; - let allowed = filter.allowed.iter().map(|value| crate::value::folded_key(&ScalarKey::from(value))).collect(); + let allowed = filter.allowed.iter().map(ScalarKey::from).collect(); filters.push((bound, allowed)); } @@ -525,7 +525,7 @@ impl<'a> Plan<'a> { fn passes(&self, row: &[Scalar]) -> bool { self.filters.iter().all(|(field, allowed)| { let value = row.get(field.field.column).cloned().unwrap_or(Scalar::Blank); - allowed.contains(&crate::value::distinct_key(&value)) + allowed.iter().any(|allowed| crate::value::folded_key(allowed) == crate::value::distinct_key(&value)) }) } @@ -1095,12 +1095,12 @@ fn hop_key_lookups<'a>(model: &DataModel, fields: impl IntoIterator context.set(table, column, std::iter::empty()), - _ => context.set(table, column, [key]), + Some(allowed) if !allowed.iter().any(|allowed| crate::value::folded_key(allowed) == folded) => context.set(table, column, std::iter::empty()), + _ => context.set(table, column, [key.clone()]), } }